Skip to content

Commit

Permalink
Use getTraceName() when preparing trace data (jaegertracing#544)
Browse files Browse the repository at this point in the history
* Usage of getTraceName() when preparing trace data

Usage of a helper for trace name resolution when preparing traces data.
It affects Search and Compare pages.

Signed-off-by: Valerii Varankin <swapster@yandex-team.ru>

* Tests for transform-trace-data helper

* Test for trace without an ID
* Test for trace with remote (missing) root span
* Test for trace with root span without refs

Signed-off-by: Valerii Varankin <swapster@yandex-team.ru>

* Removed unnecessary data from tests

Tags has been removed since it are not relevant to the functionality being tested

Signed-off-by: Valerii Varankin <swapster@yandex-team.ru>
Signed-off-by: vvvprabhakar <vvvprabhakar@gmail.com>
  • Loading branch information
swapster authored Apr 8, 2020
1 parent ca552d3 commit b9a26c6
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 5 deletions.
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

0 comments on commit b9a26c6

Please sign in to comment.