Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/datasource/DataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PRIVATE_PROBE } from 'test/fixtures/probes';
import { apiRoute, ApiRoutes, getServerRequests } from 'test/handlers';
import { server } from 'test/server';

import { AlertSensitivity } from 'types';
import { SMDataSource } from 'datasource/DataSource';

type Entry = {
Expand Down Expand Up @@ -256,4 +257,25 @@ describe('SMDataSource', () => {
expect(result?.uid).toEqual('grafanacloud-metrics');
});
});

describe('listChecks', () => {
it('should normalize empty alertSensitivity to AlertSensitivity.None', async () => {
const checkWithEmptySensitivity = { ...BASIC_HTTP_CHECK, alertSensitivity: '' };
const checkWithSetSensitivity = { ...BASIC_HTTP_CHECK, alertSensitivity: AlertSensitivity.Medium };

server.use(
apiRoute('listChecks', {
result: () => ({
json: [checkWithEmptySensitivity, checkWithSetSensitivity],
}),
})
);

const smDataSource = new SMDataSource(SM_DATASOURCE);
const result = await smDataSource.listChecks();

expect(result[0].alertSensitivity).toEqual(AlertSensitivity.None);
expect(result[1].alertSensitivity).toEqual(AlertSensitivity.Medium);
});
});
});
10 changes: 8 additions & 2 deletions src/datasource/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { BackendSrvRequest, getBackendSrv, getTemplateSrv } from '@grafana/runti
import { isArray } from 'lodash';
import { firstValueFrom } from 'rxjs';

import { Check, CheckAlertDraft, ListChannelsResponse, Probe, ThresholdSettings } from '../types';
import { AlertSensitivity, Check, CheckAlertDraft, ListChannelsResponse, Probe, ThresholdSettings } from '../types';
import {
AccessTokenResponse,
AddCheckResult,
Expand Down Expand Up @@ -311,7 +311,13 @@ export class SMDataSource extends DataSourceApi<SMQuery, SMOptions> {
}

async listChecks(includeAlerts = false) {
return this.fetchAPI<ListCheckResult>(`${this.instanceSettings.url}/sm/check/list?includeAlerts=${includeAlerts}`);
return this.fetchAPI<ListCheckResult>(
`${this.instanceSettings.url}/sm/check/list?includeAlerts=${includeAlerts}`
).then((checks) =>
checks.map((check) =>
check.alertSensitivity ? check : { ...check, alertSensitivity: AlertSensitivity.None }
)
);
}

async testCheck(check: Check) {
Expand Down
Loading