diff --git a/rules/alerting.go b/rules/alerting.go index e43867e82..1872c948b 100644 --- a/rules/alerting.go +++ b/rules/alerting.go @@ -200,9 +200,9 @@ func (rule *AlertingRule) HTMLSnippet() template.HTML { } return template.HTML(fmt.Sprintf( `ALERT %s IF %s FOR %s WITH %s`, - ConsoleLinkForExpression(alertMetric.String()), + GraphLinkForExpression(alertMetric.String()), rule.name, - ConsoleLinkForExpression(rule.Vector.String()), + GraphLinkForExpression(rule.Vector.String()), rule.Vector, utility.DurationToString(rule.holdDuration), rule.Labels)) diff --git a/rules/helpers.go b/rules/helpers.go index b883e4b19..0f9ffe4bb 100644 --- a/rules/helpers.go +++ b/rules/helpers.go @@ -131,7 +131,7 @@ func newLabelMatcher(matchTypeStr string, name clientmodel.LabelName, value clie return metric.NewLabelMatcher(matchType, name, value) } -func ConsoleLinkForExpression(expr string) string { +func TableLinkForExpression(expr string) string { // url.QueryEscape percent-escapes everything except spaces, for which it // uses "+". However, in the non-query part of a URI, only percent-escaped // spaces are legal, so we need to manually replace "+" with "%20" after @@ -142,3 +142,8 @@ func ConsoleLinkForExpression(expr string) string { urlData := url.QueryEscape(fmt.Sprintf(`[{"expr":%q,"tab":1}]`, expr)) return fmt.Sprintf("/graph#%s", strings.Replace(urlData, "+", "%20", -1)) } + +func GraphLinkForExpression(expr string) string { + urlData := url.QueryEscape(fmt.Sprintf(`[{"expr":%q}]`, expr)) + return fmt.Sprintf("/graph#%s", strings.Replace(urlData, "+", "%20", -1)) +} diff --git a/rules/manager/manager.go b/rules/manager/manager.go index ae3d29e43..b69546d8a 100644 --- a/rules/manager/manager.go +++ b/rules/manager/manager.go @@ -187,7 +187,7 @@ func (m *ruleManager) queueAlertNotifications(rule *rules.AlertingRule, timestam Value: aa.Value, ActiveSince: aa.ActiveSince.Time(), RuleString: rule.String(), - GeneratorUrl: m.prometheusUrl + rules.ConsoleLinkForExpression(rule.Vector.String()), + GeneratorUrl: m.prometheusUrl + rules.GraphLinkForExpression(rule.Vector.String()), }) } m.notifications <- notifications diff --git a/rules/recording.go b/rules/recording.go index 881407a29..9f5695892 100644 --- a/rules/recording.go +++ b/rules/recording.go @@ -77,10 +77,10 @@ func (rule RecordingRule) HTMLSnippet() template.HTML { ruleExpr := rule.vector.String() return template.HTML(fmt.Sprintf( `%s%s = %s`, - ConsoleLinkForExpression(rule.name), + GraphLinkForExpression(rule.name), rule.name, rule.labels, - ConsoleLinkForExpression(ruleExpr), + GraphLinkForExpression(ruleExpr), ruleExpr)) } diff --git a/templates/templates.go b/templates/templates.go index 2a1f11e3a..167554c15 100644 --- a/templates/templates.go +++ b/templates/templates.go @@ -129,8 +129,10 @@ func NewTemplateExpander(text string, name string, data interface{}, timestamp c "safeHtml": func(text string) html_template.HTML { return html_template.HTML(text) }, - "match": regexp.MatchString, - "title": strings.Title, + "match": regexp.MatchString, + "title": strings.Title, + "graphLink": rules.GraphLinkForExpression, + "tableLink": rules.TableLinkForExpression, "sortByLabel": func(label string, v queryResult) queryResult { sorter := queryResultByLabelSorter{v[:], label} sort.Stable(sorter) diff --git a/templates/templates_test.go b/templates/templates_test.go index 08917acd7..23e9babb3 100644 --- a/templates/templates_test.go +++ b/templates/templates_test.go @@ -137,6 +137,16 @@ func TestTemplateExpansion(t *testing.T) { text: "{{ match \"a+\" \"aa\" }} {{ match \"a+\" \"b\" }}", output: "true false", }, + { + // graphLink. + text: "{{ graphLink \"up\" }}", + output: "/graph#%5B%7B%22expr%22%3A%22up%22%7D%5D", + }, + { + // tableLink. + text: "{{ tableLink \"up\" }}", + output: "/graph#%5B%7B%22expr%22%3A%22up%22%2C%22tab%22%3A1%7D%5D", + }, } time := clientmodel.Timestamp(0) diff --git a/web/static/js/graph.js b/web/static/js/graph.js index 81463d1d7..4d68620c4 100644 --- a/web/static/js/graph.js +++ b/web/static/js/graph.js @@ -553,7 +553,7 @@ function parseGraphOptionsFromUrl() { return options; } -// NOTE: This needs to be kept in sync with rules/helpers.go:ConsoleLinkForExpression! +// NOTE: This needs to be kept in sync with rules/helpers.go:GraphLinkForExpression! function storeGraphOptionsInUrl() { var allGraphsOptions = []; for (var i = 0; i < graphs.length; i++) {