From bd606ceb727dd590d6d37fc8f2e277acf6d74493 Mon Sep 17 00:00:00 2001 From: zzzk1 Date: Sun, 29 Dec 2024 19:36:17 +0800 Subject: [PATCH] public -> private --- exporter/logzioexporter/from_domain.go | 90 ++++++++++----------- exporter/logzioexporter/from_domain_test.go | 16 ++-- exporter/logzioexporter/logziospan.go | 38 ++++----- 3 files changed, 72 insertions(+), 72 deletions(-) diff --git a/exporter/logzioexporter/from_domain.go b/exporter/logzioexporter/from_domain.go index 5eb88a8b4216..05483e165a85 100644 --- a/exporter/logzioexporter/from_domain.go +++ b/exporter/logzioexporter/from_domain.go @@ -19,7 +19,7 @@ type TraceID string // SpanID is the id of a span type SpanID string -// ValueType is the type of a value stored in KeyValue struct. +// ValueType is the type of a value stored in keyValue struct. type ValueType string const ( @@ -28,71 +28,71 @@ const ( // FollowsFrom means a span follows from another span FollowsFrom ReferenceType = "FOLLOWS_FROM" - // StringType indicates a string value stored in KeyValue + // StringType indicates a string value stored in keyValue StringType ValueType = "string" - // BoolType indicates a Boolean value stored in KeyValue + // BoolType indicates a Boolean value stored in keyValue BoolType ValueType = "bool" - // Int64Type indicates a 64bit signed integer value stored in KeyValue + // Int64Type indicates a 64bit signed integer value stored in keyValue Int64Type ValueType = "int64" - // Float64Type indicates a 64bit float value stored in KeyValue + // Float64Type indicates a 64bit float value stored in keyValue Float64Type ValueType = "float64" - // BinaryType indicates an arbitrary byte array stored in KeyValue + // BinaryType indicates an arbitrary byte array stored in keyValue BinaryType ValueType = "binary" ) -// Reference is a reference from one span to another -type Reference struct { +// reference is a reference from one span to another +type reference struct { RefType ReferenceType `json:"refType"` TraceID TraceID `json:"traceID"` SpanID SpanID `json:"spanID"` } -// Process is the process emitting a set of spans -type Process struct { +// process is the process emitting a set of spans +type process struct { ServiceName string `json:"serviceName"` - Tags []KeyValue `json:"tags"` + Tags []keyValue `json:"tags"` // Alternative representation of tags for better kibana support Tag map[string]any `json:"tag,omitempty"` } -// Log is a log emitted in a span -type Log struct { +// log is a log emitted in a span +type log struct { Timestamp uint64 `json:"timestamp"` - Fields []KeyValue `json:"fields"` + Fields []keyValue `json:"fields"` } -// KeyValue is a key-value pair with typed value. -type KeyValue struct { +// keyValue is a key-value pair with typed value. +type keyValue struct { Key string `json:"key"` Type ValueType `json:"type,omitempty"` Value any `json:"value"` } -// Service is the JSON struct for service:operation documents in ElasticSearch -type Service struct { +// service is the JSON struct for service:operation documents in ElasticSearch +type service struct { ServiceName string `json:"serviceName"` OperationName string `json:"operationName"` } -// only for testing Span is ES database representation of the domain span. -type Span struct { +// only for testing span is ES database representation of the domain span. +type span struct { TraceID TraceID `json:"traceID"` SpanID SpanID `json:"spanID"` ParentSpanID SpanID `json:"parentSpanID,omitempty"` // deprecated Flags uint32 `json:"flags,omitempty"` OperationName string `json:"operationName"` - References []Reference `json:"references"` + References []reference `json:"references"` StartTime uint64 `json:"startTime"` // microseconds since Unix epoch // ElasticSearch does not support a UNIX Epoch timestamp in microseconds, // so Jaeger maps StartTime to a 'long' type. This extra StartTimeMillis field // works around this issue, enabling timerange queries. StartTimeMillis uint64 `json:"startTimeMillis"` Duration uint64 `json:"duration"` // microseconds - Tags []KeyValue `json:"tags"` + Tags []keyValue `json:"tags"` // Alternative representation of tags for better kibana support Tag map[string]any `json:"tag,omitempty"` - Logs []Log `json:"logs"` - Process Process `json:"process,omitempty"` + Logs []log `json:"logs"` + Process process `json:"process,omitempty"` } // newFromDomain creates fromDomain used to convert model span to db span @@ -111,8 +111,8 @@ type fromDomain struct { tagDotReplacement string } -// fromDomainEmbedProcess converts model.Span into json.Span format. -// This format includes a ParentSpanID and an embedded Process. +// 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 { return fd.convertSpanEmbedProcess(span) } @@ -140,10 +140,10 @@ func (fd fromDomain) convertSpanEmbedProcess(span *model.Span) *logzioSpan { return &s } -func (fd fromDomain) convertReferences(span *model.Span) []Reference { - out := make([]Reference, 0, len(span.References)) +func (fd fromDomain) convertReferences(span *model.Span) []reference { + out := make([]reference, 0, len(span.References)) for _, ref := range span.References { - out = append(out, Reference{ + out = append(out, reference{ RefType: fd.convertRefType(ref.RefType), TraceID: TraceID(ref.TraceID.String()), SpanID: SpanID(ref.SpanID.String()), @@ -159,9 +159,9 @@ func (fromDomain) convertRefType(refType model.SpanRefType) ReferenceType { return ChildOf } -func (fd fromDomain) convertKeyValuesString(keyValues model.KeyValues) ([]KeyValue, map[string]any) { +func (fd fromDomain) convertKeyValuesString(keyValues model.KeyValues) ([]keyValue, map[string]any) { var tagsMap map[string]any - var kvs []KeyValue + var kvs []keyValue for _, kv := range keyValues { if kv.GetVType() != model.BinaryType && (fd.allTagsAsFields || fd.tagKeysAsFields[kv.Key]) { if tagsMap == nil { @@ -173,37 +173,37 @@ func (fd fromDomain) convertKeyValuesString(keyValues model.KeyValues) ([]KeyVal } } if kvs == nil { - kvs = make([]KeyValue, 0) + kvs = make([]keyValue, 0) } return kvs, tagsMap } -func (fromDomain) convertLogs(logs []model.Log) []Log { - out := make([]Log, len(logs)) - for i, log := range logs { - var kvs []KeyValue - for _, kv := range log.Fields { +func (fromDomain) convertLogs(logs []model.Log) []log { + out := make([]log, len(logs)) + for i, l := range logs { + var kvs []keyValue + for _, kv := range l.Fields { kvs = append(kvs, convertKeyValue(kv)) } - out[i] = Log{ - Timestamp: model.TimeAsEpochMicroseconds(log.Timestamp), + out[i] = log{ + Timestamp: model.TimeAsEpochMicroseconds(l.Timestamp), Fields: kvs, } } return out } -func (fd fromDomain) convertProcess(process *model.Process) Process { - tags, tagsMap := fd.convertKeyValuesString(process.Tags) - return Process{ - ServiceName: process.ServiceName, +func (fd fromDomain) convertProcess(p *model.Process) process { + tags, tagsMap := fd.convertKeyValuesString(p.Tags) + return process{ + ServiceName: p.ServiceName, Tags: tags, Tag: tagsMap, } } -func convertKeyValue(kv model.KeyValue) KeyValue { - return KeyValue{ +func convertKeyValue(kv model.KeyValue) keyValue { + return keyValue{ Key: kv.Key, Type: ValueType(strings.ToLower(kv.VType.String())), Value: kv.AsString(), diff --git a/exporter/logzioexporter/from_domain_test.go b/exporter/logzioexporter/from_domain_test.go index f7586bf2c782..40510fb565fb 100644 --- a/exporter/logzioexporter/from_domain_test.go +++ b/exporter/logzioexporter/from_domain_test.go @@ -98,35 +98,35 @@ func TestConvertKeyValueValue(t *testing.T) { key := "key" tests := []struct { kv model.KeyValue - expected KeyValue + expected keyValue }{ { kv: model.Bool(key, true), - expected: KeyValue{Key: key, Value: "true", Type: "bool"}, + expected: keyValue{Key: key, Value: "true", Type: "bool"}, }, { kv: model.Bool(key, false), - expected: KeyValue{Key: key, Value: "false", Type: "bool"}, + expected: keyValue{Key: key, Value: "false", Type: "bool"}, }, { kv: model.Int64(key, int64(1499)), - expected: KeyValue{Key: key, Value: "1499", Type: "int64"}, + expected: keyValue{Key: key, Value: "1499", Type: "int64"}, }, { kv: model.Float64(key, float64(15.66)), - expected: KeyValue{Key: key, Value: "15.66", Type: "float64"}, + expected: keyValue{Key: key, Value: "15.66", Type: "float64"}, }, { kv: model.String(key, longString), - expected: KeyValue{Key: key, Value: longString, Type: "string"}, + expected: 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: 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: keyValue{Key: key, Value: "unknown type 1500", Type: "1500"}, }, } diff --git a/exporter/logzioexporter/logziospan.go b/exporter/logzioexporter/logziospan.go index 63a7ba772125..e3dd75cfc4e6 100644 --- a/exporter/logzioexporter/logziospan.go +++ b/exporter/logzioexporter/logziospan.go @@ -15,21 +15,21 @@ const ( tagDotReplacementCharacter = "@" ) -// logzioSpan is same as ESSpan with a few different json field names and an addition on type field. +// 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"` SpanID SpanID `json:"spanID"` OperationName string `json:"operationName,omitempty"` - References []Reference `json:"references"` + 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"` + Tags []keyValue `json:"JaegerTags,omitempty"` Tag map[string]any `json:"JaegerTag,omitempty"` - Logs []Log `json:"logs"` - Process Process `json:"process,omitempty"` + Logs []log `json:"logs"` + Process process `json:"process,omitempty"` Type string `json:"type"` } @@ -66,19 +66,19 @@ func transformToLogzioSpanBytes(span *model.Span) ([]byte, error) { } // only for testing transformToDbModelSpan coverts logz.io span to ElasticSearch span -func (span *logzioSpan) transformToDbModelSpan() *Span { - return &Span{ - OperationName: span.OperationName, - Process: span.Process, - Tags: span.Tags, - Tag: span.Tag, - References: span.References, - Logs: span.Logs, - Duration: span.Duration, - StartTimeMillis: span.StartTimeMillis, - StartTime: span.StartTime, - Flags: span.Flags, - SpanID: span.SpanID, - TraceID: span.TraceID, +func (logziospan *logzioSpan) transformToDbModelSpan() *span { + return &span{ + OperationName: logziospan.OperationName, + Process: logziospan.Process, + Tags: logziospan.Tags, + Tag: logziospan.Tag, + References: logziospan.References, + Logs: logziospan.Logs, + Duration: logziospan.Duration, + StartTimeMillis: logziospan.StartTimeMillis, + StartTime: logziospan.StartTime, + Flags: logziospan.Flags, + SpanID: logziospan.SpanID, + TraceID: logziospan.TraceID, } }