latencyChart.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {DEFAULT_RELATIVE_PERIODS} from 'sentry/constants';
  2. import {CHART_PALETTE} from 'sentry/constants/chartPalette';
  3. import {t} from 'sentry/locale';
  4. import {decodeScalar} from 'sentry/utils/queryString';
  5. import {useLocation} from 'sentry/utils/useLocation';
  6. import usePageFilters from 'sentry/utils/usePageFilters';
  7. import {CHART_HEIGHT} from 'sentry/views/performance/database/settings';
  8. import {useQueuesTimeSeriesQuery} from 'sentry/views/performance/queues/queries/useQueuesTimeSeriesQuery';
  9. import Chart, {ChartType} from 'sentry/views/starfish/components/chart';
  10. import ChartPanel from 'sentry/views/starfish/components/chartPanel';
  11. interface Props {
  12. error?: Error | null;
  13. }
  14. export function LatencyChart({error}: Props) {
  15. const {query} = useLocation();
  16. const destination = decodeScalar(query.destination);
  17. const pageFilters = usePageFilters();
  18. const period = pageFilters.selection.datetime.period;
  19. const chartSubtext = (period && DEFAULT_RELATIVE_PERIODS[period]) ?? '';
  20. const {data, isLoading} = useQueuesTimeSeriesQuery({destination});
  21. return (
  22. <ChartPanel title={t('Avg Latency')} subtitle={chartSubtext}>
  23. <Chart
  24. height={CHART_HEIGHT}
  25. grid={{
  26. left: '0',
  27. right: '0',
  28. top: '12px',
  29. bottom: '0',
  30. }}
  31. data={
  32. [
  33. {
  34. seriesName: t('Average Processing Latency'),
  35. data: data['avg_if(span.self_time,span.op,queue.task.celery)'].data,
  36. },
  37. ] ?? []
  38. }
  39. loading={isLoading}
  40. error={error}
  41. chartColors={CHART_PALETTE[2].slice(1)}
  42. type={ChartType.AREA}
  43. />
  44. </ChartPanel>
  45. );
  46. }