plugin/template : add view label into plugin metrics (#5620)

Signed-off-by: Ondřej Benkovský <ondrej.benkovsky@jamf.com>
This commit is contained in:
Ondřej Benkovský
2022-09-15 15:36:49 +02:00
committed by GitHub
parent 4116a4ebdb
commit 51f021c079
3 changed files with 13 additions and 13 deletions

View File

@@ -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.

View File

@@ -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"})
)

View File

@@ -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