diff options
author | 2022-09-15 15:36:49 +0200 | |
---|---|---|
committer | 2022-09-15 09:36:49 -0400 | |
commit | 51f021c079cfb21b355a6412917345c80eeaccad (patch) | |
tree | 976f2e2af5fd595626ab69abf52b36e13f232647 /plugin | |
parent | 4116a4ebdb0caae743cc9ebe0b462a0055c12754 (diff) | |
download | coredns-51f021c079cfb21b355a6412917345c80eeaccad.tar.gz coredns-51f021c079cfb21b355a6412917345c80eeaccad.tar.zst coredns-51f021c079cfb21b355a6412917345c80eeaccad.zip |
plugin/template : add view label into plugin metrics (#5620)
Signed-off-by: Ondřej Benkovský <ondrej.benkovsky@jamf.com>
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/template/README.md | 6 | ||||
-rw-r--r-- | plugin/template/metrics.go | 6 | ||||
-rw-r--r-- | plugin/template/template.go | 14 |
3 files changed, 13 insertions, 13 deletions
diff --git a/plugin/template/README.md b/plugin/template/README.md index ec37c7d26..55889f7bc 100644 --- a/plugin/template/README.md +++ b/plugin/template/README.md @@ -64,9 +64,9 @@ The output of the template must be a [RFC 1035](https://tools.ietf.org/html/rfc1 If monitoring is enabled (via the *prometheus* plugin) then the following metrics are exported: -* `coredns_template_matches_total{server, regex}` the total number of matched requests by regex. -* `coredns_template_template_failures_total{server, regex,section,template}` the number of times the Go templating failed. Regex, section and template label values can be used to map the error back to the config file. -* `coredns_template_rr_failures_total{server, regex,section,template}` the number of times the templated resource record was invalid and could not be parsed. Regex, section and template label values can be used to map the error back to the config file. +* `coredns_template_matches_total{server, zone, view, class, type}` the total number of matched requests by regex. +* `coredns_template_template_failures_total{server, zone, view, class, type, section, template}` the number of times the Go templating failed. Regex, section and template label values can be used to map the error back to the config file. +* `coredns_template_rr_failures_total{server, zone, view, class, type, section, template}` the number of times the templated resource record was invalid and could not be parsed. Regex, section and template label values can be used to map the error back to the config file. Both failure cases indicate a problem with the template configuration. The `server` label indicates the server incrementing the metric, see the *metrics* plugin for details. diff --git a/plugin/template/metrics.go b/plugin/template/metrics.go index b18cded78..6a6912a4f 100644 --- a/plugin/template/metrics.go +++ b/plugin/template/metrics.go @@ -14,19 +14,19 @@ var ( Subsystem: "template", Name: "matches_total", Help: "Counter of template regex matches.", - }, []string{"server", "zone", "class", "type"}) + }, []string{"server", "zone", "view", "class", "type"}) // templateFailureCount is the counter of go template failures. templateFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "template", Name: "template_failures_total", Help: "Counter of go template failures.", - }, []string{"server", "zone", "class", "type", "section", "template"}) + }, []string{"server", "zone", "view", "class", "type", "section", "template"}) // templateRRFailureCount is the counter of mis-templated RRs. templateRRFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "template", Name: "rr_failures_total", Help: "Counter of mis-templated RRs.", - }, []string{"server", "zone", "class", "type", "section", "template"}) + }, []string{"server", "zone", "view", "class", "type", "section", "template"}) ) diff --git a/plugin/template/template.go b/plugin/template/template.go index abeadf05d..7b6647109 100644 --- a/plugin/template/template.go +++ b/plugin/template/template.go @@ -86,7 +86,7 @@ func (h Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) continue } - templateMatchesCount.WithLabelValues(metrics.WithServer(ctx), data.Zone, data.Class, data.Type).Inc() + templateMatchesCount.WithLabelValues(metrics.WithServer(ctx), data.Zone, metrics.WithView(ctx), data.Class, data.Type).Inc() if template.rcode == dns.RcodeServerFailure { return template.rcode, nil @@ -98,7 +98,7 @@ func (h Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) msg.Rcode = template.rcode for _, answer := range template.answer { - rr, err := executeRRTemplate(metrics.WithServer(ctx), "answer", answer, data) + rr, err := executeRRTemplate(metrics.WithServer(ctx), metrics.WithView(ctx), "answer", answer, data) if err != nil { return dns.RcodeServerFailure, err } @@ -111,14 +111,14 @@ func (h Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) } } for _, additional := range template.additional { - rr, err := executeRRTemplate(metrics.WithServer(ctx), "additional", additional, data) + rr, err := executeRRTemplate(metrics.WithServer(ctx), metrics.WithView(ctx), "additional", additional, data) if err != nil { return dns.RcodeServerFailure, err } msg.Extra = append(msg.Extra, rr) } for _, authority := range template.authority { - rr, err := executeRRTemplate(metrics.WithServer(ctx), "authority", authority, data) + rr, err := executeRRTemplate(metrics.WithServer(ctx), metrics.WithView(ctx), "authority", authority, data) if err != nil { return dns.RcodeServerFailure, err } @@ -135,16 +135,16 @@ func (h Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) // Name implements the plugin.Handler interface. func (h Handler) Name() string { return "template" } -func executeRRTemplate(server, section string, template *gotmpl.Template, data *templateData) (dns.RR, error) { +func executeRRTemplate(server, view, section string, template *gotmpl.Template, data *templateData) (dns.RR, error) { buffer := &bytes.Buffer{} err := template.Execute(buffer, data) if err != nil { - templateFailureCount.WithLabelValues(server, data.Zone, data.Class, data.Type, section, template.Tree.Root.String()).Inc() + templateFailureCount.WithLabelValues(server, data.Zone, view, data.Class, data.Type, section, template.Tree.Root.String()).Inc() return nil, err } rr, err := dns.NewRR(buffer.String()) if err != nil { - templateRRFailureCount.WithLabelValues(server, data.Zone, data.Class, data.Type, section, template.Tree.Root.String()).Inc() + templateRRFailureCount.WithLabelValues(server, data.Zone, view, data.Class, data.Type, section, template.Tree.Root.String()).Inc() return rr, err } return rr, nil |