Prometheus: Fix bug when adding a query in mixed datasource (#69424)

default query needs to not be a function separate from ds
This commit is contained in:
Brendan O'Handley 2023-06-02 12:24:42 -04:00 committed by GitHub
parent 770ae4bbc9
commit 4fdccef7b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 12 deletions

View File

@ -1265,7 +1265,12 @@ export class PrometheusDatasource
}
getDefaultQuery(app: CoreApp): PromQuery {
const defaults = promDefaultBaseQuery();
const defaults = {
refId: 'A',
expr: '',
range: true,
instant: false,
};
if (app === CoreApp.UnifiedAlerting) {
return {
@ -1335,12 +1340,3 @@ export function prometheusRegularEscape(value: any) {
export function prometheusSpecialRegexEscape(value: any) {
return typeof value === 'string' ? value.replace(/\\/g, '\\\\\\\\').replace(/[$^*{}\[\]\'+?.()|]/g, '\\\\$&') : value;
}
export function promDefaultBaseQuery(): PromQuery {
return {
refId: 'A',
expr: '',
range: true,
instant: false,
};
}

View File

@ -5,7 +5,6 @@ import { selectOptionInTest } from 'test/helpers/selectOptionInTest';
import { CoreApp } from '@grafana/data';
import { promDefaultBaseQuery } from '../../datasource';
import { PromQuery } from '../../types';
import { getQueryWithDefaults } from '../state';
@ -107,7 +106,15 @@ function setup(queryOverrides: Partial<PromQuery> = {}, app: CoreApp = CoreApp.P
const props = {
app,
query: {
...getQueryWithDefaults(promDefaultBaseQuery(), CoreApp.PanelEditor),
...getQueryWithDefaults(
{
refId: 'A',
expr: '',
range: true,
instant: false,
} as PromQuery,
CoreApp.PanelEditor
),
...queryOverrides,
},
onRunQuery: jest.fn(),