diff options
author | 2018-04-01 13:57:03 +0100 | |
---|---|---|
committer | 2018-04-01 13:57:03 +0100 | |
commit | 4df416ca1da2fff396ff84805518aa8f8b55b80b (patch) | |
tree | 2ed84dce69a0a6565505aa1ad9dab5d8f4c58a75 /core/dnsserver/server.go | |
parent | 5c5a98ee292e68cf59faf66f601fdcb169ea7eed (diff) | |
download | coredns-4df416ca1da2fff396ff84805518aa8f8b55b80b.tar.gz coredns-4df416ca1da2fff396ff84805518aa8f8b55b80b.tar.zst coredns-4df416ca1da2fff396ff84805518aa8f8b55b80b.zip |
Metrics (#1579)
* plugin/metrics: set server address in context
Allow cross server block metrics to co-exist; for this we should label
each metric with the server label. Put this information in the context
and provide a helper function to get it out.
Abstracting with entirely away with difficult as the release client_go
(0.8.0) doesn't have the CurryWith functions yet. So current use is like
so:
define metric, with server label:
RcodeCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace,
Subsystem: "forward",
Name: "response_rcode_count_total",
Help: "Counter of requests made per upstream.",
}, []string{"server", "rcode", "to"})
And report ith with the helper function metrics.WithServer:
RcodeCount.WithLabelValues(metrics.WithServer(ctx), rc, p.addr).Add(1)
Diffstat (limited to 'core/dnsserver/server.go')
-rw-r--r-- | core/dnsserver/server.go | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/core/dnsserver/server.go b/core/dnsserver/server.go index 2fa67be05..dbc7bd5ce 100644 --- a/core/dnsserver/server.go +++ b/core/dnsserver/server.go @@ -245,6 +245,11 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) } if h, ok := s.zones[string(b[:l])]; ok { + + // Set server's address in the context so plugins can reference back to this, + // This will makes those metrics unique. + ctx = context.WithValue(ctx, plugin.ServerCtx{}, s.Addr) + if r.Question[0].Qtype != dns.TypeDS { if h.FilterFunc == nil { rcode, _ := h.pluginChain.ServeDNS(ctx, w, r) @@ -287,6 +292,10 @@ func (s *Server) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) // Wildcard match, if we have found nothing try the root zone as a last resort. if h, ok := s.zones["."]; ok && h.pluginChain != nil { + + // See comment above. + ctx = context.WithValue(ctx, plugin.ServerCtx{}, s.Addr) + rcode, _ := h.pluginChain.ServeDNS(ctx, w, r) if !plugin.ClientWrite(rcode) { DefaultErrorFunc(w, r, rcode) @@ -359,11 +368,11 @@ const ( maxreentries = 10 ) -// Key is the context key for the current server -type Key struct{} - -// loopKey is the context key for counting self loops -type loopKey struct{} +type ( + // Key is the context key for the current server + Key struct{} + loopKey struct{} // loopKey is the context key for counting self loops +) // enableChaos is a map with plugin names for which we should open CH class queries as // we block these by default. |