diff --git a/pkg/services/ngalert/state/template.go b/pkg/services/ngalert/state/template.go index b6e8bb11a00..b5f8458711e 100644 --- a/pkg/services/ngalert/state/template.go +++ b/pkg/services/ngalert/state/template.go @@ -107,7 +107,7 @@ func graphLink(rawQuery string) string { escapedDatasource := url.QueryEscape(q.Datasource) return fmt.Sprintf( - `/explore?left=["now-1h","now",%[1]q,{"datasource":%[1]q,"expr":%q,"instant":false,"range":true}]`, escapedDatasource, escapedExpression) + `/explore?left={"datasource":%[1]q,"queries":[{"datasource":%[1]q,"expr":%q,"instant":false,"range":true,"refId":"A"}],"range":{"from":"now-1h","to":"now"}}`, escapedDatasource, escapedExpression) } func tableLink(rawQuery string) string { @@ -120,5 +120,5 @@ func tableLink(rawQuery string) string { escapedDatasource := url.QueryEscape(q.Datasource) return fmt.Sprintf( - `/explore?left=["now-1h","now",%[1]q,{"datasource":%[1]q,"expr":%q,"instant":true,"range":false}]`, escapedDatasource, escapedExpression) + `/explore?left={"datasource":%[1]q,"queries":[{"datasource":%[1]q,"expr":%q,"instant":true,"range":false,"refId":"A"}],"range":{"from":"now-1h","to":"now"}}`, escapedDatasource, escapedExpression) } diff --git a/pkg/services/ngalert/state/template_test.go b/pkg/services/ngalert/state/template_test.go index 398349b61c3..ae5538bfdc0 100644 --- a/pkg/services/ngalert/state/template_test.go +++ b/pkg/services/ngalert/state/template_test.go @@ -359,11 +359,11 @@ func TestExpandTemplate(t *testing.T) { }, { name: "graphLink", text: `{{ graphLink "{\"expr\": \"up\", \"datasource\": \"gdev-prometheus\"}" }}`, - expected: `/explore?left=["now-1h","now","gdev-prometheus",{"datasource":"gdev-prometheus","expr":"up","instant":false,"range":true}]`, + expected: `/explore?left={"datasource":"gdev-prometheus","queries":[{"datasource":"gdev-prometheus","expr":"up","instant":false,"range":true,"refId":"A"}],"range":{"from":"now-1h","to":"now"}}`, }, { name: "graphLink should escape both the expression and the datasource", text: `{{ graphLink "{\"expr\": \"process_open_fds > 0\", \"datasource\": \"gdev prometheus\"}" }}`, - expected: `/explore?left=["now-1h","now","gdev+prometheus",{"datasource":"gdev+prometheus","expr":"process_open_fds+%3E+0","instant":false,"range":true}]`, + expected: `/explore?left={"datasource":"gdev+prometheus","queries":[{"datasource":"gdev+prometheus","expr":"process_open_fds+%3E+0","instant":false,"range":true,"refId":"A"}],"range":{"from":"now-1h","to":"now"}}`, }, { name: "check that graphLink returns an empty string when the query is not formatted correctly", text: "{{ graphLink \"up\" }}", @@ -371,11 +371,11 @@ func TestExpandTemplate(t *testing.T) { }, { name: "tableLink", text: `{{ tableLink "{\"expr\": \"up\", \"datasource\": \"gdev-prometheus\"}" }}`, - expected: `/explore?left=["now-1h","now","gdev-prometheus",{"datasource":"gdev-prometheus","expr":"up","instant":true,"range":false}]`, + expected: `/explore?left={"datasource":"gdev-prometheus","queries":[{"datasource":"gdev-prometheus","expr":"up","instant":true,"range":false,"refId":"A"}],"range":{"from":"now-1h","to":"now"}}`, }, { name: "tableLink should escape both the expression and the datasource", text: `{{ tableLink "{\"expr\": \"process_open_fds > 0\", \"datasource\": \"gdev prometheus\"}" }}`, - expected: `/explore?left=["now-1h","now","gdev+prometheus",{"datasource":"gdev+prometheus","expr":"process_open_fds+%3E+0","instant":true,"range":false}]`, + expected: `/explore?left={"datasource":"gdev+prometheus","queries":[{"datasource":"gdev+prometheus","expr":"process_open_fds+%3E+0","instant":true,"range":false,"refId":"A"}],"range":{"from":"now-1h","to":"now"}}`, }, { name: "check that tableLink returns an empty string when the query is not formatted correctly", text: "{{ tableLink \"up\" }}", diff --git a/public/app/features/alerting/unified/components/rule-viewer/RuleViewerVisualization.tsx b/public/app/features/alerting/unified/components/rule-viewer/RuleViewerVisualization.tsx index 4739f2e526b..c743f699a71 100644 --- a/public/app/features/alerting/unified/components/rule-viewer/RuleViewerVisualization.tsx +++ b/public/app/features/alerting/unified/components/rule-viewer/RuleViewerVisualization.tsx @@ -136,7 +136,11 @@ function createExploreLink(settings: DataSourceInstanceSettings, query: AlertQue const queryParams = { ...rest, datasource: name }; return urlUtil.renderUrl(`${config.appSubUrl}/explore`, { - left: JSON.stringify(['now-1h', 'now', name, queryParams]), + left: JSON.stringify({ + datasource: name, + queries: [{ refId: 'A', datasource: name, expr: queryParams }], + range: { from: 'now-1h', to: 'now' }, + }), }); } diff --git a/public/app/features/alerting/unified/utils/misc.ts b/public/app/features/alerting/unified/utils/misc.ts index 66ea5f64292..181ccd33dfe 100644 --- a/public/app/features/alerting/unified/utils/misc.ts +++ b/public/app/features/alerting/unified/utils/misc.ts @@ -27,13 +27,11 @@ export function createViewLink(ruleSource: RulesSource, rule: CombinedRule, retu export function createExploreLink(dataSourceName: string, query: string) { return createUrl(`/explore`, { - left: JSON.stringify([ - 'now-1h', - 'now', - dataSourceName, - { datasource: dataSourceName, expr: query }, - { ui: [true, true, true, 'none'] }, - ]), + left: JSON.stringify({ + datasource: dataSourceName, + queries: [{ refId: 'A', datasource: dataSourceName, expr: query }], + range: { from: 'now-1h', to: 'now' }, + }), }); }