useQueuesByDestinationQuery.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 {DEFAULT_QUERY_FILTER} from 'sentry/views/performance/queues/settings';
  6. import {useSpanMetrics} from 'sentry/views/starfish/queries/useDiscover';
  7. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  8. type Props = {
  9. destination?: string;
  10. enabled?: boolean;
  11. sort?: Sort;
  12. };
  13. export function useQueuesByDestinationQuery({enabled, destination, sort}: Props) {
  14. const location = useLocation();
  15. const cursor = decodeScalar(location.query?.[QueryParameterNames.DESTINATIONS_CURSOR]);
  16. const mutableSearch = new MutableSearch(DEFAULT_QUERY_FILTER);
  17. if (destination) {
  18. mutableSearch.addFilterValue('messaging.destination.name', destination, false);
  19. }
  20. const response = useSpanMetrics(
  21. {
  22. search: mutableSearch,
  23. fields: [
  24. 'messaging.destination.name',
  25. 'count()',
  26. 'count_op(queue.publish)',
  27. 'count_op(queue.process)',
  28. 'sum(span.duration)',
  29. 'avg(span.duration)',
  30. 'avg_if(span.duration,span.op,queue.publish)',
  31. 'avg_if(span.duration,span.op,queue.process)',
  32. 'avg(messaging.message.receive.latency)',
  33. 'time_spent_percentage()',
  34. ],
  35. enabled,
  36. sorts: sort ? [sort] : [],
  37. limit: 10,
  38. cursor,
  39. },
  40. 'api.performance.queues.destination-summary'
  41. );
  42. return response;
  43. }