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

Sort span tags in alphabetical order #489

Merged
merged 5 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions packages/jaeger-ui/src/constants/default-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default deepFreeze(
gaID: null,
trackErrors: true,
},
topTagPrefixes: ['http.'],
Copy link
Member

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?

Copy link
Contributor Author

@nabam nabam Dec 2, 2019

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
Screenshot 2019-12-02 at 10 01 14
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.

Copy link
Collaborator

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.

},
// fields that should be individually merged vs wholesale replaced
'__mergeFields',
Expand Down
51 changes: 51 additions & 0 deletions packages/jaeger-ui/src/model/transform-trace-data.test.js
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"']);
});
});
23 changes: 21 additions & 2 deletions packages/jaeger-ui/src/model/transform-trace-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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:

const aKey = a.key.toLowerCase();
const bKey = b.key.toLowerCase();

and then use aKey and bKey in place of a.key and b.key

and above tree.walk on line 111 I would add:

const prefixes = getConfigValue('topTagPrefixes');
const topTagPrefixes = prefixes && prefixes.map(p => p.toLowerCase())`;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that toLowerCase mapping can be done inside orderTags. It's a bit of performance loss but makes code more testable.

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.
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/jaeger-ui/src/types/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type Config = {
menu: (ConfigMenuGroup | ConfigMenuItem)[];
search?: { maxLookback: { label: string; value: string } };
scripts?: TScript[];
topTagPrefixes?: string[];
tracking?: {
gaID: string | TNil;
trackErrors: boolean | TNil;
Expand Down