From 3e914a8cb1054a499a282201f3da1770211c70cf Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Tue, 19 May 2015 02:44:40 +0900 Subject: [PATCH] fix graph links with path prefix --- console_libraries/prom.lib | 2 +- rules/alerting.go | 7 ++++--- rules/recording.go | 7 ++++--- rules/rules.go | 2 +- web/templates/alerts.html | 2 +- web/templates/status.html | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/console_libraries/prom.lib b/console_libraries/prom.lib index f80ea58b7..72ea238e5 100644 --- a/console_libraries/prom.lib +++ b/console_libraries/prom.lib @@ -40,7 +40,7 @@ renderTemplate is the name of the template to use to render the value. */}} {{ define "prom_query_drilldown" }} {{ $expr := .arg0 }}{{ $suffix := (or .arg1 "") }}{{ $renderTemplate := (or .arg2 "__prom_query_drilldown_noop") }} -{{ with query $expr }}{{tmpl $renderTemplate ( . | first | value )}}{{ $suffix }}{{ else }}-{{ end }} +{{ with query $expr }}{{tmpl $renderTemplate ( . | first | value )}}{{ $suffix }}{{ else }}-{{ end }} {{ end }} {{ define "prom_path" }}/consoles/{{ .Path }}?{{ range $param, $value := .Params }}{{ $param }}={{ $value }}&{{ end }}{{ end }}" diff --git a/rules/alerting.go b/rules/alerting.go index 8a558aeca..65cfab407 100644 --- a/rules/alerting.go +++ b/rules/alerting.go @@ -17,6 +17,7 @@ import ( "fmt" "html/template" "reflect" + "strings" "sync" "time" @@ -213,16 +214,16 @@ func (rule *AlertingRule) String() string { } // HTMLSnippet returns an HTML snippet representing this alerting rule. -func (rule *AlertingRule) HTMLSnippet() template.HTML { +func (rule *AlertingRule) HTMLSnippet(pathPrefix string) template.HTML { alertMetric := clientmodel.Metric{ clientmodel.MetricNameLabel: AlertMetricName, AlertNameLabel: clientmodel.LabelValue(rule.name), } return template.HTML(fmt.Sprintf( `ALERT %s IF %s FOR %s WITH %s`, - utility.GraphLinkForExpression(alertMetric.String()), + pathPrefix+strings.TrimLeft(utility.GraphLinkForExpression(alertMetric.String()), "/"), rule.name, - utility.GraphLinkForExpression(rule.Vector.String()), + pathPrefix+strings.TrimLeft(utility.GraphLinkForExpression(rule.Vector.String()), "/"), rule.Vector, utility.DurationToString(rule.holdDuration), rule.Labels)) diff --git a/rules/recording.go b/rules/recording.go index 2402fa84f..d9d2b0028 100644 --- a/rules/recording.go +++ b/rules/recording.go @@ -17,6 +17,7 @@ import ( "fmt" "html/template" "reflect" + "strings" clientmodel "github.com/prometheus/client_golang/model" @@ -85,13 +86,13 @@ func (rule RecordingRule) String() string { } // HTMLSnippet returns an HTML snippet representing this rule. -func (rule RecordingRule) HTMLSnippet() template.HTML { +func (rule RecordingRule) HTMLSnippet(pathPrefix string) template.HTML { ruleExpr := rule.vector.String() return template.HTML(fmt.Sprintf( `%s%s = %s`, - utility.GraphLinkForExpression(rule.name), + pathPrefix+strings.TrimLeft(utility.GraphLinkForExpression(rule.name), "/"), rule.name, rule.labels, - utility.GraphLinkForExpression(ruleExpr), + pathPrefix+strings.TrimLeft(utility.GraphLinkForExpression(ruleExpr), "/"), ruleExpr)) } diff --git a/rules/rules.go b/rules/rules.go index 9485bc533..2af1d5c61 100644 --- a/rules/rules.go +++ b/rules/rules.go @@ -37,5 +37,5 @@ type Rule interface { String() string // HTMLSnippet returns a human-readable string representation of the rule, // decorated with HTML elements for use the web frontend. - HTMLSnippet() template.HTML + HTMLSnippet(pathPrefix string) template.HTML } diff --git a/web/templates/alerts.html b/web/templates/alerts.html index 903ef7cd0..202b67c1c 100644 --- a/web/templates/alerts.html +++ b/web/templates/alerts.html @@ -17,7 +17,7 @@
- {{.HTMLSnippet}} + {{.HTMLSnippet pathPrefix}} Silence All Children…
{{if $activeAlerts}} diff --git a/web/templates/status.html b/web/templates/status.html index 91332c601..b7de91bf2 100644 --- a/web/templates/status.html +++ b/web/templates/status.html @@ -28,7 +28,7 @@
{{.Config}}

Rules

-
{{range .RuleManager.Rules}}{{.HTMLSnippet}}
{{end}}
+
{{range .RuleManager.Rules}}{{.HTMLSnippet pathPrefix}}
{{end}}

Targets