throughputChart.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 {useProcessQueuesTimeSeriesQuery} from 'sentry/views/insights/queues/queries/useProcessQueuesTimeSeriesQuery';
  8. import {usePublishQueuesTimeSeriesQuery} from 'sentry/views/insights/queues/queries/usePublishQueuesTimeSeriesQuery';
  9. import type {Referrer} from 'sentry/views/insights/queues/referrers';
  10. import {CHART_HEIGHT} from 'sentry/views/insights/queues/settings';
  11. interface Props {
  12. referrer: Referrer;
  13. destination?: string;
  14. error?: Error | null;
  15. }
  16. export function ThroughputChart({error, destination, referrer}: Props) {
  17. const {data: publishData, isLoading: isPublishDataLoading} =
  18. usePublishQueuesTimeSeriesQuery({
  19. destination,
  20. referrer,
  21. });
  22. const {data: processData, isLoading: isProcessDataLoading} =
  23. useProcessQueuesTimeSeriesQuery({
  24. destination,
  25. referrer,
  26. });
  27. return (
  28. <ChartPanel title={t('Published vs Processed')}>
  29. <Chart
  30. height={CHART_HEIGHT}
  31. grid={{
  32. left: '0',
  33. right: '0',
  34. top: '8px',
  35. bottom: '0',
  36. }}
  37. data={
  38. [
  39. {
  40. seriesName: t('Published'),
  41. data: publishData['spm()'].data,
  42. },
  43. {
  44. seriesName: t('Processed'),
  45. data: processData['spm()'].data,
  46. },
  47. ] ?? []
  48. }
  49. loading={isPublishDataLoading || isProcessDataLoading}
  50. error={error}
  51. chartColors={CHART_PALETTE[2].slice(1, 3)}
  52. type={ChartType.LINE}
  53. aggregateOutputFormat="rate"
  54. rateUnit={RateUnit.PER_MINUTE}
  55. tooltipFormatterOptions={{
  56. valueFormatter: value => formatRate(value, RateUnit.PER_MINUTE),
  57. }}
  58. showLegend
  59. />
  60. </ChartPanel>
  61. );
  62. }