useQueuesByDestinationQuery.tsx 1.6 KB

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