From f7ed1accfcacf024cdfc0e83d521adf310986810 Mon Sep 17 00:00:00 2001 From: pegasko Date: Sun, 29 Oct 2023 20:19:35 +0300 Subject: [PATCH] boba --- dnsstat.go | 13 ++++++++++++- metrics.go | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/dnsstat.go b/dnsstat.go index 6fdf238..4b888cf 100644 --- a/dnsstat.go +++ b/dnsstat.go @@ -7,10 +7,15 @@ import ( "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin/metrics" + clog "github.com/coredns/coredns/plugin/pkg/log" "github.com/miekg/dns" ) +// Define log to be a logger with the plugin name in it. This way we can just use log.Info and +// friends to log. +var log = clog.NewWithPlugin("dnsstat") + // Dump implement the plugin interface. type DNSStat struct { Next plugin.Handler @@ -35,9 +40,15 @@ func setup(c *caddy.Controller) error { // ServeDNS implements the plugin.Handler interface. func (d DNSStat) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { + // Debug log that we've have seen the query. This will only be shown when the debug plugin is loaded. + log.Error("Received response") + + // Wrap. + pw := NewResponsePrinter(w) + // Metric increment requestCount.WithLabelValues(metrics.WithServer(ctx)).Inc() - return plugin.NextOrFailure(d.Name(), d.Next, ctx, w, r) + return plugin.NextOrFailure(d.Name(), d.Next, ctx, pw, r) } // Name implements the Handler interface. diff --git a/metrics.go b/metrics.go index 28ec98e..316f164 100644 --- a/metrics.go +++ b/metrics.go @@ -13,7 +13,7 @@ import ( var requestCount = promauto.NewCounterVec(prometheus.CounterOpts{ Namespace: plugin.Namespace, Subsystem: "dnsstat", - Name: "request_count_total", + Name: "dnsstat_request_count_total", Help: "Counter of requests made.", }, []string{"server"})