From f303fae8c78bccfefcf67e83936cc11475df003f Mon Sep 17 00:00:00 2001 From: luhualin Date: Fri, 27 Nov 2020 12:32:39 +0800 Subject: [PATCH 1/3] dedup collector tags Signed-off-by: luhualin --- cmd/collector/app/span_processor.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/collector/app/span_processor.go b/cmd/collector/app/span_processor.go index 3a568a5d0b7..78624f6931b 100644 --- a/cmd/collector/app/span_processor.go +++ b/cmd/collector/app/span_processor.go @@ -178,9 +178,17 @@ 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 + dedupKey := make(map[string]struct{}) + for _, tag := range span.Process.Tags { + if value, ok := sp.collectorTags[tag.Key]; ok && value == tag.AsString() { + dedupKey[tag.Key] = struct{}{} + } + } + // 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)) + } } } From 72c187360731dae6afccf2b4420d945ba659c9ff Mon Sep 17 00:00:00 2001 From: luhualin Date: Mon, 30 Nov 2020 18:42:53 +0800 Subject: [PATCH 2/3] revise debug log Signed-off-by: luhualin --- cmd/collector/app/span_processor.go | 3 ++ cmd/collector/app/span_processor_test.go | 49 ++++++++++++++++-------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/cmd/collector/app/span_processor.go b/cmd/collector/app/span_processor.go index 78624f6931b..794244dfd8f 100644 --- a/cmd/collector/app/span_processor.go +++ b/cmd/collector/app/span_processor.go @@ -181,6 +181,7 @@ func (sp *spanProcessor) addCollectorTags(span *model.Span) { dedupKey := make(map[string]struct{}) 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{}{} } } @@ -190,6 +191,8 @@ func (sp *spanProcessor) addCollectorTags(span *model.Span) { span.Process.Tags = append(span.Process.Tags, model.String(k, v)) } } + typedTags := model.KeyValues(span.Process.Tags) + typedTags.Sort() } func (sp *spanProcessor) enqueueSpan(span *model.Span, originalFormat processor.SpanFormat, transport processor.InboundTransport) bool { diff --git a/cmd/collector/app/span_processor_test.go b/cmd/collector/app/span_processor_test.go index ee828ac717b..67f358745a7 100644 --- a/cmd/collector/app/span_processor_test.go +++ b/cmd/collector/app/span_processor_test.go @@ -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) { From 3fb570410cb483baf73ed76acc913d6741281ae0 Mon Sep 17 00:00:00 2001 From: luhualin Date: Mon, 7 Dec 2020 10:57:55 +0800 Subject: [PATCH 3/3] skip add tags if empty Signed-off-by: luhualin --- cmd/collector/app/span_processor.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/collector/app/span_processor.go b/cmd/collector/app/span_processor.go index 794244dfd8f..119e66ece66 100644 --- a/cmd/collector/app/span_processor.go +++ b/cmd/collector/app/span_processor.go @@ -178,6 +178,9 @@ func (sp *spanProcessor) processItemFromQueue(item *queueItem) { } func (sp *spanProcessor) addCollectorTags(span *model.Span) { + if len(sp.collectorTags) == 0 { + return + } dedupKey := make(map[string]struct{}) for _, tag := range span.Process.Tags { if value, ok := sp.collectorTags[tag.Key]; ok && value == tag.AsString() {