add alert template expanding failure metric (#4747)

Signed-off-by: Mucahit Kurt <mucahitkurt@gmail.com>
pull/4829/head
Mucahit Kurt 6 years ago committed by Brian Brazil
parent c2f32c99cf
commit 4a6c329d71

@ -30,10 +30,27 @@ import (
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/prometheus/promql" "github.com/prometheus/prometheus/promql"
"github.com/prometheus/prometheus/util/strutil" "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. // A version of vector that's easier to use from templates.
type sample struct { type sample struct {
Labels map[string]string 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) 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) tmpl, err := text_template.New(te.name).Funcs(te.funcMap).Option("missingkey=zero").Parse(te.text)
if err != nil { if err != nil {
return "", fmt.Errorf("error parsing template %v: %v", te.name, err) return "", fmt.Errorf("error parsing template %v: %v", te.name, err)

Loading…
Cancel
Save