types.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import type {EChartsOption} from 'echarts';
  2. /**
  3. * Defines the keys which may be passed into the chartcuterie chart rendering
  4. * service.
  5. *
  6. * When adding or removing from this list, please also update the
  7. * sentry/charts/types.py file
  8. */
  9. export enum ChartType {
  10. SLACK_DISCOVER_TOTAL_PERIOD = 'slack:discover.totalPeriod',
  11. SLACK_DISCOVER_TOTAL_DAILY = 'slack:discover.totalDaily',
  12. SLACK_DISCOVER_TOP5_PERIOD = 'slack:discover.top5Period',
  13. SLACK_DISCOVER_TOP5_PERIOD_LINE = 'slack:discover.top5PeriodLine',
  14. SLACK_DISCOVER_TOP5_DAILY = 'slack:discover.top5Daily',
  15. SLACK_DISCOVER_PREVIOUS_PERIOD = 'slack:discover.previousPeriod',
  16. SLACK_METRIC_ALERT_EVENTS = 'slack:metricAlert.events',
  17. SLACK_METRIC_ALERT_SESSIONS = 'slack:metricAlert.sessions',
  18. SLACK_PERFORMANCE_ENDPOINT_REGRESSION = 'slack:performance.endpointRegression',
  19. SLACK_PERFORMANCE_FUNCTION_REGRESSION = 'slack:performance.functionRegression',
  20. }
  21. /**
  22. * XXX(epurkhiser): These are copied directly over from chartucterie to avoid
  23. * installing the package, which has some system-level dependencies we would
  24. * prefer not to install with sentry.
  25. */
  26. export type RenderOption = Omit<EChartsOption, 'animation' | 'tooltip' | 'toolbox'>;
  27. /**
  28. * Describes configuration for a renderable chart style
  29. */
  30. export type RenderDescriptor<D extends string = string> = {
  31. /**
  32. * Produce the echart option config for rendering the charts series. It is up
  33. * to the implementation to declare what data it should receive, as long as
  34. * it produces a valid ECharts Option config.
  35. */
  36. getOption: (data: any) => RenderOption;
  37. /**
  38. * Height of the produced image in pixels
  39. */
  40. height: number;
  41. key: D;
  42. /**
  43. * Width of the produced image in pixels
  44. */
  45. width: number;
  46. };
  47. /**
  48. * Maps style keys to style descriptor configuration
  49. */
  50. export type RenderConfig<D extends string = string> = Map<D, RenderDescriptor<D>>;
  51. /**
  52. * The data given to the service to render a chart
  53. */
  54. export type RenderData = {
  55. /**
  56. * Arbitrary series data. The RenderDescriptor.getOption should transform this
  57. * into a valid echarts series.
  58. */
  59. data: any;
  60. /**
  61. * Globally unique render ID.
  62. */
  63. requestId: string;
  64. /**
  65. * The style config key
  66. */
  67. style: string;
  68. };
  69. /**
  70. * Performs any additional initialization steps on Chartcuterie's global
  71. * echarts object on service start up. For example, registerMaps can
  72. * be called here to register any available maps to ECharts.
  73. */
  74. export type InitFn = (echarts: any) => void;
  75. /**
  76. * The configuration object type expected to be provided to the service
  77. */
  78. export type ChartcuterieConfig = {
  79. renderConfig: RenderConfig;
  80. /**
  81. * A string version identifier for the configuration. This may be useful for
  82. * validating that a chart is being rendered using a specific known
  83. * configuration.
  84. */
  85. version: string;
  86. /**
  87. * The optional initialization function to run when the service starts
  88. * or restarts due to configuration updates.
  89. */
  90. init?: InitFn;
  91. };
  92. /**
  93. * Configuration to specify how often to poll for configuration changes
  94. */
  95. export type PollingConfig = {
  96. /**
  97. * The number of seconds between each polling attempt when the application boots
  98. * and has yet to load a configuration.
  99. */
  100. bootInterval: number;
  101. /**
  102. * The number of seconds between each polling attempt after the application
  103. * has already loaded a valid configuration file
  104. */
  105. idleInterval: number;
  106. };