mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
make alert tab create alert button work with default datasource (#40334)
This commit is contained in:
parent
6e395c8275
commit
c43b82d44b
@ -34,9 +34,16 @@ const dataSources = {
|
||||
prometheus: mockDataSource<PromOptions>({
|
||||
name: 'Prometheus',
|
||||
type: DataSourceType.Prometheus,
|
||||
isDefault: false,
|
||||
}),
|
||||
default: mockDataSource<PromOptions>({
|
||||
name: 'Default',
|
||||
type: DataSourceType.Prometheus,
|
||||
isDefault: true,
|
||||
}),
|
||||
};
|
||||
dataSources.prometheus.meta.alerting = true;
|
||||
dataSources.default.meta.alerting = true;
|
||||
|
||||
const mocks = {
|
||||
getAllDataSources: typeAsJestMock(getAllDataSources),
|
||||
@ -165,6 +172,10 @@ describe('PanelAlertTabContent', () => {
|
||||
dsService.datasources[dataSources.prometheus.name] = new PrometheusDatasource(
|
||||
dataSources.prometheus
|
||||
) as DataSourceApi<any, any>;
|
||||
dsService.datasources[dataSources.default.name] = new PrometheusDatasource(dataSources.default) as DataSourceApi<
|
||||
any,
|
||||
any
|
||||
>;
|
||||
setDataSourceSrv(dsService);
|
||||
});
|
||||
|
||||
@ -189,6 +200,28 @@ describe('PanelAlertTabContent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('Will work with default datasource', async () => {
|
||||
await renderAlertTabContent(dashboard, ({
|
||||
...panel,
|
||||
datasource: undefined,
|
||||
maxDataPoints: 100,
|
||||
interval: '10s',
|
||||
} as any) as PanelModel);
|
||||
const button = await ui.createButton.find();
|
||||
const href = button.href;
|
||||
const match = href.match(/alerting\/new\?defaults=(.*)&returnTo=/);
|
||||
expect(match).toHaveLength(2);
|
||||
const defaults = JSON.parse(decodeURIComponent(match![1]));
|
||||
expect(defaults.queries[0].model).toEqual({
|
||||
expr: 'sum(some_metric [5m])) by (app)',
|
||||
refId: 'A',
|
||||
datasource: 'Default',
|
||||
interval: '',
|
||||
intervalMs: 300000,
|
||||
maxDataPoints: 100,
|
||||
});
|
||||
});
|
||||
|
||||
it('Will take into account datasource minInterval', async () => {
|
||||
((getDatasourceSrv() as any) as MockDataSourceSrv).datasources[dataSources.prometheus.name].interval = '7m';
|
||||
|
||||
|
@ -229,8 +229,8 @@ const dataQueriesToGrafanaQueries = async (
|
||||
): Promise<AlertQuery[]> => {
|
||||
const result: AlertQuery[] = [];
|
||||
for (const target of queries) {
|
||||
const dsName = target.datasource || datasourceName;
|
||||
const datasource = await getDataSourceSrv().get(dsName);
|
||||
const datasource = await getDataSourceSrv().get(target.datasource || datasourceName);
|
||||
const dsName = datasource.name;
|
||||
|
||||
const range = rangeUtil.relativeToTimeRange(relativeTimeRange);
|
||||
const { interval, intervalMs } = getIntervals(range, minInterval ?? datasource.interval, maxDataPoints);
|
||||
|
Loading…
Reference in New Issue
Block a user