testResponse.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { ArrayVector, FieldDTO } from '@grafana/data';
  2. import { TraceResponse } from './types';
  3. export const testResponse: TraceResponse = {
  4. traceID: '3fa414edcef6ad90',
  5. spans: [
  6. {
  7. traceID: '3fa414edcef6ad90',
  8. spanID: '3fa414edcef6ad90',
  9. operationName: 'HTTP GET - api_traces_traceid',
  10. references: [],
  11. startTime: 1605873894680409,
  12. duration: 1049141,
  13. tags: [
  14. { key: 'sampler.type', type: 'string', value: 'probabilistic' },
  15. { key: 'sampler.param', type: 'float64', value: 1 },
  16. ],
  17. logs: [],
  18. processID: 'p1',
  19. warnings: null,
  20. flags: 0,
  21. },
  22. {
  23. traceID: '3fa414edcef6ad90',
  24. spanID: '0f5c1808567e4403',
  25. operationName: '/tempopb.Querier/FindTraceByID',
  26. references: [{ refType: 'CHILD_OF', traceID: '3fa414edcef6ad90', spanID: '3fa414edcef6ad90' }],
  27. startTime: 1605873894680587,
  28. duration: 1847,
  29. tags: [
  30. { key: 'component', type: 'string', value: 'gRPC' },
  31. { key: 'span.kind', type: 'string', value: 'client' },
  32. ],
  33. logs: [],
  34. processID: 'p1',
  35. warnings: null,
  36. flags: 0,
  37. },
  38. ],
  39. processes: {
  40. p1: {
  41. serviceName: 'tempo-querier',
  42. tags: [
  43. { key: 'cluster', type: 'string', value: 'ops-tools1' },
  44. { key: 'container', type: 'string', value: 'tempo-query' },
  45. ],
  46. },
  47. },
  48. warnings: null,
  49. };
  50. function toVectors(fields: FieldDTO[]) {
  51. return fields.map((f) => ({ ...f, values: new ArrayVector<any>(f.values as any[]) }));
  52. }
  53. export const testResponseDataFrameFields = toVectors([
  54. { name: 'traceID', values: ['3fa414edcef6ad90', '3fa414edcef6ad90'] },
  55. { name: 'spanID', values: ['3fa414edcef6ad90', '0f5c1808567e4403'] },
  56. { name: 'parentSpanID', values: [undefined, '3fa414edcef6ad90'] },
  57. { name: 'operationName', values: ['HTTP GET - api_traces_traceid', '/tempopb.Querier/FindTraceByID'] },
  58. { name: 'serviceName', values: ['tempo-querier', 'tempo-querier'] },
  59. {
  60. name: 'serviceTags',
  61. values: [
  62. [
  63. { key: 'cluster', type: 'string', value: 'ops-tools1' },
  64. { key: 'container', type: 'string', value: 'tempo-query' },
  65. ],
  66. [
  67. { key: 'cluster', type: 'string', value: 'ops-tools1' },
  68. { key: 'container', type: 'string', value: 'tempo-query' },
  69. ],
  70. ],
  71. },
  72. { name: 'startTime', values: [1605873894680.409, 1605873894680.587] },
  73. { name: 'duration', values: [1049.141, 1.847] },
  74. { name: 'logs', values: [[], []] },
  75. {
  76. name: 'tags',
  77. values: [
  78. [
  79. { key: 'sampler.type', type: 'string', value: 'probabilistic' },
  80. { key: 'sampler.param', type: 'float64', value: 1 },
  81. ],
  82. [
  83. { key: 'component', type: 'string', value: 'gRPC' },
  84. { key: 'span.kind', type: 'string', value: 'client' },
  85. ],
  86. ],
  87. },
  88. { name: 'warnings', values: [undefined, undefined] },
  89. { name: 'stackTraces', values: [undefined, undefined] },
  90. ]);
  91. export const testResponseNodesFields = toNodesFrame([
  92. ['3fa414edcef6ad90', '0f5c1808567e4403'],
  93. ['tempo-querier', 'tempo-querier'],
  94. ['HTTP GET - api_traces_traceid', '/tempopb.Querier/FindTraceByID'],
  95. ['1049.14ms (100%)', '1.85ms (0.18%)'],
  96. ['1047.29ms (99.82%)', '1.85ms (100%)'],
  97. [0.9982395121342127, 0.0017604878657873442],
  98. ]);
  99. export const testResponseEdgesFields = toEdgesFrame([
  100. ['3fa414edcef6ad90--0f5c1808567e4403'],
  101. ['0f5c1808567e4403'],
  102. ['3fa414edcef6ad90'],
  103. ]);
  104. export function toNodesFrame(values: any[]) {
  105. return toVectors([
  106. { name: 'id', values: values[0] },
  107. { name: 'title', values: values[1] },
  108. { name: 'subtitle', values: values[2] },
  109. { name: 'mainstat', values: values[3] },
  110. { name: 'secondarystat', values: values[4] },
  111. {
  112. name: 'color',
  113. config: {
  114. color: {
  115. mode: 'continuous-GrYlRd',
  116. },
  117. },
  118. values: values[5],
  119. },
  120. ]);
  121. }
  122. export function toEdgesFrame(values: any[]) {
  123. return toVectors([
  124. { name: 'id', values: values[0] },
  125. { name: 'target', values: values[1] },
  126. { name: 'source', values: values[2] },
  127. ]);
  128. }