-
Notifications
You must be signed in to change notification settings - Fork 504
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
Sort span tags in alphabetical order #489
Changes from 3 commits
85a1a97
ca5884d
23af4a8
2eb7676
129d8ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2019 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { orderTags, deduplicateTags } from './transform-trace-data'; | ||
|
||
describe('orderTags()', () => { | ||
it('correctly orders tags', () => { | ||
const orderedTags = orderTags( | ||
[ | ||
nabam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ key: 'b.ip', value: '8.8.4.4' }, | ||
{ key: 'http.status_code', value: '200' }, | ||
{ key: 'a.ip', value: '8.8.8.8' }, | ||
], | ||
['http.'] | ||
); | ||
expect(orderedTags).toEqual([ | ||
{ key: 'http.status_code', value: '200' }, | ||
{ key: 'a.ip', value: '8.8.8.8' }, | ||
{ key: 'b.ip', value: '8.8.4.4' }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('deduplicateTags()', () => { | ||
it('deduplicates tags', () => { | ||
const tagsInfo = deduplicateTags([ | ||
{ key: 'b.ip', value: '8.8.4.4' }, | ||
{ key: 'b.ip', value: '8.8.8.8' }, | ||
{ key: 'b.ip', value: '8.8.4.4' }, | ||
{ key: 'a.ip', value: '8.8.8.8' }, | ||
]); | ||
|
||
expect(tagsInfo.tags).toEqual([ | ||
{ key: 'b.ip', value: '8.8.4.4' }, | ||
{ key: 'b.ip', value: '8.8.8.8' }, | ||
{ key: 'a.ip', value: '8.8.8.8' }, | ||
]); | ||
expect(tagsInfo.warnings).toEqual(['Duplicate tag "b.ip:8.8.4.4"']); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,11 @@ | |
import _isEqual from 'lodash/isEqual'; | ||
|
||
import { getTraceSpanIdsAsTree } from '../selectors/trace'; | ||
import { getConfigValue } from '../utils/config/get-config'; | ||
import { KeyValuePair, Span, SpanData, Trace, TraceData } from '../types/trace'; | ||
import TreeNode from '../utils/TreeNode'; | ||
|
||
function deduplicateTags(spanTags: Array<KeyValuePair>) { | ||
export function deduplicateTags(spanTags: Array<KeyValuePair>) { | ||
nabam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const warningsHash: Map<string, string> = new Map<string, string>(); | ||
const tags: Array<KeyValuePair> = spanTags.reduce<Array<KeyValuePair>>((uniqueTags, tag) => { | ||
if (!uniqueTags.some(t => t.key === tag.key && t.value === tag.value)) { | ||
|
@@ -32,6 +33,24 @@ function deduplicateTags(spanTags: Array<KeyValuePair>) { | |
return { tags, warnings }; | ||
} | ||
|
||
export function orderTags(spanTags: Array<KeyValuePair>, topPrefixes: Array<string>) { | ||
nabam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const orderedTags: Array<KeyValuePair> = [...spanTags]; | ||
nabam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
orderedTags.sort((a, b) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be case insensitive, so below this I would add:
and then use and above
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that |
||
for (let i = 0; i < topPrefixes.length; i++) { | ||
nabam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const p = topPrefixes[i]; | ||
if (a.key.startsWith(p) && !b.key.startsWith(p)) { | ||
return -1; | ||
} | ||
|
||
if (!a.key.startsWith(p) && b.key.startsWith(p)) { | ||
return 1; | ||
} | ||
} | ||
return a.key.localeCompare(b.key); | ||
nabam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
return orderedTags; | ||
} | ||
|
||
/** | ||
* NOTE: Mutates `data` - Transform the HTTP response data into the form the app | ||
* generally requires. | ||
|
@@ -109,7 +128,7 @@ export default function transformTraceData(data: TraceData & { spans: SpanData[] | |
span.tags = span.tags || []; | ||
span.references = span.references || []; | ||
const tagsInfo = deduplicateTags(span.tags); | ||
span.tags = tagsInfo.tags; | ||
span.tags = orderTags(tagsInfo.tags, getConfigValue('topTagPrefixes') || []); | ||
span.warnings = span.warnings.concat(tagsInfo.warnings); | ||
span.references.forEach(ref => { | ||
const refSpan = spanMap.get(ref.spanID) as Span; | ||
|
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.
the priority sorting feels contrary to the intention of this PR. Is it really necessary?
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.
Sorting by itself makes it much easier to find relevant information in a trace compare to experience with tags in the random order. At least the tag one is trying to follow is at the same position in every span.
I was trying to find a way to access tags that that are more relevant than others faster. Issue #218 mentions that and in my installation I have a similar problem
Without priority sorting I would have to name tags the way they are alphabetically in order of importance to get most relevant ones in that view.
Though I bet there are more elegant solutions for that UX problem than priority sorting. I think it's quite a standard approach to have many tags some of which are used rarely for things like troubleshooting corner cases and others are crucial for most of the usage scenarios.
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.
I like the priority sorting as a config option, but I wouldn't add a default value.