mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-27 06:29:42 -08:00
Let consoles get graph links from experssions.
Rename ConsoleLinkFromExpression, as we now have consoles. Change-Id: I7ed2c9c83863adb390b51121dd9736845f7bcdfc
This commit is contained in:
parent
de71467758
commit
8be993b8f8
|
@ -200,9 +200,9 @@ func (rule *AlertingRule) HTMLSnippet() template.HTML {
|
|||
}
|
||||
return template.HTML(fmt.Sprintf(
|
||||
`ALERT <a href="%s">%s</a> IF <a href="%s">%s</a> 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))
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -77,10 +77,10 @@ func (rule RecordingRule) HTMLSnippet() template.HTML {
|
|||
ruleExpr := rule.vector.String()
|
||||
return template.HTML(fmt.Sprintf(
|
||||
`<a href="%s">%s</a>%s = <a href="%s">%s</a>`,
|
||||
ConsoleLinkForExpression(rule.name),
|
||||
GraphLinkForExpression(rule.name),
|
||||
rule.name,
|
||||
rule.labels,
|
||||
ConsoleLinkForExpression(ruleExpr),
|
||||
GraphLinkForExpression(ruleExpr),
|
||||
ruleExpr))
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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++) {
|
||||
|
|
Loading…
Reference in a new issue