Commit 0f964c02 by Andrej Ocenas Committed by GitHub

Zipkin: Fix error when span contains remoteEndpoint (#24524)

parent 8e5a3a57
...@@ -5,16 +5,20 @@ export type ZipkinSpan = { ...@@ -5,16 +5,20 @@ export type ZipkinSpan = {
id: string; id: string;
timestamp: number; timestamp: number;
duration: number; duration: number;
localEndpoint: { localEndpoint?: ZipkinEndpoint;
serviceName: string; remoteEndpoint?: ZipkinEndpoint;
ipv4: string;
port?: number;
};
annotations?: ZipkinAnnotation[]; annotations?: ZipkinAnnotation[];
tags?: { [key: string]: string }; tags?: { [key: string]: string };
kind?: 'CLIENT' | 'SERVER' | 'PRODUCER' | 'CONSUMER'; kind?: 'CLIENT' | 'SERVER' | 'PRODUCER' | 'CONSUMER';
}; };
export type ZipkinEndpoint = {
serviceName: string;
ipv4?: string;
ipv6?: string;
port?: number;
};
export type ZipkinAnnotation = { export type ZipkinAnnotation = {
timestamp: number; timestamp: number;
value: string; value: string;
......
...@@ -45,6 +45,18 @@ export const zipkinResponse: ZipkinSpan[] = [ ...@@ -45,6 +45,18 @@ export const zipkinResponse: ZipkinSpan[] = [
error: '404', error: '404',
}, },
}, },
{
traceId: 'trace_id',
parentId: 'span 1 id',
name: 'span 3',
id: 'span 3 id',
timestamp: 6,
duration: 7,
remoteEndpoint: {
serviceName: 'spanstore-jdbc',
ipv6: '127.0.0.1',
},
},
]; ];
export const jaegerTrace: TraceData & { spans: SpanData[] } = { export const jaegerTrace: TraceData & { spans: SpanData[] } = {
...@@ -74,6 +86,16 @@ export const jaegerTrace: TraceData & { spans: SpanData[] } = { ...@@ -74,6 +86,16 @@ export const jaegerTrace: TraceData & { spans: SpanData[] } = {
}, },
], ],
}, },
'spanstore-jdbc': {
serviceName: 'spanstore-jdbc',
tags: [
{
key: 'ipv6',
type: 'string',
value: '127.0.0.1',
},
],
},
}, },
traceID: 'trace_id', traceID: 'trace_id',
warnings: null, warnings: null,
...@@ -141,5 +163,24 @@ export const jaegerTrace: TraceData & { spans: SpanData[] } = { ...@@ -141,5 +163,24 @@ export const jaegerTrace: TraceData & { spans: SpanData[] } = {
}, },
], ],
}, },
{
duration: 7,
flags: 1,
logs: [],
operationName: 'span 3',
processID: 'spanstore-jdbc',
startTime: 6,
tags: [],
spanID: 'span 3 id',
traceID: 'trace_id',
warnings: null as any,
references: [
{
refType: 'CHILD_OF',
spanID: 'span 1 id',
traceID: 'trace_id',
},
],
},
], ],
}; };
import { identity } from 'lodash'; import { identity } from 'lodash';
import { keyBy } from 'lodash'; import { keyBy } from 'lodash';
import { ZipkinAnnotation, ZipkinSpan } from '../types'; import { ZipkinAnnotation, ZipkinEndpoint, ZipkinSpan } from '../types';
import { KeyValuePair, Log, Process, SpanData, TraceData } from '@jaegertracing/jaeger-ui-components'; import { KeyValuePair, Log, Process, SpanData, TraceData } from '@jaegertracing/jaeger-ui-components';
/** /**
...@@ -22,7 +22,7 @@ function transformSpan(span: ZipkinSpan): SpanData { ...@@ -22,7 +22,7 @@ function transformSpan(span: ZipkinSpan): SpanData {
flags: 1, flags: 1,
logs: span.annotations?.map(transformAnnotation) ?? [], logs: span.annotations?.map(transformAnnotation) ?? [],
operationName: span.name, operationName: span.name,
processID: span.localEndpoint.serviceName, processID: span.localEndpoint?.serviceName || span.remoteEndpoint?.serviceName || 'unknown',
startTime: span.timestamp, startTime: span.timestamp,
spanID: span.id, spanID: span.id,
traceID: span.traceId, traceID: span.traceId,
...@@ -77,22 +77,36 @@ function transformAnnotation(annotation: ZipkinAnnotation): Log { ...@@ -77,22 +77,36 @@ function transformAnnotation(annotation: ZipkinAnnotation): Log {
} }
function gatherProcesses(zSpans: ZipkinSpan[]): Record<string, Process> { function gatherProcesses(zSpans: ZipkinSpan[]): Record<string, Process> {
const processes = zSpans.map(span => ({ const processes = zSpans.reduce((acc, span) => {
serviceName: span.localEndpoint.serviceName, if (span.localEndpoint) {
acc.push(endpointToProcess(span.localEndpoint));
}
if (span.remoteEndpoint) {
acc.push(endpointToProcess(span.remoteEndpoint));
}
return acc;
}, [] as Process[]);
return keyBy(processes, 'serviceName');
}
function endpointToProcess(endpoint: ZipkinEndpoint): Process {
return {
serviceName: endpoint.serviceName,
tags: [ tags: [
{ valueToTag('ipv4', endpoint.ipv4, 'string'),
key: 'ipv4', valueToTag('ipv6', endpoint.ipv6, 'string'),
type: 'string', valueToTag('port', endpoint.port, 'number'),
value: span.localEndpoint.ipv4,
},
span.localEndpoint.port
? {
key: 'port',
type: 'number',
value: span.localEndpoint.port,
}
: undefined,
].filter(identity) as KeyValuePair[], ].filter(identity) as KeyValuePair[],
})); };
return keyBy(processes, 'serviceName'); }
function valueToTag(key: string, value: string | number | undefined, type: string): KeyValuePair | undefined {
if (!value) {
return undefined;
}
return {
key,
type,
value,
};
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment