From 930e342fb7ebc91510b5833bbfe97c078a68b96b Mon Sep 17 00:00:00 2001 From: zzzk1 Date: Thu, 2 Jan 2025 21:35:04 +0800 Subject: [PATCH] remove back 0.0 --- exporter/logzioexporter/exporter.go | 4 +- exporter/logzioexporter/exporter_test.go | 4 +- .../{internal/dbmodel => }/from_domain.go | 57 ++++++++++--------- .../dbmodel => }/from_domain_test.go | 32 +++++------ .../logzioexporter/internal/dbmodel/model.go | 3 +- .../{internal/dbmodel => }/logziospan.go | 40 ++++++------- .../{internal/dbmodel => }/logziospan_test.go | 6 +- 7 files changed, 74 insertions(+), 72 deletions(-) rename exporter/logzioexporter/{internal/dbmodel => }/from_domain.go (63%) rename exporter/logzioexporter/{internal/dbmodel => }/from_domain_test.go (78%) rename exporter/logzioexporter/{internal/dbmodel => }/logziospan.go (54%) rename exporter/logzioexporter/{internal/dbmodel => }/logziospan_test.go (84%) diff --git a/exporter/logzioexporter/exporter.go b/exporter/logzioexporter/exporter.go index 30d9932abd07..a4cc01780ec9 100644 --- a/exporter/logzioexporter/exporter.go +++ b/exporter/logzioexporter/exporter.go @@ -15,8 +15,6 @@ import ( "strconv" "time" - "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logzioexporter/internal/dbmodel" - "github.com/hashicorp/go-hclog" "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/pkg/cache" @@ -191,7 +189,7 @@ func (exporter *logzioExporter) pushTraceData(ctx context.Context, traces ptrace span.Process = batch.Process span.Tags = exporter.dropEmptyTags(span.Tags) span.Process.Tags = exporter.dropEmptyTags(span.Process.Tags) - logzioSpan, transformErr := dbmodel.TransformToLogzioSpanBytes(span) + logzioSpan, transformErr := transformToLogzioSpanBytes(span) if transformErr != nil { return transformErr } diff --git a/exporter/logzioexporter/exporter_test.go b/exporter/logzioexporter/exporter_test.go index 0dbd06dee86d..2943c50a9413 100644 --- a/exporter/logzioexporter/exporter_test.go +++ b/exporter/logzioexporter/exporter_test.go @@ -16,8 +16,6 @@ import ( "testing" "time" - "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logzioexporter/internal/dbmodel" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" @@ -257,7 +255,7 @@ func TestPushTraceData(tester *testing.T) { res.Attributes().PutStr(conventions.AttributeHostName, testHost) err := testTracesExporter(tester, td, &cfg) require.NoError(tester, err) - var newSpan dbmodel.LogzioSpan + var newSpan logzioSpan decoded, _ := gUnzipData(recordedRequests) requests := strings.Split(string(decoded), "\n") assert.NoError(tester, json.Unmarshal([]byte(requests[0]), &newSpan)) diff --git a/exporter/logzioexporter/internal/dbmodel/from_domain.go b/exporter/logzioexporter/from_domain.go similarity index 63% rename from exporter/logzioexporter/internal/dbmodel/from_domain.go rename to exporter/logzioexporter/from_domain.go index 1f02075f618e..5eee5652677d 100644 --- a/exporter/logzioexporter/internal/dbmodel/from_domain.go +++ b/exporter/logzioexporter/from_domain.go @@ -1,13 +1,16 @@ +// Copyright The OpenTelemetry Authors // Copyright (c) 2019 The Jaeger Authors. // Copyright (c) 2018 Uber Technologies, Inc. // SPDX-License-Identifier: Apache-2.0 -package dbmodel // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logzioexporter" +package logzioexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logzioexporter" import ( "strings" "github.com/jaegertracing/jaeger/model" + + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logzioexporter/internal/dbmodel" ) // newFromDomain creates fromDomain used to convert model span to db span @@ -28,15 +31,15 @@ type fromDomain struct { // fromDomainEmbedProcess converts model.span into json.span format. // This format includes a ParentSpanID and an embedded process. -func (fd fromDomain) fromDomainEmbedProcess(span *model.Span) *LogzioSpan { +func (fd fromDomain) fromDomainEmbedProcess(span *model.Span) *logzioSpan { return fd.convertSpanEmbedProcess(span) } -func (fd fromDomain) convertSpanInternal(span *model.Span) LogzioSpan { +func (fd fromDomain) convertSpanInternal(span *model.Span) logzioSpan { tags, tagsMap := fd.convertKeyValuesString(span.Tags) - return LogzioSpan{ - TraceID: TraceID(span.TraceID.String()), - SpanID: SpanID(span.SpanID.String()), + return logzioSpan{ + TraceID: dbmodel.TraceID(span.TraceID.String()), + SpanID: dbmodel.SpanID(span.SpanID.String()), Flags: uint32(span.Flags), OperationName: span.OperationName, StartTime: model.TimeAsEpochMicroseconds(span.StartTime), @@ -48,35 +51,35 @@ func (fd fromDomain) convertSpanInternal(span *model.Span) LogzioSpan { } } -func (fd fromDomain) convertSpanEmbedProcess(span *model.Span) *LogzioSpan { +func (fd fromDomain) convertSpanEmbedProcess(span *model.Span) *logzioSpan { s := fd.convertSpanInternal(span) s.Process = fd.convertProcess(span.Process) s.References = fd.convertReferences(span) return &s } -func (fd fromDomain) convertReferences(span *model.Span) []Reference { - out := make([]Reference, 0, len(span.References)) +func (fd fromDomain) convertReferences(span *model.Span) []dbmodel.Reference { + out := make([]dbmodel.Reference, 0, len(span.References)) for _, ref := range span.References { - out = append(out, Reference{ + out = append(out, dbmodel.Reference{ RefType: fd.convertRefType(ref.RefType), - TraceID: TraceID(ref.TraceID.String()), - SpanID: SpanID(ref.SpanID.String()), + TraceID: dbmodel.TraceID(ref.TraceID.String()), + SpanID: dbmodel.SpanID(ref.SpanID.String()), }) } return out } -func (fromDomain) convertRefType(refType model.SpanRefType) ReferenceType { +func (fromDomain) convertRefType(refType model.SpanRefType) dbmodel.ReferenceType { if refType == model.FollowsFrom { - return FollowsFrom + return dbmodel.FollowsFrom } - return ChildOf + return dbmodel.ChildOf } -func (fd fromDomain) convertKeyValuesString(keyValues model.KeyValues) ([]KeyValue, map[string]any) { +func (fd fromDomain) convertKeyValuesString(keyValues model.KeyValues) ([]dbmodel.KeyValue, map[string]any) { var tagsMap map[string]any - var kvs []KeyValue + var kvs []dbmodel.KeyValue for _, kv := range keyValues { if kv.GetVType() != model.BinaryType && (fd.allTagsAsFields || fd.tagKeysAsFields[kv.Key]) { if tagsMap == nil { @@ -88,19 +91,19 @@ func (fd fromDomain) convertKeyValuesString(keyValues model.KeyValues) ([]KeyVal } } if kvs == nil { - kvs = make([]KeyValue, 0) + kvs = make([]dbmodel.KeyValue, 0) } return kvs, tagsMap } -func (fromDomain) convertLogs(logs []model.Log) []Log { - out := make([]Log, len(logs)) +func (fromDomain) convertLogs(logs []model.Log) []dbmodel.Log { + out := make([]dbmodel.Log, len(logs)) for i, log := range logs { - var kvs []KeyValue + var kvs []dbmodel.KeyValue for _, kv := range log.Fields { kvs = append(kvs, convertKeyValue(kv)) } - out[i] = Log{ + out[i] = dbmodel.Log{ Timestamp: model.TimeAsEpochMicroseconds(log.Timestamp), Fields: kvs, } @@ -108,19 +111,19 @@ func (fromDomain) convertLogs(logs []model.Log) []Log { return out } -func (fd fromDomain) convertProcess(process *model.Process) Process { +func (fd fromDomain) convertProcess(process *model.Process) dbmodel.Process { tags, tagsMap := fd.convertKeyValuesString(process.Tags) - return Process{ + return dbmodel.Process{ ServiceName: process.ServiceName, Tags: tags, Tag: tagsMap, } } -func convertKeyValue(kv model.KeyValue) KeyValue { - return KeyValue{ +func convertKeyValue(kv model.KeyValue) dbmodel.KeyValue { + return dbmodel.KeyValue{ Key: kv.Key, - Type: ValueType(strings.ToLower(kv.VType.String())), + Type: dbmodel.ValueType(strings.ToLower(kv.VType.String())), Value: kv.AsString(), } } diff --git a/exporter/logzioexporter/internal/dbmodel/from_domain_test.go b/exporter/logzioexporter/from_domain_test.go similarity index 78% rename from exporter/logzioexporter/internal/dbmodel/from_domain_test.go rename to exporter/logzioexporter/from_domain_test.go index 05e6a8e61957..b345d3d961ee 100644 --- a/exporter/logzioexporter/internal/dbmodel/from_domain_test.go +++ b/exporter/logzioexporter/from_domain_test.go @@ -1,8 +1,9 @@ +// Copyright The OpenTelemetry Authors // Copyright (c) 2019 The Jaeger Authors. // Copyright (c) 2018 Uber Technologies, Inc. // SPDX-License-Identifier: Apache-2.0 -package dbmodel +package logzioexporter import ( "bytes" @@ -13,10 +14,11 @@ import ( "testing" "github.com/gogo/protobuf/jsonpb" + "github.com/jaegertracing/jaeger/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/jaegertracing/jaeger/model" + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logzioexporter/internal/dbmodel" ) func TestFromDomainEmbedProcess(t *testing.T) { @@ -27,7 +29,7 @@ func TestFromDomainEmbedProcess(t *testing.T) { converter := newFromDomain(false, nil, ":") embeddedSpan := converter.fromDomainEmbedProcess(&span) - var expectedSpan LogzioSpan + var expectedSpan logzioSpan require.NoError(t, json.Unmarshal(jsonStr, &expectedSpan)) testJSONEncoding(t, jsonStr, embeddedSpan) @@ -35,11 +37,9 @@ func TestFromDomainEmbedProcess(t *testing.T) { // Loads and returns domain model and JSON model. func loadModel(t *testing.T) ([]byte, []byte) { - in := fmt.Sprintf("../../testdata/span.json") - inStr, err := os.ReadFile(in) + inStr, err := os.ReadFile("./testdata/span.json") require.NoError(t, err) - out := fmt.Sprintf("../../testdata/logziospan.json") - outStr, err := os.ReadFile(out) + outStr, err := os.ReadFile("./testdata/logziospan.json") require.NoError(t, err) return inStr, outStr } @@ -50,7 +50,7 @@ func testJSONEncoding(t *testing.T, expectedStr []byte, object any) { enc.SetIndent("", " ") require.NoError(t, enc.Encode(object)) if !assert.Equal(t, string(expectedStr), buf.String()) { - err := os.WriteFile("model-actual.json", buf.Bytes(), 0o644) + err := os.WriteFile("model-actual.json", buf.Bytes(), 0o600) require.NoError(t, err) } } @@ -95,35 +95,35 @@ func TestConvertKeyValueValue(t *testing.T) { key := "key" tests := []struct { kv model.KeyValue - expected KeyValue + expected dbmodel.KeyValue }{ { kv: model.Bool(key, true), - expected: KeyValue{Key: key, Value: "true", Type: "bool"}, + expected: dbmodel.KeyValue{Key: key, Value: "true", Type: "bool"}, }, { kv: model.Bool(key, false), - expected: KeyValue{Key: key, Value: "false", Type: "bool"}, + expected: dbmodel.KeyValue{Key: key, Value: "false", Type: "bool"}, }, { kv: model.Int64(key, int64(1499)), - expected: KeyValue{Key: key, Value: "1499", Type: "int64"}, + expected: dbmodel.KeyValue{Key: key, Value: "1499", Type: "int64"}, }, { kv: model.Float64(key, float64(15.66)), - expected: KeyValue{Key: key, Value: "15.66", Type: "float64"}, + expected: dbmodel.KeyValue{Key: key, Value: "15.66", Type: "float64"}, }, { kv: model.String(key, longString), - expected: KeyValue{Key: key, Value: longString, Type: "string"}, + expected: dbmodel.KeyValue{Key: key, Value: longString, Type: "string"}, }, { kv: model.Binary(key, []byte(longString)), - expected: KeyValue{Key: key, Value: hex.EncodeToString([]byte(longString)), Type: "binary"}, + expected: dbmodel.KeyValue{Key: key, Value: hex.EncodeToString([]byte(longString)), Type: "binary"}, }, { kv: model.KeyValue{VType: 1500, Key: key}, - expected: KeyValue{Key: key, Value: "unknown type 1500", Type: "1500"}, + expected: dbmodel.KeyValue{Key: key, Value: "unknown type 1500", Type: "1500"}, }, } diff --git a/exporter/logzioexporter/internal/dbmodel/model.go b/exporter/logzioexporter/internal/dbmodel/model.go index f71b9984b9ff..af42f10eecb9 100644 --- a/exporter/logzioexporter/internal/dbmodel/model.go +++ b/exporter/logzioexporter/internal/dbmodel/model.go @@ -1,8 +1,9 @@ +// Copyright The OpenTelemetry Authors // Copyright (c) 2019 The Jaeger Authors. // Copyright (c) 2018 Uber Technologies, Inc. // SPDX-License-Identifier: Apache-2.0 -package dbmodel +package dbmodel // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logzioexporter/internal/dbmodel" // ReferenceType is the reference type of one span to another type ReferenceType string diff --git a/exporter/logzioexporter/internal/dbmodel/logziospan.go b/exporter/logzioexporter/logziospan.go similarity index 54% rename from exporter/logzioexporter/internal/dbmodel/logziospan.go rename to exporter/logzioexporter/logziospan.go index 35d12efc150b..edeef69b0ea9 100644 --- a/exporter/logzioexporter/internal/dbmodel/logziospan.go +++ b/exporter/logzioexporter/logziospan.go @@ -1,12 +1,14 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package dbmodel // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logzioexporter" +package logzioexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logzioexporter" import ( "encoding/json" "github.com/jaegertracing/jaeger/model" + + "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logzioexporter/internal/dbmodel" ) const ( @@ -15,22 +17,22 @@ const ( tagDotReplacementCharacter = "@" ) -// LogzioSpan is same as esSpan with a few different json field names and an addition on type field. -type LogzioSpan struct { - TraceID TraceID `json:"traceID"` - OperationName string `json:"operationName,omitempty"` - SpanID SpanID `json:"spanID"` - References []Reference `json:"references"` - Flags uint32 `json:"flags,omitempty"` - StartTime uint64 `json:"startTime"` - StartTimeMillis uint64 `json:"startTimeMillis"` - Timestamp uint64 `json:"@timestamp"` - Duration uint64 `json:"duration"` - Tags []KeyValue `json:"JaegerTags,omitempty"` - Tag map[string]any `json:"JaegerTag,omitempty"` - Logs []Log `json:"logs"` - Process Process `json:"process,omitempty"` - Type string `json:"type"` +// logzioSpan is same as esSpan with a few different json field names and an addition on type field. +type logzioSpan struct { + TraceID dbmodel.TraceID `json:"traceID"` + OperationName string `json:"operationName,omitempty"` + SpanID dbmodel.SpanID `json:"spanID"` + References []dbmodel.Reference `json:"references"` + Flags uint32 `json:"flags,omitempty"` + StartTime uint64 `json:"startTime"` + StartTimeMillis uint64 `json:"startTimeMillis"` + Timestamp uint64 `json:"@timestamp"` + Duration uint64 `json:"duration"` + Tags []dbmodel.KeyValue `json:"JaegerTags,omitempty"` + Tag map[string]any `json:"JaegerTag,omitempty"` + Logs []dbmodel.Log `json:"logs"` + Process dbmodel.Process `json:"process,omitempty"` + Type string `json:"type"` } func getTagsValues(tags []model.KeyValue) []string { @@ -43,10 +45,10 @@ func getTagsValues(tags []model.KeyValue) []string { // transformToLogzioSpanBytes receives a Jaeger span, converts it to logzio span and returns it as a byte array. // The main differences between Jaeger span and logzio span are arrays which are represented as maps -func TransformToLogzioSpanBytes(span *model.Span) ([]byte, error) { +func transformToLogzioSpanBytes(span *model.Span) ([]byte, error) { spanConverter := newFromDomain(true, getTagsValues(span.Tags), tagDotReplacementCharacter) jsonSpan := spanConverter.fromDomainEmbedProcess(span) - newSpan := LogzioSpan{ + newSpan := logzioSpan{ TraceID: jsonSpan.TraceID, OperationName: jsonSpan.OperationName, SpanID: jsonSpan.SpanID, diff --git a/exporter/logzioexporter/internal/dbmodel/logziospan_test.go b/exporter/logzioexporter/logziospan_test.go similarity index 84% rename from exporter/logzioexporter/internal/dbmodel/logziospan_test.go rename to exporter/logzioexporter/logziospan_test.go index fec3b034160b..af4b768e1b2a 100644 --- a/exporter/logzioexporter/internal/dbmodel/logziospan_test.go +++ b/exporter/logzioexporter/logziospan_test.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package dbmodel +package logzioexporter import ( "encoding/json" @@ -14,7 +14,7 @@ import ( ) func TestTransformToLogzioSpanBytes(tester *testing.T) { - inStr, err := os.ReadFile("../../testdata/span.json") + inStr, err := os.ReadFile("./testdata/span.json") require.NoError(tester, err, "error opening sample span file") var span model.Span @@ -22,7 +22,7 @@ func TestTransformToLogzioSpanBytes(tester *testing.T) { if err != nil { fmt.Println("json.Unmarshal") } - newSpan, err := TransformToLogzioSpanBytes(&span) + newSpan, err := transformToLogzioSpanBytes(&span) require.NoError(tester, err) m := make(map[string]any) err = json.Unmarshal(newSpan, &m)