useQueuesByDestinationQuery.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import type {Sort} from 'sentry/utils/discover/fields';
  2. import {decodeScalar} from 'sentry/utils/queryString';
  3. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  4. import {useLocation} from 'sentry/utils/useLocation';
  5. import {useSpanMetrics} from 'sentry/views/insights/common/queries/useDiscover';
  6. import {QueryParameterNames} from 'sentry/views/insights/common/views/queryParameters';
  7. import type {Referrer} from 'sentry/views/insights/queues/referrers';
  8. import {
  9. DEFAULT_QUERY_FILTER,
  10. TABLE_ROWS_LIMIT,
  11. } from 'sentry/views/insights/queues/settings';
  12. type Props = {
  13. referrer: Referrer;
  14. destination?: string;
  15. enabled?: boolean;
  16. sort?: Sort;
  17. };
  18. export function useQueuesByDestinationQuery({
  19. enabled,
  20. destination,
  21. sort,
  22. referrer,
  23. }: Props) {
  24. const location = useLocation();
  25. const cursor = decodeScalar(location.query?.[QueryParameterNames.DESTINATIONS_CURSOR]);
  26. const mutableSearch = new MutableSearch(DEFAULT_QUERY_FILTER);
  27. if (destination) {
  28. mutableSearch.addFilterValue('messaging.destination.name', destination, false);
  29. }
  30. const response = useSpanMetrics(
  31. {
  32. search: mutableSearch,
  33. fields: [
  34. 'messaging.destination.name',
  35. 'count()',
  36. 'count_op(queue.publish)',
  37. 'count_op(queue.process)',
  38. 'sum(span.duration)',
  39. 'avg(span.duration)',
  40. 'avg_if(span.duration,span.op,queue.publish)',
  41. 'avg_if(span.duration,span.op,queue.process)',
  42. 'avg(messaging.message.receive.latency)',
  43. 'trace_status_rate(ok)',
  44. 'time_spent_percentage(app,span.duration)',
  45. ],
  46. enabled,
  47. sorts: sort ? [sort] : [],
  48. limit: TABLE_ROWS_LIMIT,
  49. cursor,
  50. },
  51. referrer
  52. );
  53. return response;
  54. }