From 4a6c329d7169dae547af2d6c3651a071a907299b Mon Sep 17 00:00:00 2001 From: Mucahit Kurt Date: Tue, 6 Nov 2018 17:39:06 +0300 Subject: [PATCH] add alert template expanding failure metric (#4747) Signed-off-by: Mucahit Kurt --- template/template.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/template/template.go b/template/template.go index f25fe67db..7ae230063 100644 --- a/template/template.go +++ b/template/template.go @@ -30,10 +30,27 @@ import ( "github.com/prometheus/common/model" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/util/strutil" ) +var ( + templateTextExpansionFailures = prometheus.NewCounter(prometheus.CounterOpts{ + Name: "prometheus_template_text_expansion_failures_total", + Help: "The total number of template text expansion failures.", + }) + templateTextExpansionTotal = prometheus.NewCounter(prometheus.CounterOpts{ + Name: "prometheus_template_text_expansions_total", + Help: "The total number of template text expansions.", + }) +) + +func init() { + prometheus.MustRegister(templateTextExpansionFailures) + prometheus.MustRegister(templateTextExpansionTotal) +} + // A version of vector that's easier to use from templates. type sample struct { Labels map[string]string @@ -274,8 +291,13 @@ func (te Expander) Expand() (result string, resultErr error) { resultErr = fmt.Errorf("panic expanding template %v: %v", te.name, r) } } + if resultErr != nil { + templateTextExpansionFailures.Inc() + } }() + templateTextExpansionTotal.Inc() + tmpl, err := text_template.New(te.name).Funcs(te.funcMap).Option("missingkey=zero").Parse(te.text) if err != nil { return "", fmt.Errorf("error parsing template %v: %v", te.name, err)