performance.tsx 2.9 KB

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