From be92c6cebda6e1bfcad4564bd22dcb2375821b4a Mon Sep 17 00:00:00 2001 From: Ruben Vargas Palma Date: Wed, 8 Apr 2020 18:33:11 -0500 Subject: [PATCH] Dedupe search results DDG paths (#558) * Dedupled search results DDG paths Signed-off-by: Ruben Vargas * Add deduplet ddg paths test Signed-off-by: Ruben Vargas Signed-off-by: vvvprabhakar --- .../model/ddg/transformTracesToPaths.test.js | 22 +++++++++---- .../src/model/ddg/transformTracesToPaths.tsx | 31 ++++++++++++------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.test.js b/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.test.js index 9980512ed0..2b3942d8b9 100644 --- a/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.test.js +++ b/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.test.js @@ -164,11 +164,21 @@ describe('transform traces to ddg paths', () => { const kindlessTrace = makeTrace([rootSpan, focalSpan, kindlessSpan], 'kindlessTraceID'); const { dependencies: result } = transformTracesToPaths(makeTraces(clientTrace, kindlessTrace), focalSvc); - expect(new Set(result)).toEqual( - new Set([ - makeExpectedPath([rootSpan, focalSpan], clientTrace), - makeExpectedPath([rootSpan, focalSpan], kindlessTrace), - ]) - ); + + const path = makeExpectedPath([rootSpan, focalSpan], clientTrace); + path.attributes.push({ key: 'exemplar_trace_id', value: kindlessTrace.data.traceID }); + + expect(new Set(result)).toEqual(new Set([path])); + }); + + it('dedupled paths', () => { + const otherSpan = makeSpan('other-span', focalSpan); + otherSpan.hasChildren = false; + const trace1 = makeTrace([rootSpan, focalSpan, otherSpan], 'trace1'); + const trace2 = makeTrace([rootSpan, focalSpan, otherSpan], 'trace2'); + const { dependencies: result } = transformTracesToPaths(makeTraces(trace1, trace2), focalSvc); + const path = makeExpectedPath([rootSpan, focalSpan, otherSpan], trace1); + path.attributes.push({ key: 'exemplar_trace_id', value: trace2.data.traceID }); + expect(new Set(result)).toEqual(new Set([path])); }); }); diff --git a/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.tsx b/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.tsx index 76e7b10c59..4f381d0b9e 100644 --- a/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.tsx +++ b/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.tsx @@ -25,7 +25,7 @@ function transformTracesToPaths( focalService: string, focalOperation?: string ): TDdgPayload { - const dependencies: TDdgPayloadPath[] = []; + const dependenciesMap = new Map(); Object.values(traces).forEach(({ data }) => { if (data) { const spanMap: Map = new Map(); @@ -57,20 +57,29 @@ function transformTracesToPaths( service === focalService && (!focalOperation || operation === focalOperation) ) ) { - // TODO: Paths should be deduped with all traceIDs #503 - dependencies.push({ - path, - attributes: [ - { - key: 'exemplar_trace_id', - value: traceID, - }, - ], - }); + const pathKey = path.map(value => `${value.operation}:${value.service}`).join('/'); + const dependency = dependenciesMap.get(pathKey); + if (!dependency) { + dependenciesMap.set(pathKey, { + path, + attributes: [ + { + key: 'exemplar_trace_id', + value: traceID, + }, + ], + }); + } else { + dependency.attributes.push({ + key: 'exemplar_trace_id', + value: traceID, + }); + } } }); } }); + const dependencies = Array.from(dependenciesMap.values()); return { dependencies }; }