Align plugin/template usage and syntax with other plugins (#1360)

* Align plugin/template usage and syntax with other plugins

* Use new fallthrough logic in plugin/template

* Use zone name normalization for plugin/template

* Test fallthrough parsing in plugin/template

* Rework scoping of match checks

Most matches are not plugin global but per template. The plugin does only a
very rough check while detailed checks are done per-template.

Per template checks include:
- Zones
- Class/Type
- Regex
- Fallthrough

* Remove trailing `.` from fully qualified domain names

* Register template metrics with zone/class/type instead of regex

* Remove trailing fqdn dot from multiple testcases
This commit is contained in:
Rene Treffer
2018-01-09 22:30:58 +01:00
committed by Miek Gieben
parent a7590897fb
commit 0091e1c9dc
6 changed files with 412 additions and 134 deletions

View File

@@ -3,7 +3,10 @@ package template
import (
"sync"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/mholt/caddy"
"github.com/prometheus/client_golang/prometheus"
)
@@ -15,28 +18,38 @@ var (
Subsystem: "template",
Name: "matches_total",
Help: "Counter of template regex matches.",
}, []string{"regex"})
}, []string{"zone", "class", "type"})
TemplateFailureCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace,
Subsystem: "template",
Name: "template_failures_total",
Help: "Counter of go template failures.",
}, []string{"regex", "section", "template"})
}, []string{"zone", "class", "type", "section", "template"})
TemplateRRFailureCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace,
Subsystem: "template",
Name: "rr_failures_total",
Help: "Counter of mis-templated RRs.",
}, []string{"regex", "section", "template"})
}, []string{"zone", "class", "type", "section", "template"})
)
// OnStartupMetrics sets up the metrics on startup.
func OnStartupMetrics() error {
metricsOnce.Do(func() {
prometheus.MustRegister(TemplateMatchesCount)
prometheus.MustRegister(TemplateFailureCount)
prometheus.MustRegister(TemplateRRFailureCount)
func setupMetrics(c *caddy.Controller) error {
c.OnStartup(func() error {
metricsOnce.Do(func() {
m := dnsserver.GetConfig(c).Handler("prometheus")
if m == nil {
return
}
if x, ok := m.(*metrics.Metrics); ok {
x.MustRegister(TemplateMatchesCount)
x.MustRegister(TemplateFailureCount)
x.MustRegister(TemplateRRFailureCount)
}
})
return nil
})
return nil
}