mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 05:04:05 -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
eba205fcac
commit
f525ca5d9e
|
@ -200,9 +200,9 @@ func (rule *AlertingRule) HTMLSnippet() template.HTML {
|
||||||
}
|
}
|
||||||
return template.HTML(fmt.Sprintf(
|
return template.HTML(fmt.Sprintf(
|
||||||
`ALERT <a href="%s">%s</a> IF <a href="%s">%s</a> FOR %s WITH %s`,
|
`ALERT <a href="%s">%s</a> IF <a href="%s">%s</a> FOR %s WITH %s`,
|
||||||
ConsoleLinkForExpression(alertMetric.String()),
|
GraphLinkForExpression(alertMetric.String()),
|
||||||
rule.name,
|
rule.name,
|
||||||
ConsoleLinkForExpression(rule.Vector.String()),
|
GraphLinkForExpression(rule.Vector.String()),
|
||||||
rule.Vector,
|
rule.Vector,
|
||||||
utility.DurationToString(rule.holdDuration),
|
utility.DurationToString(rule.holdDuration),
|
||||||
rule.Labels))
|
rule.Labels))
|
||||||
|
|
|
@ -131,7 +131,7 @@ func newLabelMatcher(matchTypeStr string, name clientmodel.LabelName, value clie
|
||||||
return metric.NewLabelMatcher(matchType, name, value)
|
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
|
// url.QueryEscape percent-escapes everything except spaces, for which it
|
||||||
// uses "+". However, in the non-query part of a URI, only percent-escaped
|
// 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
|
// 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))
|
urlData := url.QueryEscape(fmt.Sprintf(`[{"expr":%q,"tab":1}]`, expr))
|
||||||
return fmt.Sprintf("/graph#%s", strings.Replace(urlData, "+", "%20", -1))
|
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,
|
Value: aa.Value,
|
||||||
ActiveSince: aa.ActiveSince.Time(),
|
ActiveSince: aa.ActiveSince.Time(),
|
||||||
RuleString: rule.String(),
|
RuleString: rule.String(),
|
||||||
GeneratorUrl: m.prometheusUrl + rules.ConsoleLinkForExpression(rule.Vector.String()),
|
GeneratorUrl: m.prometheusUrl + rules.GraphLinkForExpression(rule.Vector.String()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
m.notifications <- notifications
|
m.notifications <- notifications
|
||||||
|
|
|
@ -77,10 +77,10 @@ func (rule RecordingRule) HTMLSnippet() template.HTML {
|
||||||
ruleExpr := rule.vector.String()
|
ruleExpr := rule.vector.String()
|
||||||
return template.HTML(fmt.Sprintf(
|
return template.HTML(fmt.Sprintf(
|
||||||
`<a href="%s">%s</a>%s = <a href="%s">%s</a>`,
|
`<a href="%s">%s</a>%s = <a href="%s">%s</a>`,
|
||||||
ConsoleLinkForExpression(rule.name),
|
GraphLinkForExpression(rule.name),
|
||||||
rule.name,
|
rule.name,
|
||||||
rule.labels,
|
rule.labels,
|
||||||
ConsoleLinkForExpression(ruleExpr),
|
GraphLinkForExpression(ruleExpr),
|
||||||
ruleExpr))
|
ruleExpr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,8 +129,10 @@ func NewTemplateExpander(text string, name string, data interface{}, timestamp c
|
||||||
"safeHtml": func(text string) html_template.HTML {
|
"safeHtml": func(text string) html_template.HTML {
|
||||||
return html_template.HTML(text)
|
return html_template.HTML(text)
|
||||||
},
|
},
|
||||||
"match": regexp.MatchString,
|
"match": regexp.MatchString,
|
||||||
"title": strings.Title,
|
"title": strings.Title,
|
||||||
|
"graphLink": rules.GraphLinkForExpression,
|
||||||
|
"tableLink": rules.TableLinkForExpression,
|
||||||
"sortByLabel": func(label string, v queryResult) queryResult {
|
"sortByLabel": func(label string, v queryResult) queryResult {
|
||||||
sorter := queryResultByLabelSorter{v[:], label}
|
sorter := queryResultByLabelSorter{v[:], label}
|
||||||
sort.Stable(sorter)
|
sort.Stable(sorter)
|
||||||
|
|
|
@ -137,6 +137,16 @@ func TestTemplateExpansion(t *testing.T) {
|
||||||
text: "{{ match \"a+\" \"aa\" }} {{ match \"a+\" \"b\" }}",
|
text: "{{ match \"a+\" \"aa\" }} {{ match \"a+\" \"b\" }}",
|
||||||
output: "true false",
|
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)
|
time := clientmodel.Timestamp(0)
|
||||||
|
|
|
@ -553,7 +553,7 @@ function parseGraphOptionsFromUrl() {
|
||||||
return options;
|
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() {
|
function storeGraphOptionsInUrl() {
|
||||||
var allGraphsOptions = [];
|
var allGraphsOptions = [];
|
||||||
for (var i = 0; i < graphs.length; i++) {
|
for (var i = 0; i < graphs.length; i++) {
|
||||||
|
|
Loading…
Reference in a new issue