performance.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import Grid from 'sentry/components/charts/components/grid';
  2. import type {LineChartProps} from 'sentry/components/charts/lineChart';
  3. import {transformToLineSeries} from 'sentry/components/charts/lineChart';
  4. import getBreakpointChartOptionsFromData, {
  5. type EventBreakpointChartData,
  6. } from 'sentry/components/events/eventStatisticalDetector/breakpointChartOptions';
  7. import type {EventsStatsSeries} from 'sentry/types/organization';
  8. import {transformStatsResponse} from 'sentry/utils/profiling/hooks/utils';
  9. import {lightTheme as theme} from 'sentry/utils/theme';
  10. import type {NormalizedTrendsTransaction} from 'sentry/views/performance/trends/types';
  11. import {DEFAULT_FONT_FAMILY, slackChartDefaults, slackChartSize} from './slack';
  12. import type {RenderDescriptor} from './types';
  13. import {ChartType} from './types';
  14. export const performanceCharts: RenderDescriptor<ChartType>[] = [];
  15. export type FunctionRegressionPercentileData = {
  16. data: EventsStatsSeries<'p95()'>;
  17. };
  18. const performanceChartDefaults = {
  19. ...slackChartDefaults,
  20. grid: Grid({left: 10, right: 5, bottom: 5}),
  21. };
  22. function modifyOptionsForSlack(options: Omit<LineChartProps, 'series'>) {
  23. options.legend = options.legend || {};
  24. options.legend.icon = 'none';
  25. options.legend.left = '25';
  26. options.legend.top = '20';
  27. options.grid = slackChartDefaults.grid;
  28. options.yAxis = options.yAxis || {};
  29. options.yAxis.axisLabel = options.yAxis.axisLabel || {};
  30. options.yAxis.axisLabel.fontSize = 11;
  31. options.yAxis.axisLabel.fontFamily = DEFAULT_FONT_FAMILY;
  32. options.xAxis = options.xAxis || {};
  33. options.xAxis.axisLabel = options.xAxis.axisLabel || {};
  34. options.xAxis.axisLabel.fontSize = 11;
  35. options.xAxis.axisLabel.fontFamily = DEFAULT_FONT_FAMILY;
  36. return {
  37. ...options,
  38. grid: performanceChartDefaults.grid,
  39. visualMap: options.options?.visualMap,
  40. backgroundColor: theme.background,
  41. };
  42. }
  43. type FunctionRegressionChartData = {
  44. evidenceData: NormalizedTrendsTransaction;
  45. rawResponse: any;
  46. };
  47. performanceCharts.push({
  48. key: ChartType.SLACK_PERFORMANCE_ENDPOINT_REGRESSION,
  49. getOption: (data: EventBreakpointChartData) => {
  50. const {chartOptions, series} = getBreakpointChartOptionsFromData(
  51. data,
  52. ChartType.SLACK_PERFORMANCE_ENDPOINT_REGRESSION,
  53. theme
  54. );
  55. const transformedSeries = transformToLineSeries({series});
  56. const modifiedOptions = modifyOptionsForSlack(chartOptions);
  57. return {
  58. ...modifiedOptions,
  59. series: transformedSeries,
  60. };
  61. },
  62. ...slackChartSize,
  63. });
  64. performanceCharts.push({
  65. key: ChartType.SLACK_PERFORMANCE_FUNCTION_REGRESSION,
  66. getOption: (data: FunctionRegressionChartData) => {
  67. const transformed = transformStatsResponse(
  68. 'profileFunctions',
  69. ['p95()'],
  70. data.rawResponse
  71. );
  72. const percentileData = {
  73. data: transformed,
  74. };
  75. const param = {
  76. percentileData: percentileData as FunctionRegressionPercentileData,
  77. evidenceData: data.evidenceData,
  78. };
  79. const {chartOptions, series} = getBreakpointChartOptionsFromData(
  80. param,
  81. ChartType.SLACK_PERFORMANCE_FUNCTION_REGRESSION,
  82. theme
  83. );
  84. const transformedSeries = transformToLineSeries({series});
  85. const modifiedOptions = modifyOptionsForSlack(chartOptions);
  86. return {
  87. ...modifiedOptions,
  88. series: transformedSeries,
  89. };
  90. },
  91. ...slackChartSize,
  92. });