Skip to content

Commit

Permalink
Dedupe search results DDG paths (jaegertracing#558)
Browse files Browse the repository at this point in the history
* Dedupled search results DDG paths

Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>

* Add deduplet ddg  paths test

Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
Signed-off-by: vvvprabhakar <vvvprabhakar@gmail.com>
  • Loading branch information
rubenvp8510 authored Apr 8, 2020
1 parent 5f63911 commit be92c6c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
22 changes: 16 additions & 6 deletions packages/jaeger-ui/src/model/ddg/transformTracesToPaths.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
});
});
31 changes: 20 additions & 11 deletions packages/jaeger-ui/src/model/ddg/transformTracesToPaths.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function transformTracesToPaths(
focalService: string,
focalOperation?: string
): TDdgPayload {
const dependencies: TDdgPayloadPath[] = [];
const dependenciesMap = new Map<String, TDdgPayloadPath>();
Object.values(traces).forEach(({ data }) => {
if (data) {
const spanMap: Map<string, Span> = new Map();
Expand Down Expand Up @@ -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 };
}

Expand Down

0 comments on commit be92c6c

Please sign in to comment.