mirror of
https://github.com/prometheus/prometheus
synced 2024-12-22 22:43:19 +00:00
add alert template expanding failure metric (#4747)
Signed-off-by: Mucahit Kurt <mucahitkurt@gmail.com>
This commit is contained in:
parent
c2f32c99cf
commit
4a6c329d71
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user