mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
plugin/template : add view label into plugin metrics (#5620)
Signed-off-by: Ondřej Benkovský <ondrej.benkovsky@jamf.com>
This commit is contained in:
@@ -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:
|
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_matches_total{server, zone, view, class, type}` 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_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, 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_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
|
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.
|
the server incrementing the metric, see the *metrics* plugin for details.
|
||||||
|
|||||||
@@ -14,19 +14,19 @@ var (
|
|||||||
Subsystem: "template",
|
Subsystem: "template",
|
||||||
Name: "matches_total",
|
Name: "matches_total",
|
||||||
Help: "Counter of template regex matches.",
|
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 is the counter of go template failures.
|
||||||
templateFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{
|
templateFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: plugin.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
Subsystem: "template",
|
Subsystem: "template",
|
||||||
Name: "template_failures_total",
|
Name: "template_failures_total",
|
||||||
Help: "Counter of go template failures.",
|
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 is the counter of mis-templated RRs.
|
||||||
templateRRFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{
|
templateRRFailureCount = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: plugin.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
Subsystem: "template",
|
Subsystem: "template",
|
||||||
Name: "rr_failures_total",
|
Name: "rr_failures_total",
|
||||||
Help: "Counter of mis-templated RRs.",
|
Help: "Counter of mis-templated RRs.",
|
||||||
}, []string{"server", "zone", "class", "type", "section", "template"})
|
}, []string{"server", "zone", "view", "class", "type", "section", "template"})
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ func (h Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
|||||||
continue
|
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 {
|
if template.rcode == dns.RcodeServerFailure {
|
||||||
return template.rcode, nil
|
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
|
msg.Rcode = template.rcode
|
||||||
|
|
||||||
for _, answer := range template.answer {
|
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 {
|
if err != nil {
|
||||||
return dns.RcodeServerFailure, err
|
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 {
|
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 {
|
if err != nil {
|
||||||
return dns.RcodeServerFailure, err
|
return dns.RcodeServerFailure, err
|
||||||
}
|
}
|
||||||
msg.Extra = append(msg.Extra, rr)
|
msg.Extra = append(msg.Extra, rr)
|
||||||
}
|
}
|
||||||
for _, authority := range template.authority {
|
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 {
|
if err != nil {
|
||||||
return dns.RcodeServerFailure, err
|
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.
|
// Name implements the plugin.Handler interface.
|
||||||
func (h Handler) Name() string { return "template" }
|
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{}
|
buffer := &bytes.Buffer{}
|
||||||
err := template.Execute(buffer, data)
|
err := template.Execute(buffer, data)
|
||||||
if err != nil {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
rr, err := dns.NewRR(buffer.String())
|
rr, err := dns.NewRR(buffer.String())
|
||||||
if err != nil {
|
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, err
|
||||||
}
|
}
|
||||||
return rr, nil
|
return rr, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user