queuesTable.spec.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import {QueuesTable} from 'sentry/views/insights/queues/components/tables/queuesTable';
  4. import {SpanIndexedField} from 'sentry/views/insights/types';
  5. describe('queuesTable', () => {
  6. const organization = OrganizationFixture();
  7. let eventsMock: jest.Mock;
  8. const pageLinks =
  9. '<https://sentry.io/fake/previous>; rel="previous"; results="false"; cursor="0:0:1", ' +
  10. '<https://sentry.io/fake/next>; rel="next"; results="true"; cursor="0:20:0"';
  11. beforeEach(() => {
  12. eventsMock = MockApiClient.addMockResponse({
  13. url: `/organizations/${organization.slug}/events/`,
  14. headers: {Link: pageLinks},
  15. method: 'GET',
  16. body: {
  17. data: [
  18. {
  19. 'messaging.destination.name': 'celery.backend_cleanup',
  20. 'count()': 2,
  21. 'count_op(queue.publish)': 0,
  22. 'count_op(queue.process)': 2,
  23. 'sum(span.duration)': 6,
  24. 'avg(span.duration)': 3,
  25. 'avg_if(span.duration,span.op,queue.publish)': 0,
  26. 'avg_if(span.duration,span.op,queue.process)': 3,
  27. 'avg(messaging.message.receive.latency)': 20,
  28. 'trace_status_rate(ok)': 0.8,
  29. 'time_spent_percentage(app,span.duration)': 0.5,
  30. },
  31. ],
  32. meta: {
  33. fields: {
  34. 'count()': 'integer',
  35. 'count_op(queue.publish)': 'integer',
  36. 'count_op(queue.process)': 'integer',
  37. 'sum(span.duration)': 'duration',
  38. 'avg(span.duration)': 'duration',
  39. 'avg_if(span.duration,span.op,queue.publish)': 'duration',
  40. 'avg_if(span.duration,span.op,queue.process)': 'duration',
  41. 'avg(messaging.message.receive.latency)': 'duration',
  42. 'trace_status_rate(ok)': 'percentage',
  43. 'time_spent_percentage(app,span.duration)': 'percentage',
  44. },
  45. },
  46. },
  47. });
  48. });
  49. it('renders', async () => {
  50. render(
  51. <QueuesTable
  52. sort={{field: 'time_spent_percentage(app,span.duration)', kind: 'desc'}}
  53. />,
  54. {organization}
  55. );
  56. expect(screen.getByRole('table', {name: 'Queues'})).toBeInTheDocument();
  57. expect(screen.getByRole('columnheader', {name: 'Destination'})).toBeInTheDocument();
  58. expect(
  59. screen.getByRole('columnheader', {name: 'Avg Time in Queue'})
  60. ).toBeInTheDocument();
  61. expect(
  62. screen.getByRole('columnheader', {name: 'Avg Processing Time'})
  63. ).toBeInTheDocument();
  64. expect(screen.getByRole('columnheader', {name: 'Error Rate'})).toBeInTheDocument();
  65. expect(screen.getByRole('columnheader', {name: 'Published'})).toBeInTheDocument();
  66. expect(screen.getByRole('columnheader', {name: 'Processed'})).toBeInTheDocument();
  67. expect(screen.getByRole('columnheader', {name: 'Time Spent'})).toBeInTheDocument();
  68. expect(eventsMock).toHaveBeenCalledWith(
  69. '/organizations/org-slug/events/',
  70. expect.objectContaining({
  71. query: expect.objectContaining({
  72. field: [
  73. 'messaging.destination.name',
  74. 'count()',
  75. 'count_op(queue.publish)',
  76. 'count_op(queue.process)',
  77. 'sum(span.duration)',
  78. 'avg(span.duration)',
  79. 'avg_if(span.duration,span.op,queue.publish)',
  80. 'avg_if(span.duration,span.op,queue.process)',
  81. 'avg(messaging.message.receive.latency)',
  82. 'trace_status_rate(ok)',
  83. 'time_spent_percentage(app,span.duration)',
  84. ],
  85. dataset: 'spansMetrics',
  86. }),
  87. })
  88. );
  89. await screen.findByText('celery.backend_cleanup');
  90. expect(screen.getByRole('cell', {name: '3.00ms'})).toBeInTheDocument();
  91. expect(screen.getByRole('cell', {name: '2'})).toBeInTheDocument();
  92. expect(screen.getByRole('cell', {name: '6.00ms'})).toBeInTheDocument();
  93. expect(screen.getByRole('cell', {name: '20.00ms'})).toBeInTheDocument();
  94. expect(screen.getByRole('cell', {name: '20%'})).toBeInTheDocument();
  95. expect(screen.getByRole('button', {name: 'Next'})).toBeInTheDocument();
  96. });
  97. it('searches for a destination and sorts', async () => {
  98. render(
  99. <QueuesTable
  100. destination="*events*"
  101. sort={{field: SpanIndexedField.MESSAGING_MESSAGE_DESTINATION_NAME, kind: 'desc'}}
  102. />,
  103. {organization}
  104. );
  105. expect(eventsMock).toHaveBeenCalledWith(
  106. '/organizations/org-slug/events/',
  107. expect.objectContaining({
  108. query: expect.objectContaining({
  109. field: [
  110. 'messaging.destination.name',
  111. 'count()',
  112. 'count_op(queue.publish)',
  113. 'count_op(queue.process)',
  114. 'sum(span.duration)',
  115. 'avg(span.duration)',
  116. 'avg_if(span.duration,span.op,queue.publish)',
  117. 'avg_if(span.duration,span.op,queue.process)',
  118. 'avg(messaging.message.receive.latency)',
  119. 'trace_status_rate(ok)',
  120. 'time_spent_percentage(app,span.duration)',
  121. ],
  122. dataset: 'spansMetrics',
  123. sort: '-messaging.destination.name',
  124. query:
  125. 'span.op:[queue.process,queue.publish] messaging.destination.name:*events*',
  126. }),
  127. })
  128. );
  129. await screen.findByText('celery.backend_cleanup');
  130. });
  131. });