Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search results DDG path ordering #504

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion packages/jaeger-ui/src/model/ddg/transformTracesToPaths.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import transformTracesToPaths from './transformTracesToPaths';

describe('transform traces to ddg paths', () => {
const makeSpan = (spanName, childOf) => ({
const makeSpan = (spanName, childOf, kind) => ({
everett980 marked this conversation as resolved.
Show resolved Hide resolved
hasChildren: true,
operationName: `${spanName} operation`,
processID: `${spanName} processID`,
Expand All @@ -28,6 +28,15 @@ describe('transform traces to ddg paths', () => {
},
]
: [],
tags:
kind === false
? []
: [
{
key: 'span.kind',
value: kind === undefined ? 'server' : kind,
},
],
spanID: `${spanName} spanID`,
});
const makeTrace = (spans, traceID) => ({
Expand Down Expand Up @@ -150,4 +159,27 @@ describe('transform traces to ddg paths', () => {
const { dependencies: result } = transformTracesToPaths(traces, 'child service');
expect(result.length).toBe(1);
});

it("omits span if tags does not have span.kind === 'server'", () => {
const badSpanName = 'test bad span name';
const clientSpan = makeSpan(badSpanName, childSpan, 'client');
clientSpan.hasChildren = false;
const clientTraceID = 'test client trace ID';
const clientTrace = makeTrace([rootSpan, childSpan, clientSpan], clientTraceID);
const kindlessSpan = makeSpan(badSpanName, childSpan, false);
kindlessSpan.hasChildren = false;
const kindlessTraceID = 'test kindless trace ID';
const kindlessTrace = makeTrace([rootSpan, childSpan, kindlessSpan], kindlessTraceID);

const traces = {
[clientTraceID]: clientTrace,
[kindlessTraceID]: kindlessTrace,
};
const { dependencies: result } = transformTracesToPaths(traces, 'child service');
expect(result.length).toBe(2);
expect(result[0].path.length).toBe(clientTrace.data.spans.length - 1);
expect(result[0].path.some(({ operation }) => operation.startsWith(badSpanName))).toBe(false);
expect(result[1].path.length).toBe(kindlessTrace.data.spans.length - 1);
expect(result[1].path.some(({ operation }) => operation.startsWith(badSpanName))).toBe(false);
});
});
13 changes: 9 additions & 4 deletions packages/jaeger-ui/src/model/ddg/transformTracesToPaths.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,25 @@ function transformTracesToPaths(
return !span.hasChildren;
})
.forEach(leaf => {
const path = spanAncestorIds(leaf).map(id => {
const spans = spanAncestorIds(leaf).map(id => {
const span = spanMap.get(id);
if (!span) throw new Error(`Ancestor spanID ${id} not found in trace ${traceID}`);

return convertSpan(span, data);
return span;
});
path.push(convertSpan(leaf, data));
spans.reverse();
spans.push(leaf);

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

if (
path.some(
({ service, operation }) =>
service === focalService && (!focalOperation || operation === focalOperation)
)
) {
// TODO: Paths should be deduped with all traceIDs #503
dependencies.push({
path,
attributes: [
Expand Down
8 changes: 4 additions & 4 deletions packages/jaeger-ui/src/utils/span-ancestor-ids.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ function getFirstAncestor(span: Span): Span | TNil {
}

export default function spanAncestorIds(span: Span | TNil): string[] {
if (!span) return [];
const ancestorIDs: Set<string> = new Set();
const ancestorIDs: string[] = [];
if (!span) return ancestorIDs;
let ref = getFirstAncestor(span);
while (ref) {
ancestorIDs.add(ref.spanID);
ancestorIDs.push(ref.spanID);
ref = getFirstAncestor(ref);
}
return Array.from(ancestorIDs);
return ancestorIDs;
}