Remove explore compact URLs (#59686)

* Remove explore compact URLs

* Remove two explore link builders that create compact URLs

* Fix merge conflict
This commit is contained in:
Kristina 2022-12-14 12:57:53 -06:00 committed by GitHub
parent d3afe9e85c
commit 5a7f38053b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 14 deletions

View File

@ -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)
}

View File

@ -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\" }}",

View File

@ -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' },
}),
});
}

View File

@ -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' },
}),
});
}