metricAlert.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import type {LineSeriesOption} from 'echarts';
  2. import type {AreaChartSeries} from 'sentry/components/charts/areaChart';
  3. import XAxis from 'sentry/components/charts/components/xAxis';
  4. import AreaSeries from 'sentry/components/charts/series/areaSeries';
  5. import type {SessionApiResponse} from 'sentry/types';
  6. import {lightTheme as theme} from 'sentry/utils/theme';
  7. import {
  8. getMetricAlertChartOption,
  9. MetricChartData,
  10. transformSessionResponseToSeries,
  11. } from 'sentry/views/alerts/rules/metric/details/metricChartOption';
  12. import {DEFAULT_FONT_FAMILY, slackChartDefaults, slackChartSize} from './slack';
  13. import {ChartType, RenderDescriptor} from './types';
  14. const metricAlertXaxis = XAxis({
  15. theme,
  16. splitNumber: 3,
  17. isGroupedByDate: true,
  18. axisLabel: {fontSize: 11, fontFamily: DEFAULT_FONT_FAMILY},
  19. });
  20. function transformAreaSeries(series: AreaChartSeries[]): LineSeriesOption[] {
  21. return series.map(({seriesName, data, ...otherSeriesProps}) => {
  22. const areaSeries = AreaSeries({
  23. name: seriesName,
  24. data: data.map(({name, value}) => [name, value]),
  25. lineStyle: {
  26. opacity: 1,
  27. width: 0.4,
  28. },
  29. areaStyle: {
  30. opacity: 1.0,
  31. },
  32. animation: false,
  33. animationThreshold: 1,
  34. animationDuration: 0,
  35. ...otherSeriesProps,
  36. });
  37. // Fix incident label font family, cannot use Rubik
  38. if (areaSeries.markLine?.label?.fontFamily) {
  39. areaSeries.markLine.label.fontFamily = DEFAULT_FONT_FAMILY;
  40. }
  41. return areaSeries;
  42. });
  43. }
  44. export const metricAlertCharts: RenderDescriptor<ChartType>[] = [];
  45. metricAlertCharts.push({
  46. key: ChartType.SLACK_METRIC_ALERT_EVENTS,
  47. getOption: (data: MetricChartData) => {
  48. const {chartOption} = getMetricAlertChartOption(data);
  49. return {
  50. ...chartOption,
  51. backgroundColor: theme.background,
  52. series: transformAreaSeries(chartOption.series),
  53. xAxis: metricAlertXaxis,
  54. grid: slackChartDefaults.grid,
  55. };
  56. },
  57. ...slackChartSize,
  58. });
  59. interface MetricAlertSessionData extends Omit<MetricChartData, 'timeseriesData'> {
  60. sessionResponse: SessionApiResponse;
  61. }
  62. metricAlertCharts.push({
  63. key: ChartType.SLACK_METRIC_ALERT_SESSIONS,
  64. getOption: (data: MetricAlertSessionData) => {
  65. const {sessionResponse, rule, ...rest} = data;
  66. const {chartOption} = getMetricAlertChartOption({
  67. ...rest,
  68. rule,
  69. timeseriesData: transformSessionResponseToSeries(sessionResponse, rule),
  70. });
  71. return {
  72. ...chartOption,
  73. backgroundColor: theme.background,
  74. series: transformAreaSeries(chartOption.series),
  75. xAxis: metricAlertXaxis,
  76. grid: slackChartDefaults.grid,
  77. };
  78. },
  79. ...slackChartSize,
  80. });