plugin/metrics: add 'server' label (#1682)
* plugin/metrics: add 'server' label This uses the new WithServer(ctx) to get the current server from the context. First in a larger refactor to make all plugins do this. * compile * compile * lala test * compile and test * typos * Dont duplicate the code
This commit is contained in:
parent
573ad62b77
commit
08443a9f00
10 changed files with 68 additions and 56 deletions
|
@ -1,7 +1,7 @@
|
|||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/metrics/vars"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
@ -15,10 +15,4 @@ import (
|
|||
// Basic usage with a metric:
|
||||
//
|
||||
// <metric>.WithLabelValues(metrics.WithServer(ctx), labels..).Add(1)
|
||||
func WithServer(ctx context.Context) string {
|
||||
srv := ctx.Value(plugin.ServerCtx{})
|
||||
if srv == nil {
|
||||
return ""
|
||||
}
|
||||
return srv.(string)
|
||||
}
|
||||
func WithServer(ctx context.Context) string { return vars.WithServer(ctx) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue