virtualMetricsContext.spec.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import type {MetricsExtractionRule} from 'sentry/types/metrics';
  2. import {createMRIToVirtualMap} from 'sentry/utils/metrics/virtualMetricsContext';
  3. describe('createMRIToVirtualMap', () => {
  4. it('creates a mapping', () => {
  5. const rules = [
  6. {
  7. spanAttribute: 'span1',
  8. projectId: 1,
  9. createdById: null,
  10. dateAdded: '2021-09-29T20:00:00',
  11. dateUpdated: '2021-09-29T20:00:00',
  12. aggregates: [],
  13. tags: [],
  14. unit: 'none',
  15. conditions: [
  16. {
  17. id: 1,
  18. value: 'value',
  19. mris: ['c:custom/mri1@none' as const, 'c:custom/mri2@none' as const],
  20. },
  21. ],
  22. } satisfies MetricsExtractionRule,
  23. {
  24. spanAttribute: 'span2',
  25. projectId: 2,
  26. createdById: null,
  27. dateAdded: '2021-09-29T20:00:00',
  28. dateUpdated: '2021-09-29T20:00:00',
  29. aggregates: [],
  30. tags: [],
  31. unit: 'millisecond',
  32. conditions: [
  33. {
  34. id: 2,
  35. value: 'value',
  36. mris: ['c:custom/mri3@none' as const, 'c:custom/mri4@none' as const],
  37. },
  38. ],
  39. } satisfies MetricsExtractionRule,
  40. ];
  41. const result = createMRIToVirtualMap(rules);
  42. expect(result).toEqual(
  43. new Map([
  44. ['c:custom/mri1@none', 'v:custom/span1|1@none'],
  45. ['c:custom/mri2@none', 'v:custom/span1|1@none'],
  46. ['c:custom/mri3@none', 'v:custom/span2|2@millisecond'],
  47. ['c:custom/mri4@none', 'v:custom/span2|2@millisecond'],
  48. ])
  49. );
  50. });
  51. });