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

Usage of a helper for trace name when preparing trace data #544

Merged
merged 3 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
110 changes: 109 additions & 1 deletion packages/jaeger-ui/src/model/transform-trace-data.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { orderTags, deduplicateTags } from './transform-trace-data';
import transformTraceData, { orderTags, deduplicateTags } from './transform-trace-data';

describe('orderTags()', () => {
it('correctly orders tags', () => {
Expand Down Expand Up @@ -53,3 +53,111 @@ describe('deduplicateTags()', () => {
expect(tagsInfo.warnings).toEqual(['Duplicate tag "b.ip:8.8.4.4"']);
});
});

describe('transformTraceData()', () => {
const startTime = 1586160015434000;
const duration = 34000;
const traceID = 'f77950feed55c1ce91dd8e87896623a6';
const rootSpanID = 'd4dcb46e95b781f5';
const rootOperationName = 'rootOperation';
const serviceName = 'serviceName';

const spans = [
{
traceID,
spanID: '41f71485ed2593e4',
operationName: 'someOperationName',
references: [
{
refType: 'CHILD_OF',
traceID,
spanID: rootSpanID,
},
],
startTime,
duration,
tags: [],
processID: 'p1',
},
{
traceID,
spanID: '4f623fd33c213cba',
operationName: 'anotherOperationName',
references: [
{
refType: 'CHILD_OF',
traceID,
spanID: rootSpanID,
},
],
startTime: startTime + 100,
duration,
tags: [],
processID: 'p1',
},
];

const rootSpanWithMissingRef = {
traceID,
spanID: rootSpanID,
operationName: rootOperationName,
references: [
{
refType: 'CHILD_OF',
traceID,
spanID: 'missingSpanId',
},
],
startTime: startTime + 50,
duration,
tags: [],
processID: 'p1',
};

const rootSpanWithoutRefs = {
traceID,
spanID: rootSpanID,
operationName: rootOperationName,
startTime: startTime + 50,
duration,
tags: [],
processID: 'p1',
};

const processes = {
p1: {
serviceName,
tags: [],
},
};

it('should return null for trace without traceID', () => {
const traceData = {
traceID: undefined,
processes,
spans,
};

expect(transformTraceData(traceData)).toEqual(null);
});

it('should return trace data with correct traceName based on root span with missing ref', () => {
const traceData = {
traceID,
processes,
spans: [...spans, rootSpanWithMissingRef],
};

expect(transformTraceData(traceData).traceName).toEqual(`${serviceName}: ${rootOperationName}`);
});

it('should return trace data with correct traceName based on root span without any refs', () => {
const traceData = {
traceID,
processes,
spans: [...spans, rootSpanWithoutRefs],
};

expect(transformTraceData(traceData).traceName).toEqual(`${serviceName}: ${rootOperationName}`);
});
});
6 changes: 2 additions & 4 deletions packages/jaeger-ui/src/model/transform-trace-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import _isEqual from 'lodash/isEqual';

import { getTraceSpanIdsAsTree } from '../selectors/trace';
import { getConfigValue } from '../utils/config/get-config';
import { getTraceName } from './trace-viewer';
import { KeyValuePair, Span, SpanData, Trace, TraceData } from '../types/trace';
import TreeNode from '../utils/TreeNode';

Expand Down Expand Up @@ -120,7 +121,6 @@ export default function transformTraceData(data: TraceData & { spans: SpanData[]
const tree = getTraceSpanIdsAsTree(data);
const spans: Span[] = [];
const svcCounts: Record<string, number> = {};
let traceName = '';

tree.walk((spanID: string, node: TreeNode, depth: number = 0) => {
if (spanID === '__root__') {
Expand All @@ -132,9 +132,6 @@ export default function transformTraceData(data: TraceData & { spans: SpanData[]
}
const { serviceName } = span.process;
svcCounts[serviceName] = (svcCounts[serviceName] || 0) + 1;
if (!span.references || !span.references.length) {
traceName = `${serviceName}: ${span.operationName}`;
}
span.relativeStartTime = span.startTime - traceStartTime;
span.depth = depth - 1;
span.hasChildren = node.children.length > 0;
Expand Down Expand Up @@ -163,6 +160,7 @@ export default function transformTraceData(data: TraceData & { spans: SpanData[]
});
spans.push(span);
});
const traceName = getTraceName(spans);
const services = Object.keys(svcCounts).map(name => ({ name, numberOfSpans: svcCounts[name] }));
return {
services,
Expand Down