Skip to content

Commit

Permalink
DDG: Remove kind.server filter and handle service calling itself
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <[email protected]>
  • Loading branch information
rubenvp8510 committed Apr 14, 2020
1 parent 025f7af commit 0de01ca
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
33 changes: 20 additions & 13 deletions packages/jaeger-ui/src/model/ddg/transformTracesToPaths.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ describe('transform traces to ddg paths', () => {
})),
attributes: [{ key: 'exemplar_trace_id', value: trace.data.traceID }],
});
const makeSpan = (spanName, parent, kind) => ({
const makeSpan = (spanName, parent, kind, operationName, processID) => ({
hasChildren: true,
operationName: `${spanName} operation`,
processID: `${spanName} processID`,
operationName: operationName || `${spanName} operation`,
processID: processID || `${spanName} processID`,
references: parent
? [
{
Expand All @@ -52,7 +52,7 @@ describe('transform traces to ddg paths', () => {
(result, span) => ({
...result,
[span.processID]: {
serviceName: `${span.spanID.split(' ')[0]} service`,
serviceName: span.processID,
},
}),
{}
Expand Down Expand Up @@ -152,20 +152,27 @@ describe('transform traces to ddg paths', () => {
expect(result.length).toBe(1);
});

it("omits span if tags does not have span.kind === 'server'", () => {
const badSpanName = 'test bad span name';
it("omits span if tags does not have span.kind === 'server' and is followed by the same service", () => {
const spanServiceAServer = makeSpan('SpanA1', focalSpan, 'server', 'GET /customer', 'serviceA');
const spanServiceAClient = makeSpan('SpanA2', spanServiceAServer, 'client', 'GET /customer', 'serviceA');
spanServiceAClient.hasChildren = false;

const clientSpan = makeSpan(badSpanName, focalSpan, 'client');
clientSpan.hasChildren = false;
const clientTrace = makeTrace([rootSpan, focalSpan, clientSpan], 'clientTraceID');
const spanServiceAKindless = makeSpan('SpanA2', spanServiceAServer, false, 'GET /customer', 'serviceA');
spanServiceAKindless.hasChildren = false;

const kindlessSpan = makeSpan(badSpanName, focalSpan, false);
kindlessSpan.hasChildren = false;
const kindlessTrace = makeTrace([rootSpan, focalSpan, kindlessSpan], 'kindlessTraceID');
const clientTrace = makeTrace(
[rootSpan, focalSpan, spanServiceAServer, spanServiceAClient],
'clientTraceID'
);

const kindlessTrace = makeTrace(
[rootSpan, focalSpan, spanServiceAServer, spanServiceAKindless],
'kindlessTraceID'
);

const { dependencies: result } = transformTracesToPaths(makeTraces(clientTrace, kindlessTrace), focalSvc);

const path = makeExpectedPath([rootSpan, focalSpan], clientTrace);
const path = makeExpectedPath([rootSpan, focalSpan, spanServiceAServer], clientTrace);
path.attributes.push({ key: 'exemplar_trace_id', value: kindlessTrace.data.traceID });

expect(new Set(result)).toEqual(new Set([path]));
Expand Down
40 changes: 27 additions & 13 deletions packages/jaeger-ui/src/model/ddg/transformTracesToPaths.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { TDdgPayloadEntry, TDdgPayloadPath, TDdgPayload } from './types';
import { FetchedTrace } from '../../types';
import { Span } from '../../types/trace';

const isKindServer = (span: Span) =>
span.tags.find(({ key, value }) => key === 'span.kind' && value === 'server');

function transformTracesToPaths(
traces: Record<string, FetchedTrace>,
focalService: string,
Expand All @@ -35,22 +38,33 @@ function transformTracesToPaths(
spanMap.set(span.spanID, span);
return !span.hasChildren;
})

.forEach(leaf => {
const spans = spanAncestorIds(leaf).map(id => {
const ancestors = spanAncestorIds(leaf).reverse();
ancestors.push(leaf.spanID);
const spans = ancestors.reduce((reducedSpans: Span[], id: string): Span[] => {
const span = spanMap.get(id);
if (!span) throw new Error(`Ancestor spanID ${id} not found in trace ${traceID}`);
return span;
});
spans.reverse();
spans.push(leaf);

const path: TDdgPayloadEntry[] = spans
.filter(span => span.tags.find(({ key, value }) => key === 'span.kind' && value === 'server'))
.map(({ processID, operationName: operation }) => ({
service: data.processes[processID].serviceName,
operation,
}));

if (reducedSpans.length > 0) {
const headSpan = reducedSpans[reducedSpans.length - 1];
// Transition inside the same service ServiceA -> ServiceA
if (headSpan.processID === span.processID) {
if (isKindServer(span) && !isKindServer(headSpan)) {
reducedSpans.pop();
reducedSpans.push(span);
} else if (isKindServer(span) && isKindServer(headSpan)) {
reducedSpans.push(span);
}
return reducedSpans;
}
}
reducedSpans.push(span);
return reducedSpans;
}, []);
const path: TDdgPayloadEntry[] = spans.map(({ processID, operationName: operation }) => ({
service: data.processes[processID].serviceName,
operation,
}));
if (
path.some(
({ service, operation }) =>
Expand Down

0 comments on commit 0de01ca

Please sign in to comment.