Skip to content
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

Dedup collector tags #2658

Merged
merged 3 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions cmd/collector/app/span_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,24 @@ func (sp *spanProcessor) processItemFromQueue(item *queueItem) {
}

func (sp *spanProcessor) addCollectorTags(span *model.Span) {
// TODO add support for deduping tags, https://github.com/jaegertracing/jaeger/issues/1778
if len(sp.collectorTags) == 0 {
return
}
dedupKey := make(map[string]struct{})
Betula-L marked this conversation as resolved.
Show resolved Hide resolved
for _, tag := range span.Process.Tags {
if value, ok := sp.collectorTags[tag.Key]; ok && value == tag.AsString() {
sp.logger.Debug("ignore collector process tags", zap.String("key", tag.Key), zap.String("value", value))
dedupKey[tag.Key] = struct{}{}
Betula-L marked this conversation as resolved.
Show resolved Hide resolved
}
}
// ignore collector tags if has the same key-value in spans
for k, v := range sp.collectorTags {
span.Process.Tags = append(span.Process.Tags, model.String(k, v))
if _, ok := dedupKey[k]; !ok {
span.Process.Tags = append(span.Process.Tags, model.String(k, v))
}
}
typedTags := model.KeyValues(span.Process.Tags)
typedTags.Sort()
Betula-L marked this conversation as resolved.
Show resolved Hide resolved
}

func (sp *spanProcessor) enqueueSpan(span *model.Span, originalFormat processor.SpanFormat, transport processor.InboundTransport) bool {
Expand Down
49 changes: 34 additions & 15 deletions cmd/collector/app/span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,32 +333,51 @@ func TestSpanProcessorWithNilProcess(t *testing.T) {
}

func TestSpanProcessorWithCollectorTags(t *testing.T) {

testCollectorTags := map[string]string{
"extra": "tag",
"env": "prod",
"node": "172.22.18.161",
}

w := &fakeSpanWriter{}
p := NewSpanProcessor(w, Options.CollectorTags(testCollectorTags)).(*spanProcessor)
defer assert.NoError(t, p.Close())

defer assert.NoError(t, p.Close())
span := &model.Span{
Process: model.NewProcess("unit-test-service", []model.KeyValue{}),
Process: model.NewProcess("unit-test-service", []model.KeyValue{
{
Key: "env",
VStr: "prod",
},
{
Key: "node",
VStr: "k8s-test-node-01",
},
}),
}

p.addCollectorTags(span)

for k, v := range testCollectorTags {
var foundTag bool
for _, tag := range span.Process.Tags {
if tag.GetKey() == k {
assert.Equal(t, v, tag.AsString())
foundTag = true
break
}
}
assert.True(t, foundTag)
expected := &model.Span{
Process: model.NewProcess("unit-test-service", []model.KeyValue{
{
Key: "env",
VStr: "prod",
},
{
Key: "extra",
VStr: "tag",
},
{
Key: "node",
VStr: "172.22.18.161",
},
{
Key: "node",
VStr: "k8s-test-node-01",
},
}),
}

assert.Equal(t, expected.Process, span.Process)
}

func TestSpanProcessorCountSpan(t *testing.T) {
Expand Down