Skip to content

Commit

Permalink
revise debug log
Browse files Browse the repository at this point in the history
Signed-off-by: luhualin <luhualin@bilibili.com>
  • Loading branch information
Betula-L committed Nov 30, 2020
1 parent f303fae commit 72c1873
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
3 changes: 3 additions & 0 deletions cmd/collector/app/span_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
}
}
Expand All @@ -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 {
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

0 comments on commit 72c1873

Please sign in to comment.