From dfd4838a4eb3a098f8db84ac86f621dcb2dbaec6 Mon Sep 17 00:00:00 2001 From: Ruben Vargas Date: Sat, 4 Apr 2020 09:34:19 -0600 Subject: [PATCH] DDG: Remove kind.server filter and handle service calling itself Signed-off-by: Ruben Vargas --- .../model/ddg/transformTracesToPaths.test.js | 53 +++++++++++++------ .../src/model/ddg/transformTracesToPaths.tsx | 41 +++++++++----- 2 files changed, 66 insertions(+), 28 deletions(-) diff --git a/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.test.js b/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.test.js index 2b3942d8b9..8c99af6ed6 100644 --- a/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.test.js +++ b/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.test.js @@ -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 ? [ { @@ -52,7 +52,7 @@ describe('transform traces to ddg paths', () => { (result, span) => ({ ...result, [span.processID]: { - serviceName: `${span.spanID.split(' ')[0]} service`, + serviceName: span.processID, }, }), {} @@ -152,23 +152,46 @@ 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 otherSpanServiceAServer = makeSpan('SpanA3', spanServiceAServer, 'server', 'otherop', 'serviceA'); + otherSpanServiceAServer.hasChildren = false; - const clientSpan = makeSpan(badSpanName, focalSpan, 'client'); - clientSpan.hasChildren = false; - const clientTrace = makeTrace([rootSpan, focalSpan, clientSpan], 'clientTraceID'); + const spanServiceAClient = makeSpan('SpanA2', spanServiceAServer, 'client', 'GET /customer', 'serviceA'); + spanServiceAClient.hasChildren = false; - const kindlessSpan = makeSpan(badSpanName, focalSpan, false); - kindlessSpan.hasChildren = false; - const kindlessTrace = makeTrace([rootSpan, focalSpan, kindlessSpan], 'kindlessTraceID'); + const spanServiceAKindless = makeSpan('SpanA2', spanServiceAServer, false, 'GET /customer', 'serviceA'); + spanServiceAKindless.hasChildren = false; - const { dependencies: result } = transformTracesToPaths(makeTraces(clientTrace, kindlessTrace), focalSvc); + const clientTrace = makeTrace( + [rootSpan, focalSpan, spanServiceAServer, spanServiceAClient], + 'clientTraceID' + ); + + const kindlessTrace = makeTrace( + [rootSpan, focalSpan, spanServiceAServer, spanServiceAKindless], + 'kindlessTraceID' + ); + + const twoServersTrace = makeTrace( + [rootSpan, focalSpan, spanServiceAServer, otherSpanServiceAServer], + 'twoServersTraceID' + ); + + const { dependencies: result } = transformTracesToPaths( + makeTraces(clientTrace, kindlessTrace, twoServersTrace), + 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])); + expect(new Set(result)).toEqual( + new Set([ + path, + makeExpectedPath([rootSpan, focalSpan, spanServiceAServer, otherSpanServiceAServer], twoServersTrace), + ]) + ); }); it('dedupled paths', () => { diff --git a/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.tsx b/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.tsx index 4f381d0b9e..657f95eee0 100644 --- a/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.tsx +++ b/packages/jaeger-ui/src/model/ddg/transformTracesToPaths.tsx @@ -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, focalService: string, @@ -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 }) => @@ -59,6 +73,7 @@ function transformTracesToPaths( ) { const pathKey = path.map(value => `${value.operation}:${value.service}`).join('/'); const dependency = dependenciesMap.get(pathKey); + console.log(traceID); if (!dependency) { dependenciesMap.set(pathKey, { path,