Skip to content

Commit 9a4c6d6

Browse files
authored
fix: fix list check alerts case (#1155)
Fixes the case for alerts field as included in the list checks endpoint response. Related grafana/synthetic-monitoring-api/pull/1387
1 parent 8471cd2 commit 9a4c6d6

File tree

11 files changed

+15
-15
lines changed

11 files changed

+15
-15
lines changed

‎src/components/AlertStatus/AlertStatus.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface AlertStatusProps {
1919

2020
export const AlertStatus = ({ check, compact }: AlertStatusProps) => {
2121
const hasAlertSensitivity = check.alertSensitivity !== undefined && check.alertSensitivity !== AlertSensitivity.None;
22-
const hasPerCheckAlerts = (check.Alerts?.length ?? 0) > 0;
22+
const hasPerCheckAlerts = (check.alerts?.length ?? 0) > 0;
2323

2424
const metricsDS = useMetricsDS();
2525

@@ -52,7 +52,7 @@ export const AlertStatusContent = ({ check, compact, metricsDSName, hasAlertSens
5252
isLoading: perCheckGroupsLoading,
5353
isError: perCheckGroupsError,
5454
refetch: perCheckGroupsRefetch,
55-
} = useGMAlertRules(check.Alerts);
55+
} = useGMAlertRules(check.alerts);
5656

5757
const perCheckGroupsResponse = {
5858
perCheckGroups,

‎src/components/CheckEditor/transformations/toFormValues.http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function getHTTPCheckFormValues(check: HTTPCheck): CheckFormValuesHttp {
2929
},
3030
alerts: {
3131
...base.alerts,
32-
...predefinedAlertsToFormValues(HTTP_PREDEFINED_ALERTS, check.Alerts || []),
32+
...predefinedAlertsToFormValues(HTTP_PREDEFINED_ALERTS, check.alerts || []),
3333
},
3434
};
3535
}

‎src/components/CheckEditor/transformations/toFormValues.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function getBaseFormValuesFromCheck(check: Check): Omit<CheckFormValues,
5252
probes: check.probes,
5353
target: check.target,
5454
timeout: check.timeout,
55-
alerts: predefinedAlertsToFormValues(GLOBAL_PREDEFINED_ALERTS, check.Alerts || []),
55+
alerts: predefinedAlertsToFormValues(GLOBAL_PREDEFINED_ALERTS, check.alerts || []),
5656
};
5757
}
5858

‎src/components/CheckForm/checkForm.hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function useCheckForm({ check, checkType, checkState, onTestSuccess }: Us
6565
const alertsEnabled = useFeatureFlag(FeatureName.AlertsPerCheck).isEnabled;
6666

6767
const { mutateAsync: updateAlertsForCheck } = useUpdateAlertsForCheck({
68-
prevAlerts: check?.Alerts,
68+
prevAlerts: check?.alerts,
6969
});
7070

7171
const handleAlertsAndNavigate = useCallback(

‎src/data/useGMAlerts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function queryAlertApi() {
3838
});
3939
}
4040

41-
export function findRelevantAlertGroups(groups: PrometheusAlertsGroup[], alerts: Check['Alerts']) {
41+
export function findRelevantAlertGroups(groups: PrometheusAlertsGroup[], alerts: Check['alerts']) {
4242
const alertNames = alerts?.map((alert: { name: string }) => alert.name);
4343

4444
return groups

‎src/hooks/useAlertRules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function useAlertRules(alertSensitivity: Check['alertSensitivity']) {
2727
}, [data, isError, isLoading, alertFilter, refetch]);
2828
}
2929

30-
export function useGMAlertRules(alerts: Check['Alerts']) {
30+
export function useGMAlertRules(alerts: Check['alerts']) {
3131
const { data, isLoading, isError, refetch } = useGMAlerts();
3232

3333
return useMemo(() => {

‎src/hooks/useTerraformConfig.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,13 @@ describe('terraform config generation', () => {
401401
]);
402402
});
403403

404-
test('generates grafana_synthetic_monitoring_check_alerts resources for checks with Alerts', async () => {
404+
test('generates grafana_synthetic_monitoring_check_alerts resources for checks with alerts', async () => {
405405
const result = await renderTerraformHook([BASIC_HTTP_CHECK], [PRIVATE_PROBE]);
406406
const resourceName = sanitizeName(`${BASIC_HTTP_CHECK.job}_${BASIC_HTTP_CHECK.target}`);
407407
expect(result.current.config.resource.grafana_synthetic_monitoring_check_alerts).toEqual({
408408
[resourceName]: {
409409
check_id: String(BASIC_HTTP_CHECK.id),
410-
alerts: (BASIC_HTTP_CHECK.Alerts!).map(alert => ({
410+
alerts: (BASIC_HTTP_CHECK.alerts!).map(alert => ({
411411
name: alert.name,
412412
threshold: alert.threshold,
413413
period: alert.period,

‎src/hooks/useTerraformConfig.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ function generateTerraformConfig(probes: Probe[], checks: Check[], apiHost?: str
6565
}
6666

6767
const checkAlertsConfig = checks
68-
.filter((check) => check.Alerts && check.Alerts.length > 0)
68+
.filter((check) => check.alerts && check.alerts.length > 0)
6969
.reduce((acc: TFCheckAlertsConfig, check) => {
7070
const resourceName = sanitizeName(`${check.job}_${check.target}`);
7171
acc[resourceName] = {
7272
check_id: String(check.id),
73-
alerts: (check.Alerts!).map((alert) => ({
73+
alerts: (check.alerts!).map((alert) => ({
7474
name: alert.name,
7575
threshold: alert.threshold,
7676
period: alert.period,
@@ -90,7 +90,7 @@ function generateTerraformConfig(probes: Probe[], checks: Check[], apiHost?: str
9090
});
9191

9292
const checkAlertsCommands = checks
93-
.filter((check) => check.Alerts && check.Alerts.length > 0)
93+
.filter((check) => check.alerts && check.alerts.length > 0)
9494
.map((check) => {
9595
return `terraform import grafana_synthetic_monitoring_check_alerts.${sanitizeName(
9696
`${check.job}_${check.target}`

‎src/test/db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const baseCheckModel = ({ sequence }: { sequence: number }) => ({
2525
timeout: faker.number.int({ min: 30, max: 60 * 1000 }),
2626
enabled: true,
2727
alertSensitivity: faker.helpers.arrayElement(Object.values(AlertSensitivity)),
28-
Alerts: [],
28+
alerts: [],
2929
basicMetricsOnly: faker.datatype.boolean(),
3030
labels: [{ name: faker.animal.petName(), value: faker.color.human() }],
3131
probes: [],

‎src/test/fixtures/checks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const BASIC_HTTP_CHECK: HTTPCheck = db.check.build(
8787
value: 'httpLabelValue',
8888
},
8989
],
90-
Alerts: [
90+
alerts: [
9191
{
9292
name: CheckAlertType.ProbeFailedExecutionsTooHigh,
9393
threshold: 1,

‎src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ export interface CheckBase {
407407
basicMetricsOnly: boolean;
408408
labels: Label[]; // Currently list of [name:value]... can it be Labels?
409409
probes: number[];
410-
Alerts?: CheckAlertPublished[];
410+
alerts?: CheckAlertPublished[];
411411
}
412412

413413
export type Check =

0 commit comments

Comments
 (0)