latencyChart.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {CHART_PALETTE} from 'sentry/constants/chartPalette';
  2. import {t} from 'sentry/locale';
  3. import Chart, {ChartType} from 'sentry/views/insights/common/components/chart';
  4. import ChartPanel from 'sentry/views/insights/common/components/chartPanel';
  5. import {ALERTS} from 'sentry/views/insights/queues/alerts';
  6. import {useProcessQueuesTimeSeriesQuery} from 'sentry/views/insights/queues/queries/useProcessQueuesTimeSeriesQuery';
  7. import type {Referrer} from 'sentry/views/insights/queues/referrers';
  8. import {CHART_HEIGHT} from 'sentry/views/insights/queues/settings';
  9. interface Props {
  10. referrer: Referrer;
  11. destination?: string;
  12. error?: Error | null;
  13. }
  14. export function LatencyChart({error, destination, referrer}: Props) {
  15. const {data, isPending} = useProcessQueuesTimeSeriesQuery({
  16. destination,
  17. referrer,
  18. });
  19. let {latency, duration} = ALERTS;
  20. if (destination) {
  21. latency = {
  22. ...latency,
  23. query: `${latency.query} messaging.destination.name:${destination}`,
  24. };
  25. duration = {
  26. ...duration,
  27. query: `${duration.query} messaging.destination.name:${destination}`,
  28. };
  29. }
  30. return (
  31. <ChartPanel title={t('Avg Latency')} alertConfigs={[latency, duration]}>
  32. <Chart
  33. height={CHART_HEIGHT}
  34. grid={{
  35. left: '0',
  36. right: '0',
  37. top: '8px',
  38. bottom: '0',
  39. }}
  40. data={[
  41. {
  42. seriesName: t('Average Time in Queue'),
  43. data: data['avg(messaging.message.receive.latency)'].data,
  44. },
  45. {
  46. seriesName: t('Average Processing Time'),
  47. data: data['avg(span.duration)'].data,
  48. },
  49. ]}
  50. loading={isPending}
  51. error={error}
  52. chartColors={CHART_PALETTE[2].slice(1)}
  53. type={ChartType.AREA}
  54. showLegend
  55. stacked
  56. aggregateOutputFormat="duration"
  57. />
  58. </ChartPanel>
  59. );
  60. }