Files
grafana/public/app/plugins/datasource/zipkin/utils/graphTransform.test.ts
Andrej Ocenas 615de9bf34 Zipkin: Add node graph view to trace response (#34414)
* Add graph transform

* Add tests

* Refactor code

* Update test

* Fix zipkin block

Co-authored-by: David Kaltschmidt <david.kaltschmidt@gmail.com>
2021-05-20 10:01:28 +02:00

77 lines
2.0 KiB
TypeScript

import { createGraphFrames } from './graphTransform';
import {
testResponse,
testResponseEdgesFields,
testResponseNodesFields,
toEdgesFrame,
toNodesFrame,
} from './testResponse';
import { ZipkinSpan } from '../types';
describe('createGraphFrames', () => {
it('transforms basic response into nodes and edges frame', async () => {
const frames = createGraphFrames(testResponse);
expect(frames.length).toBe(2);
expect(frames[0].fields).toMatchObject(testResponseNodesFields);
expect(frames[1].fields).toMatchObject(testResponseEdgesFields);
});
it('handles single span response', async () => {
const frames = createGraphFrames(singleSpanResponse);
expect(frames.length).toBe(2);
expect(frames[0].fields).toMatchObject(
toNodesFrame([
['3fa414edcef6ad90'],
['tempo-querier'],
['HTTP GET - api_traces_traceid'],
['1049.14ms (100%)'],
['1049.14ms (100%)'],
[1],
])
);
expect(frames[1].fields).toMatchObject(toEdgesFrame([[], [], []]));
});
it('handles missing spans', async () => {
const frames = createGraphFrames(missingSpanResponse);
expect(frames.length).toBe(2);
expect(frames[0].length).toBe(2);
expect(frames[1].length).toBe(0);
});
});
export const singleSpanResponse: ZipkinSpan[] = [
{
traceId: '3fa414edcef6ad90',
id: '3fa414edcef6ad90',
name: 'HTTP GET - api_traces_traceid',
timestamp: 1605873894680409,
duration: 1049141,
tags: {
component: 'gRPC',
spanKind: 'client',
},
localEndpoint: {
serviceName: 'tempo-querier',
},
},
];
export const missingSpanResponse: ZipkinSpan[] = [
{
traceId: '3fa414edcef6ad90',
id: '1',
name: 'HTTP GET - api_traces_traceid',
timestamp: 1605873894680409,
duration: 1049141,
},
{
traceId: '3fa414edcef6ad90',
id: '2',
name: 'HTTP GET - api_traces_traceid',
parentId: '3',
timestamp: 1605873894680409,
duration: 1049141,
},
];