diff options
-rw-r--r-- | plugin/autopath/README.md | 10 | ||||
-rw-r--r-- | plugin/autopath/autopath.go | 6 | ||||
-rw-r--r-- | plugin/autopath/metrics.go | 29 | ||||
-rw-r--r-- | plugin/autopath/setup.go | 2 |
4 files changed, 41 insertions, 6 deletions
diff --git a/plugin/autopath/README.md b/plugin/autopath/README.md index a1a87981c..53e47b31f 100644 --- a/plugin/autopath/README.md +++ b/plugin/autopath/README.md @@ -24,6 +24,12 @@ Currently the following set of plugin has implemented *autopath*: * *kubernetes* * *erratic* +## Metrics + +If monitoring is enabled (via the *prometheus* directive) then the following metric is exported: + +* `coredns_autopath_success_count_total{}` - counter of successfully autopath-ed queries. + ## Examples ~~~ @@ -41,5 +47,5 @@ Use the search path dynamically retrieved from the kubernetes plugin. ## Bugs -When the *cache* plugin is enabled it is possible for pods in different namespaces to get the -same answer. +Replies from this plugin are not cached, as the *cache* plugin is configured after this one (see +plugin.cfg). diff --git a/plugin/autopath/autopath.go b/plugin/autopath/autopath.go index aa3d44e6a..2ca6c4df8 100644 --- a/plugin/autopath/autopath.go +++ b/plugin/autopath/autopath.go @@ -32,8 +32,6 @@ func (m Plugins ) AutoPath(state request.Request) []string { package autopath import ( - "log" - "github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin/pkg/dnsutil" "github.com/coredns/coredns/plugin/pkg/nonwriter" @@ -76,7 +74,6 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms } if len(searchpath) == 0 { - log.Printf("[WARNING] No search path available for autopath") return plugin.NextOrFailure(a.Name(), a.Next, ctx, w, r) } @@ -87,7 +84,7 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms origQName := state.QName() // Establish base name of the query. I.e what was originally asked. - base, err := dnsutil.TrimZone(state.QName(), searchpath[0]) // TODO(miek): we loose the original case of the query here. + base, err := dnsutil.TrimZone(state.QName(), searchpath[0]) if err != nil { return dns.RcodeServerFailure, err } @@ -128,6 +125,7 @@ func (a *AutoPath) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Ms // Write whatever non-nxdomain answer we've found. w.WriteMsg(msg) + AutoPathCount.WithLabelValues().Add(1) return rcode, err } diff --git a/plugin/autopath/metrics.go b/plugin/autopath/metrics.go new file mode 100644 index 000000000..3901fde3a --- /dev/null +++ b/plugin/autopath/metrics.go @@ -0,0 +1,29 @@ +package autopath + +import ( + "sync" + + "github.com/coredns/coredns/plugin" + + "github.com/prometheus/client_golang/prometheus" +) + +// Metrics for autopath. +var ( + AutoPathCount = prometheus.NewCounterVec(prometheus.CounterOpts{ + Namespace: plugin.Namespace, + Subsystem: "autopath", + Name: "success_count_total", + Help: "Counter of requests that did autopath.", + }, []string{}) +) + +// OnStartupMetrics sets up the metrics on startup. +func OnStartupMetrics() error { + metricsOnce.Do(func() { + prometheus.MustRegister(AutoPathCount) + }) + return nil +} + +var metricsOnce sync.Once diff --git a/plugin/autopath/setup.go b/plugin/autopath/setup.go index c5a39a870..42b4b317a 100644 --- a/plugin/autopath/setup.go +++ b/plugin/autopath/setup.go @@ -26,6 +26,8 @@ func setup(c *caddy.Controller) error { return plugin.Error("autopath", err) } + c.OnStartup(OnStartupMetrics) + // Do this in OnStartup, so all plugin has been initialized. c.OnStartup(func() error { m := dnsserver.GetConfig(c).Handler(mw) |