graphTransform.test.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { ZipkinSpan } from '../types';
  2. import { createGraphFrames } from './graphTransform';
  3. import {
  4. testResponse,
  5. testResponseEdgesFields,
  6. testResponseNodesFields,
  7. toEdgesFrame,
  8. toNodesFrame,
  9. } from './testResponse';
  10. describe('createGraphFrames', () => {
  11. it('transforms basic response into nodes and edges frame', async () => {
  12. const frames = createGraphFrames(testResponse);
  13. expect(frames.length).toBe(2);
  14. expect(frames[0].fields).toMatchObject(testResponseNodesFields);
  15. expect(frames[1].fields).toMatchObject(testResponseEdgesFields);
  16. });
  17. it('handles single span response', async () => {
  18. const frames = createGraphFrames(singleSpanResponse);
  19. expect(frames.length).toBe(2);
  20. expect(frames[0].fields).toMatchObject(
  21. toNodesFrame([
  22. ['3fa414edcef6ad90'],
  23. ['tempo-querier'],
  24. ['HTTP GET - api_traces_traceid'],
  25. ['1049.14ms (100%)'],
  26. ['1049.14ms (100%)'],
  27. [1],
  28. ])
  29. );
  30. expect(frames[1].fields).toMatchObject(toEdgesFrame([[], [], []]));
  31. });
  32. it('handles missing spans', async () => {
  33. const frames = createGraphFrames(missingSpanResponse);
  34. expect(frames.length).toBe(2);
  35. expect(frames[0].length).toBe(2);
  36. expect(frames[1].length).toBe(0);
  37. });
  38. });
  39. export const singleSpanResponse: ZipkinSpan[] = [
  40. {
  41. traceId: '3fa414edcef6ad90',
  42. id: '3fa414edcef6ad90',
  43. name: 'HTTP GET - api_traces_traceid',
  44. timestamp: 1605873894680409,
  45. duration: 1049141,
  46. tags: {
  47. component: 'gRPC',
  48. spanKind: 'client',
  49. },
  50. localEndpoint: {
  51. serviceName: 'tempo-querier',
  52. },
  53. },
  54. ];
  55. export const missingSpanResponse: ZipkinSpan[] = [
  56. {
  57. traceId: '3fa414edcef6ad90',
  58. id: '1',
  59. name: 'HTTP GET - api_traces_traceid',
  60. timestamp: 1605873894680409,
  61. duration: 1049141,
  62. },
  63. {
  64. traceId: '3fa414edcef6ad90',
  65. id: '2',
  66. name: 'HTTP GET - api_traces_traceid',
  67. parentId: '3',
  68. timestamp: 1605873894680409,
  69. duration: 1049141,
  70. },
  71. ];