Skip to content

Conversation

jasonyuezhang
Copy link
Owner

Adds a copy of the metric alert chartcuterie chart options, but for detectors. Should output the same chart, but it accepts detector and open period data instead of rule and incident data.

This is a stopgap to get notifications working in the new system asap. My intention is to later on put our new chart UI here so that the new alerts will look like the new UI.


Copied from getsentry#101171
Original PR: getsentry#101171

Copy link

Add Chartcuterie Support for Metric Detector Charts in Frontend

This PR introduces frontend support for rendering metric detector charts using Chartcuterie by largely duplicating the approach used for metric alert charts. Major changes include implementing new chart config logic for detectors, registering new chart types for metric detectors, and updating the core Chartcuterie configuration and types to handle and distinguish detector-based chart events. The PR adapts existing metric alert chart options to accept detector and open period data, enabling notifications for the new detector system as an interim solution before planned UI improvements.

Key Changes

• Added new file static/app/chartcuterie/metricDetector.tsx to implement Chartcuterie logic for metric detector charts, including area series transformation and chart registration.
• Created getMetricDetectorChartOption and utilities in static/app/views/detectors/components/details/metric/charts/metricDetectorChartOptions.tsx to generate chart options from detector data.
• Registered new chart types SLACK_METRIC_DETECTOR_EVENTS and SLACK_METRIC_DETECTOR_SESSIONS in static/app/chartcuterie/types.tsx.
• Integrated metric detector chart registration into static/app/chartcuterie/config.tsx.
• Revised static/app/types/workflowEngine/detectors.tsx to clean up detector type typings.

Affected Areas

static/app/chartcuterie/metricDetector.tsx
static/app/views/detectors/components/details/metric/charts/metricDetectorChartOptions.tsx
static/app/chartcuterie/config.tsx
static/app/chartcuterie/types.tsx
static/app/types/workflowEngine/detectors.tsx

This summary was automatically generated by @propel-code-bot

series[0]!.z = 1;
series[0]!.color = colors[0];

const dataArr = timeseriesData[0]!.data;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[CriticalError]

Potential array bounds issue: timeseriesData[0]!.data assumes the arrays have at least one element. If timeseriesData is empty, this will cause a runtime error when accessing array properties.

Suggested change
const dataArr = timeseriesData[0]!.data;
if (!timeseriesData.length) {
throw new Error('Timeseries data is required for metric detector chart');
}
const dataArr = timeseriesData[0].data;

Committable suggestion

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Context for Agents
[**CriticalError**]

Potential array bounds issue: `timeseriesData[0]!.data` assumes the arrays have at least one element. If `timeseriesData` is empty, this will cause a runtime error when accessing array properties.

```suggestion
  if (!timeseriesData.length) {
    throw new Error('Timeseries data is required for metric detector chart');
  }
  const dataArr = timeseriesData[0].data;
```

⚡ **Committable suggestion**

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

File: static/app/views/detectors/components/details/metric/charts/metricDetectorChartOptions.tsx
Line: 182

};
}

function getWaitingForDataRange(dataArr: any) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[BestPractice]

Type safety issue: getWaitingForDataRange parameter dataArr is typed as any, which defeats TypeScript's type checking. This could lead to runtime errors if the wrong data structure is passed.

Suggested change
function getWaitingForDataRange(dataArr: any) {
function getWaitingForDataRange(dataArr: Array<{value: number; name: string}>): {startIndex: number; endIndex: number} {

Committable suggestion

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Context for Agents
[**BestPractice**]

Type safety issue: `getWaitingForDataRange` parameter `dataArr` is typed as `any`, which defeats TypeScript's type checking. This could lead to runtime errors if the wrong data structure is passed.

```suggestion
function getWaitingForDataRange(dataArr: Array<{value: number; name: string}>): {startIndex: number; endIndex: number} {
```

⚡ **Committable suggestion**

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

File: static/app/views/detectors/components/details/metric/charts/metricDetectorChartOptions.tsx
Line: 414

Comment on lines +414 to +415
function getWaitingForDataRange(dataArr: any) {
if (dataArr[0].value > 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[CriticalError]

Potential array bounds issue: The function doesn't validate that dataArr has elements before accessing dataArr[0] and dataArr[i]. An empty array will cause runtime errors.

Suggested Change
Suggested change
function getWaitingForDataRange(dataArr: any) {
if (dataArr[0].value > 0) {
function getWaitingForDataRange(dataArr: Array<{value: number; name: string}>): {startIndex: number; endIndex: number} {
if (!dataArr.length) {
return {startIndex: 0, endIndex: 0};
}
if (dataArr[0].value > 0) {
return {startIndex: 0, endIndex: 0};
}

Committable suggestion

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Context for Agents
[**CriticalError**]

Potential array bounds issue: The function doesn't validate that `dataArr` has elements before accessing `dataArr[0]` and `dataArr[i]`. An empty array will cause runtime errors.

<details>
<summary>Suggested Change</summary>

```suggestion
function getWaitingForDataRange(dataArr: Array<{value: number; name: string}>): {startIndex: number; endIndex: number} {
  if (!dataArr.length) {
    return {startIndex: 0, endIndex: 0};
  }
  
  if (dataArr[0].value > 0) {
    return {startIndex: 0, endIndex: 0};
  }
```

⚡ **Committable suggestion**

Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

</details>

File: static/app/views/detectors/components/details/metric/charts/metricDetectorChartOptions.tsx
Line: 415

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants