messageConsumerSamplesPanel.spec.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen, waitForElementToBeRemoved} from 'sentry-test/reactTestingLibrary';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import useOrganization from 'sentry/utils/useOrganization';
  5. import usePageFilters from 'sentry/utils/usePageFilters';
  6. import {MessageConsumerSamplesPanel} from 'sentry/views/performance/queues/messageConsumerSamplesPanel';
  7. jest.mock('sentry/utils/useLocation');
  8. jest.mock('sentry/utils/usePageFilters');
  9. jest.mock('sentry/utils/useOrganization');
  10. describe('messageConsumerSamplesPanel', () => {
  11. const organization = OrganizationFixture();
  12. let eventsRequestMock, eventsStatsRequestMock, samplesRequestMock;
  13. jest.mocked(usePageFilters).mockReturnValue({
  14. isReady: true,
  15. desyncedFilters: new Set(),
  16. pinnedFilters: new Set(),
  17. shouldPersist: true,
  18. selection: {
  19. datetime: {
  20. period: '10d',
  21. start: null,
  22. end: null,
  23. utc: false,
  24. },
  25. environments: [],
  26. projects: [],
  27. },
  28. });
  29. jest.mocked(useLocation).mockReturnValue({
  30. pathname: '',
  31. search: '',
  32. query: {transaction: 'sentry.tasks.store.save_event', destination: 'event-queue'},
  33. hash: '',
  34. state: undefined,
  35. action: 'PUSH',
  36. key: '',
  37. });
  38. jest.mocked(useOrganization).mockReturnValue(organization);
  39. beforeEach(() => {
  40. eventsStatsRequestMock = MockApiClient.addMockResponse({
  41. url: `/organizations/${organization.slug}/events-stats/`,
  42. method: 'GET',
  43. body: {
  44. data: [[1699907700, [{count: 7810}]]],
  45. meta: {},
  46. },
  47. });
  48. eventsRequestMock = MockApiClient.addMockResponse({
  49. url: `/organizations/${organization.slug}/events/`,
  50. method: 'GET',
  51. body: {
  52. data: [],
  53. meta: {},
  54. },
  55. });
  56. samplesRequestMock = MockApiClient.addMockResponse({
  57. url: `/api/0/organizations/${organization.slug}/spans-samples/`,
  58. method: 'GET',
  59. body: {
  60. data: [
  61. {
  62. span_id: '123',
  63. trace: 'abc',
  64. project: 'project',
  65. timestamp: '2024-03-25T20:31:36+00:00',
  66. 'span.duration': 320.300102,
  67. },
  68. ],
  69. },
  70. });
  71. });
  72. afterAll(() => {
  73. jest.resetAllMocks();
  74. });
  75. it('renders', async () => {
  76. render(<MessageConsumerSamplesPanel />);
  77. await waitForElementToBeRemoved(() => screen.queryAllByTestId('loading-indicator'));
  78. expect(eventsStatsRequestMock).toHaveBeenCalled();
  79. expect(eventsRequestMock).toHaveBeenCalledWith(
  80. `/organizations/${organization.slug}/events/`,
  81. expect.objectContaining({
  82. method: 'GET',
  83. query: expect.objectContaining({
  84. dataset: 'spansMetrics',
  85. environment: [],
  86. field: [
  87. 'count()',
  88. 'count_op(queue.publish)',
  89. 'count_op(queue.process)',
  90. 'sum(span.duration)',
  91. 'avg(span.duration)',
  92. 'avg_if(span.duration,span.op,queue.publish)',
  93. 'avg_if(span.duration,span.op,queue.process)',
  94. 'avg(messaging.message.receive.latency)',
  95. ],
  96. per_page: 10,
  97. project: [],
  98. query:
  99. 'span.op:[queue.process,queue.publish] messaging.destination.name:event-queue transaction:sentry.tasks.store.save_event',
  100. statsPeriod: '10d',
  101. }),
  102. })
  103. );
  104. expect(samplesRequestMock).toHaveBeenCalledWith(
  105. `/api/0/organizations/${organization.slug}/spans-samples/`,
  106. expect.objectContaining({
  107. query: expect.objectContaining({
  108. additionalFields: [
  109. 'trace',
  110. 'transaction.id',
  111. 'span.description',
  112. 'measurements.messaging.message.body.size',
  113. 'measurements.messaging.message.receive.latency',
  114. 'messaging.message.id',
  115. 'trace.status',
  116. 'span.duration',
  117. ],
  118. firstBound: 2666.6666666666665,
  119. lowerBound: 0,
  120. project: [],
  121. query:
  122. 'span.op:queue.process OR span.op:queue.publish transaction:sentry.tasks.store.save_event messaging.destination.name:event-queue',
  123. referrer: undefined,
  124. secondBound: 5333.333333333333,
  125. statsPeriod: '10d',
  126. upperBound: 8000,
  127. }),
  128. })
  129. );
  130. expect(screen.getByRole('table', {name: 'Span Samples'})).toBeInTheDocument();
  131. });
  132. });