Skip to content

Commit

Permalink
Dedupled search results DDG paths
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
  • Loading branch information
rubenvp8510 committed Apr 8, 2020
1 parent 2ba4e7f commit 402be04
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
11 changes: 5 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,10 @@ 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]));
});
});
32 changes: 21 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,8 @@ 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 +58,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 402be04

Please sign in to comment.