diff options
author | 2018-04-01 13:57:03 +0100 | |
---|---|---|
committer | 2018-04-01 13:57:03 +0100 | |
commit | 4df416ca1da2fff396ff84805518aa8f8b55b80b (patch) | |
tree | 2ed84dce69a0a6565505aa1ad9dab5d8f4c58a75 /plugin/plugin.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 'plugin/plugin.go')
-rw-r--r-- | plugin/plugin.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/plugin/plugin.go b/plugin/plugin.go index 2510dbaa6..b3d5cc6ab 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -68,8 +68,7 @@ func (f HandlerFunc) Name() string { return "handlerfunc" } // Error returns err with 'plugin/name: ' prefixed to it. func Error(name string, err error) error { return fmt.Errorf("%s/%s: %s", "plugin", name, err) } -// NextOrFailure calls next.ServeDNS when next is not nill, otherwise it will return, a ServerFailure -// and a nil error. +// NextOrFailure calls next.ServeDNS when next is not nill, otherwise it will return, a ServerFailure and a nil error. func NextOrFailure(name string, next Handler, ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { // nolint: golint if next != nil { if span := ot.SpanFromContext(ctx); span != nil { @@ -107,3 +106,6 @@ var TimeBuckets = prometheus.ExponentialBuckets(0.00025, 2, 16) // from 0.25ms t // ErrOnce is returned when a plugin doesn't support multiple setups per server. var ErrOnce = errors.New("this plugin can only be used once per Server Block") + +// ServerCtx is the context key to pass server address context to the plugins handling the request. +type ServerCtx struct{} |