throughputChart.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import {CHART_PALETTE} from 'sentry/constants/chartPalette';
  2. import {t} from 'sentry/locale';
  3. import {RateUnit} from 'sentry/utils/discover/fields';
  4. import {formatRate} from 'sentry/utils/formatters';
  5. import Chart, {ChartType} from 'sentry/views/insights/common/components/chart';
  6. import ChartPanel from 'sentry/views/insights/common/components/chartPanel';
  7. import {ALERTS} from 'sentry/views/insights/queues/alerts';
  8. import {useProcessQueuesTimeSeriesQuery} from 'sentry/views/insights/queues/queries/useProcessQueuesTimeSeriesQuery';
  9. import {usePublishQueuesTimeSeriesQuery} from 'sentry/views/insights/queues/queries/usePublishQueuesTimeSeriesQuery';
  10. import type {Referrer} from 'sentry/views/insights/queues/referrers';
  11. import {CHART_HEIGHT} from 'sentry/views/insights/queues/settings';
  12. interface Props {
  13. referrer: Referrer;
  14. destination?: string;
  15. error?: Error | null;
  16. }
  17. export function ThroughputChart({error, destination, referrer}: Props) {
  18. const {data: publishData, isPending: isPublishDataLoading} =
  19. usePublishQueuesTimeSeriesQuery({
  20. destination,
  21. referrer,
  22. });
  23. const {data: processData, isPending: isProcessDataLoading} =
  24. useProcessQueuesTimeSeriesQuery({
  25. destination,
  26. referrer,
  27. });
  28. let {processed, published} = ALERTS;
  29. if (destination) {
  30. processed = {
  31. ...processed,
  32. query: `${processed.query} messaging.destination.name:${destination}`,
  33. };
  34. published = {
  35. ...published,
  36. query: `${published.query} messaging.destination.name:${destination}`,
  37. };
  38. }
  39. return (
  40. <ChartPanel title={t('Published vs Processed')} alertConfigs={[processed, published]}>
  41. <Chart
  42. height={CHART_HEIGHT}
  43. grid={{
  44. left: '0',
  45. right: '0',
  46. top: '8px',
  47. bottom: '0',
  48. }}
  49. data={[
  50. {
  51. seriesName: t('Published'),
  52. data: publishData['spm()'].data,
  53. },
  54. {
  55. seriesName: t('Processed'),
  56. data: processData['spm()'].data,
  57. },
  58. ]}
  59. loading={isPublishDataLoading || isProcessDataLoading}
  60. error={error}
  61. chartColors={CHART_PALETTE[2].slice(1, 3)}
  62. type={ChartType.LINE}
  63. aggregateOutputFormat="rate"
  64. rateUnit={RateUnit.PER_MINUTE}
  65. tooltipFormatterOptions={{
  66. valueFormatter: value => formatRate(value, RateUnit.PER_MINUTE),
  67. }}
  68. showLegend
  69. />
  70. </ChartPanel>
  71. );
  72. }