-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[exporter] Remove jaeger dbmodel dependency #36972
Open
zzzk1
wants to merge
10
commits into
open-telemetry:main
Choose a base branch
from
zzzk1:remove-dbmodel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+458
−38
Open
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4421218
[exporter] Remove jaeger dbmodel dependency
zzzk1 2a9709a
add unit test
zzzk1 d99381b
remove dependency
zzzk1 4f7013a
add changelog
zzzk1 bd606ce
public -> private
zzzk1 c575410
rename `log` struct
zzzk1 9a2c51b
remove to dbmodel package
zzzk1 b71bb84
improve test
zzzk1 fede1cc
remove to internal
zzzk1 a045394
remove back 0.0
zzzk1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: logzioexporter | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Remove jaeger dbmodel dependency. | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [36972] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [user] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
// Copyright (c) 2019 The Jaeger Authors. | ||
// Copyright (c) 2018 Uber Technologies, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package logzioexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/logzioexporter" | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
) | ||
|
||
// ReferenceType is the reference type of one span to another | ||
type ReferenceType string | ||
|
||
// TraceID is the shared trace ID of all spans in the trace. | ||
type TraceID string | ||
|
||
// SpanID is the id of a span | ||
type SpanID string | ||
|
||
// ValueType is the type of a value stored in keyValue struct. | ||
type ValueType string | ||
|
||
const ( | ||
// ChildOf means a span is the child of another span | ||
ChildOf ReferenceType = "CHILD_OF" | ||
// FollowsFrom means a span follows from another span | ||
FollowsFrom ReferenceType = "FOLLOWS_FROM" | ||
|
||
// StringType indicates a string value stored in keyValue | ||
StringType ValueType = "string" | ||
// BoolType indicates a Boolean value stored in keyValue | ||
BoolType ValueType = "bool" | ||
// Int64Type indicates a 64bit signed integer value stored in keyValue | ||
Int64Type ValueType = "int64" | ||
// Float64Type indicates a 64bit float value stored in keyValue | ||
Float64Type ValueType = "float64" | ||
// BinaryType indicates an arbitrary byte array stored in keyValue | ||
BinaryType ValueType = "binary" | ||
) | ||
|
||
// 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 { | ||
ServiceName string `json:"serviceName"` | ||
Tags []keyValue `json:"tags"` | ||
// Alternative representation of tags for better kibana support | ||
Tag map[string]any `json:"tag,omitempty"` | ||
} | ||
|
||
// spanLog is a log emitted in a span | ||
type spanLog struct { | ||
Timestamp uint64 `json:"timestamp"` | ||
Fields []keyValue `json:"fields"` | ||
} | ||
|
||
// 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 { | ||
ServiceName string `json:"serviceName"` | ||
OperationName string `json:"operationName"` | ||
} | ||
|
||
// 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"` | ||
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"` | ||
// Alternative representation of tags for better kibana support | ||
Tag map[string]any `json:"tag,omitempty"` | ||
Logs []spanLog `json:"logs"` | ||
Process process `json:"process,omitempty"` | ||
} | ||
|
||
// newFromDomain creates fromDomain used to convert model span to db span | ||
func newFromDomain(allTagsAsObject bool, tagKeysAsFields []string, tagDotReplacement string) fromDomain { | ||
tags := map[string]bool{} | ||
for _, k := range tagKeysAsFields { | ||
tags[k] = true | ||
} | ||
return fromDomain{allTagsAsFields: allTagsAsObject, tagKeysAsFields: tags, tagDotReplacement: tagDotReplacement} | ||
} | ||
|
||
// fromDomain is used to convert model span to db span | ||
type fromDomain struct { | ||
allTagsAsFields bool | ||
tagKeysAsFields map[string]bool | ||
tagDotReplacement string | ||
} | ||
|
||
// 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) | ||
} | ||
|
||
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()), | ||
Flags: uint32(span.Flags), | ||
OperationName: span.OperationName, | ||
StartTime: model.TimeAsEpochMicroseconds(span.StartTime), | ||
StartTimeMillis: model.TimeAsEpochMicroseconds(span.StartTime) / 1000, | ||
Duration: model.DurationAsMicroseconds(span.Duration), | ||
Tags: tags, | ||
Tag: tagsMap, | ||
Logs: fd.convertLogs(span.Logs), | ||
} | ||
} | ||
|
||
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)) | ||
for _, ref := range span.References { | ||
out = append(out, reference{ | ||
RefType: fd.convertRefType(ref.RefType), | ||
TraceID: TraceID(ref.TraceID.String()), | ||
SpanID: SpanID(ref.SpanID.String()), | ||
}) | ||
} | ||
return out | ||
} | ||
|
||
func (fromDomain) convertRefType(refType model.SpanRefType) ReferenceType { | ||
if refType == model.FollowsFrom { | ||
return FollowsFrom | ||
} | ||
return ChildOf | ||
} | ||
|
||
func (fd fromDomain) convertKeyValuesString(keyValues model.KeyValues) ([]keyValue, map[string]any) { | ||
var tagsMap map[string]any | ||
var kvs []keyValue | ||
for _, kv := range keyValues { | ||
if kv.GetVType() != model.BinaryType && (fd.allTagsAsFields || fd.tagKeysAsFields[kv.Key]) { | ||
if tagsMap == nil { | ||
tagsMap = map[string]any{} | ||
} | ||
tagsMap[strings.ReplaceAll(kv.Key, ".", fd.tagDotReplacement)] = kv.Value() | ||
} else { | ||
kvs = append(kvs, convertKeyValue(kv)) | ||
} | ||
} | ||
if kvs == nil { | ||
kvs = make([]keyValue, 0) | ||
} | ||
return kvs, tagsMap | ||
} | ||
|
||
func (fromDomain) convertLogs(logs []model.Log) []spanLog { | ||
out := make([]spanLog, len(logs)) | ||
for i, l := range logs { | ||
var kvs []keyValue | ||
for _, kv := range l.Fields { | ||
kvs = append(kvs, convertKeyValue(kv)) | ||
} | ||
out[i] = spanLog{ | ||
Timestamp: model.TimeAsEpochMicroseconds(l.Timestamp), | ||
Fields: kvs, | ||
} | ||
} | ||
return out | ||
} | ||
|
||
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{ | ||
Key: kv.Key, | ||
Type: ValueType(strings.ToLower(kv.VType.String())), | ||
Value: kv.AsString(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// Copyright (c) 2019 The Jaeger Authors. | ||
// Copyright (c) 2018 Uber Technologies, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package logzioexporter | ||
|
||
import ( | ||
"bytes" | ||
"encoding/hex" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/gogo/protobuf/jsonpb" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
) | ||
|
||
func TestFromDomainEmbedProcess(t *testing.T) { | ||
domainStr, jsonStr := loadFixtures(t) | ||
|
||
var span model.Span | ||
require.NoError(t, jsonpb.Unmarshal(bytes.NewReader(domainStr), &span)) | ||
converter := newFromDomain(false, nil, ":") | ||
embeddedSpan := converter.fromDomainEmbedProcess(&span) | ||
|
||
var expectedSpan logzioSpan | ||
require.NoError(t, json.Unmarshal(jsonStr, &expectedSpan)) | ||
|
||
testJSONEncoding(t, jsonStr, embeddedSpan.transformToDbModelSpan()) | ||
} | ||
|
||
// Loads and returns domain model and JSON model fixtures with given number i. | ||
func loadFixtures(t *testing.T) ([]byte, []byte) { | ||
in := fmt.Sprintf("./testdata/span.json") | ||
inStr, err := os.ReadFile(in) | ||
require.NoError(t, err) | ||
out := fmt.Sprintf("./testdata/es.json") | ||
outStr, err := os.ReadFile(out) | ||
require.NoError(t, err) | ||
return inStr, outStr | ||
} | ||
|
||
func testJSONEncoding(t *testing.T, expectedStr []byte, object any) { | ||
buf := &bytes.Buffer{} | ||
enc := json.NewEncoder(buf) | ||
enc.SetIndent("", " ") | ||
|
||
outFile := fmt.Sprintf("./testdata/es.json") | ||
require.NoError(t, enc.Encode(object)) | ||
|
||
if !assert.Equal(t, string(expectedStr), buf.String()) { | ||
err := os.WriteFile(outFile+"-actual.json", buf.Bytes(), 0o644) | ||
require.NoError(t, err) | ||
} | ||
} | ||
|
||
func TestEmptyTags(t *testing.T) { | ||
tags := make([]model.KeyValue, 0) | ||
span := model.Span{Tags: tags, Process: &model.Process{Tags: tags}} | ||
converter := newFromDomain(false, nil, ":") | ||
dbSpan := converter.fromDomainEmbedProcess(&span) | ||
assert.Empty(t, dbSpan.Tags) | ||
assert.Empty(t, dbSpan.Tag) | ||
} | ||
|
||
func TestTagMap(t *testing.T) { | ||
tags := []model.KeyValue{ | ||
model.String("foo", "foo"), | ||
model.Bool("a", true), | ||
model.Int64("b.b", 1), | ||
} | ||
span := model.Span{Tags: tags, Process: &model.Process{Tags: tags}} | ||
converter := newFromDomain(false, []string{"a", "b.b", "b*"}, ":") | ||
dbSpan := converter.fromDomainEmbedProcess(&span) | ||
|
||
assert.Len(t, dbSpan.Tags, 1) | ||
assert.Equal(t, "foo", dbSpan.Tags[0].Key) | ||
assert.Len(t, dbSpan.Process.Tags, 1) | ||
assert.Equal(t, "foo", dbSpan.Process.Tags[0].Key) | ||
|
||
tagsMap := map[string]any{} | ||
tagsMap["a"] = true | ||
tagsMap["b:b"] = int64(1) | ||
assert.Equal(t, tagsMap, dbSpan.Tag) | ||
assert.Equal(t, tagsMap, dbSpan.Process.Tag) | ||
} | ||
|
||
func TestConvertKeyValueValue(t *testing.T) { | ||
longString := `Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues | ||
Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues | ||
Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues | ||
Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues | ||
Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues Bender Bending Rodrigues ` | ||
key := "key" | ||
tests := []struct { | ||
kv model.KeyValue | ||
expected keyValue | ||
}{ | ||
{ | ||
kv: model.Bool(key, true), | ||
expected: keyValue{Key: key, Value: "true", Type: "bool"}, | ||
}, | ||
{ | ||
kv: model.Bool(key, false), | ||
expected: keyValue{Key: key, Value: "false", Type: "bool"}, | ||
}, | ||
{ | ||
kv: model.Int64(key, int64(1499)), | ||
expected: keyValue{Key: key, Value: "1499", Type: "int64"}, | ||
}, | ||
{ | ||
kv: model.Float64(key, float64(15.66)), | ||
expected: keyValue{Key: key, Value: "15.66", Type: "float64"}, | ||
}, | ||
{ | ||
kv: model.String(key, longString), | ||
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"}, | ||
}, | ||
{ | ||
kv: model.KeyValue{VType: 1500, Key: key}, | ||
expected: keyValue{Key: key, Value: "unknown type 1500", Type: "1500"}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(fmt.Sprintf("%s:%s", test.expected.Type, test.expected.Key), func(t *testing.T) { | ||
actual := convertKeyValue(test.kv) | ||
assert.Equal(t, test.expected, actual) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this type needed? why not use logziospan?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit test
fromDomain_test.go
needs this struct to compare