Skip to content

Commit

Permalink
test tags deduplication
Browse files Browse the repository at this point in the history
Signed-off-by: Lev Popov <leo@nabam.net>
  • Loading branch information
nabam committed Nov 28, 2019
1 parent ca5884d commit 6fff972
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion packages/jaeger-ui/src/model/transform-trace-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { orderTags } from './transform-trace-data';
import { orderTags, deduplicateTags } from './transform-trace-data';

describe('orderTags()', () => {
it('correctly orders tags', () => {
Expand All @@ -31,3 +31,23 @@ describe('orderTags()', () => {
]);
});
});

describe('deduplicateTags()', () => {
it('deduplicates tags', () => {
const tagsInfo = deduplicateTags([
{ key: 'b.ip', value: '8.8.4.4' },
{ key: 'b.ip', value: '8.8.4.4' },
{ key: 'b.ip', value: '8.8.8.8' },
{ key: 'http.status_code', value: '200' },
{ 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: 'http.status_code', value: '200' },
{ key: 'a.ip', value: '8.8.8.8' },
]);
expect(tagsInfo.warnings).toEqual(['Duplicate tag "b.ip:8.8.4.4"']);
});
});
2 changes: 1 addition & 1 deletion packages/jaeger-ui/src/model/transform-trace-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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>) {
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 Down

0 comments on commit 6fff972

Please sign in to comment.