-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[feat] Deduplicate spans based upon their hashcode #6009
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
88ecb83
clarify name of SpanIDDeduper
cdanis d5bdf14
rename zipkin-specific method as well
cdanis fdc22ca
fix comment
cdanis e5dc418
add DedupeSpansByID
cdanis ae4c914
add comment and test DedupeBySpanID
cdanis 18a9bab
add DedupeBySpanID to default adjusters
cdanis e847055
tweak zipkin adjuster name & move to new file
cdanis 5ee481b
fix up span id dedupe testing
cdanis ec81a10
More testing
cdanis 22cccca
fix flaky tests
cdanis 97eb7b5
rename
cdanis 3aeb4e5
group and dedupe by hashcode
cdanis d0dcc19
SortTagsAndLogFields
cdanis 824f56c
Update model/adjuster/span_hash_deduper_test.go
cdanis d525b2b
Update model/adjuster/span_hash_deduper.go
cdanis 6a31385
when hash deduping keep only first span
cdanis b11e5d3
Merge branch 'main' into dupe-dedupe
yurishkuro 128480a
Update model/adjuster/sort_tags_and_log_fields.go
cdanis 3dcc05c
add additional test
cdanis 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 hidden or 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
This file contains hidden or 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
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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,155 @@ | ||
| // Copyright (c) 2019 The Jaeger Authors. | ||
| // Copyright (c) 2017 Uber Technologies, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package adjuster | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/jaegertracing/jaeger/model" | ||
| ) | ||
|
|
||
| func TestSortTagsAndLogFieldsDoesSortFields(t *testing.T) { | ||
| testCases := []struct { | ||
| fields model.KeyValues | ||
| expected model.KeyValues | ||
| }{ | ||
| { | ||
| fields: model.KeyValues{ | ||
| model.String("event", "some event"), // event already in the first position, and no other fields | ||
| }, | ||
| expected: model.KeyValues{ | ||
| model.String("event", "some event"), | ||
| }, | ||
| }, | ||
| { | ||
| fields: model.KeyValues{ | ||
| model.Int64("event", 42), // non-string event field | ||
| model.Int64("a", 41), | ||
| }, | ||
| expected: model.KeyValues{ | ||
| model.Int64("a", 41), | ||
| model.Int64("event", 42), | ||
| }, | ||
| }, | ||
| { | ||
| fields: model.KeyValues{ | ||
| model.String("nonsense", "42"), // no event field | ||
| }, | ||
| expected: model.KeyValues{ | ||
| model.String("nonsense", "42"), | ||
| }, | ||
| }, | ||
| { | ||
| fields: model.KeyValues{ | ||
| model.String("event", "some event"), | ||
| model.Int64("a", 41), | ||
| }, | ||
| expected: model.KeyValues{ | ||
| model.String("event", "some event"), | ||
| model.Int64("a", 41), | ||
| }, | ||
| }, | ||
| { | ||
| fields: model.KeyValues{ | ||
| model.Int64("x", 1), | ||
| model.Int64("a", 2), | ||
| model.String("event", "some event"), | ||
| }, | ||
| expected: model.KeyValues{ | ||
| model.String("event", "some event"), | ||
| model.Int64("a", 2), | ||
| model.Int64("x", 1), | ||
| }, | ||
| }, | ||
| } | ||
| for _, testCase := range testCases { | ||
| trace := &model.Trace{ | ||
| Spans: []*model.Span{ | ||
| { | ||
| Logs: []model.Log{ | ||
| { | ||
| Fields: testCase.fields, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| trace, err := SortTagsAndLogFields().Adjust(trace) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, testCase.expected, model.KeyValues(trace.Spans[0].Logs[0].Fields)) | ||
| } | ||
| } | ||
|
|
||
| func TestSortTagsAndLogFieldsDoesSortTags(t *testing.T) { | ||
| testCases := []model.KeyValues{ | ||
| { | ||
| model.String("http.method", "GET"), | ||
| model.String("http.url", "http://wikipedia.org"), | ||
| model.Int64("http.status_code", 200), | ||
| model.String("guid:x-request-id", "f61defd2-7a77-11ef-b54f-4fbb67a6d181"), | ||
| }, | ||
| { | ||
| // empty | ||
| }, | ||
| { | ||
| model.String("argv", "mkfs.ext4 /dev/sda1"), | ||
| }, | ||
| } | ||
| for _, tags := range testCases { | ||
| trace := &model.Trace{ | ||
| Spans: []*model.Span{ | ||
| { | ||
| Tags: tags, | ||
| }, | ||
| }, | ||
| } | ||
| sorted, err := SortTagsAndLogFields().Adjust(trace) | ||
| require.NoError(t, err) | ||
| assert.ElementsMatch(t, tags, sorted.Spans[0].Tags) | ||
| adjustedKeys := make([]string, len(sorted.Spans[0].Tags)) | ||
| for i, kv := range sorted.Spans[0].Tags { | ||
| adjustedKeys[i] = kv.Key | ||
| } | ||
| assert.IsIncreasing(t, adjustedKeys) | ||
| } | ||
| } | ||
|
|
||
| func TestSortTagsAndLogFieldsDoesSortProcessTags(t *testing.T) { | ||
| trace := &model.Trace{ | ||
| Spans: []*model.Span{ | ||
| { | ||
| Process: &model.Process{ | ||
| Tags: model.KeyValues{ | ||
| model.String("process.argv", "mkfs.ext4 /dev/sda1"), | ||
| model.Int64("process.pid", 42), | ||
| model.Int64("process.uid", 0), | ||
| model.String("k8s.node.roles", "control-plane,etcd,master"), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| sorted, err := SortTagsAndLogFields().Adjust(trace) | ||
| require.NoError(t, err) | ||
| assert.ElementsMatch(t, trace.Spans[0].Process.Tags, sorted.Spans[0].Process.Tags) | ||
| adjustedKeys := make([]string, len(sorted.Spans[0].Process.Tags)) | ||
| for i, kv := range sorted.Spans[0].Process.Tags { | ||
| adjustedKeys[i] = kv.Key | ||
| } | ||
| assert.IsIncreasing(t, adjustedKeys) | ||
| } | ||
|
|
||
| func TestSortTagsAndLogFieldsHandlesNilProcessTags(t *testing.T) { | ||
| trace := &model.Trace{ | ||
| Spans: []*model.Span{ | ||
| {}, | ||
| }, | ||
| } | ||
| _, err := SortTagsAndLogFields().Adjust(trace) | ||
| require.NoError(t, err) | ||
| } |
This file contains hidden or 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,40 @@ | ||
| // Copyright (c) 2024 The Jaeger Authors. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package adjuster | ||
|
|
||
| import ( | ||
| "github.com/jaegertracing/jaeger/model" | ||
| ) | ||
|
|
||
| // DedupeBySpanHash returns an adjuster that removes all but one span with the same hashcode. | ||
| // This is useful for when spans are duplicated in archival storage, as happens with | ||
| // ElasticSearch archival. | ||
| func DedupeBySpanHash() Adjuster { | ||
| return Func(func(trace *model.Trace) (*model.Trace, error) { | ||
| deduper := &spanHashDeduper{trace: trace} | ||
| deduper.groupSpansByHash() | ||
| return deduper.trace, nil | ||
| }) | ||
| } | ||
|
|
||
| type spanHashDeduper struct { | ||
| trace *model.Trace | ||
| spansByHash map[uint64]*model.Span | ||
| } | ||
|
|
||
| func (d *spanHashDeduper) groupSpansByHash() { | ||
| spansByHash := make(map[uint64]*model.Span) | ||
| for _, span := range d.trace.Spans { | ||
| hash, _ := model.HashCode(span) | ||
yurishkuro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if _, ok := spansByHash[hash]; !ok { | ||
| spansByHash[hash] = span | ||
| } | ||
| } | ||
| d.spansByHash = spansByHash | ||
|
|
||
| d.trace.Spans = nil | ||
| for _, span := range d.spansByHash { | ||
| d.trace.Spans = append(d.trace.Spans, span) | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.