comment updates

This commit is contained in:
Miek Gieben 2018-04-26 21:56:11 +01:00
parent 2ba108890d
commit 7f0d44144d
2 changed files with 6 additions and 7 deletions

View File

@ -16,6 +16,8 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
) )
// 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("example") var log = clog.NewWithPlugin("example")
// Example is an example plugin to show how to write a plugin. // Example is an example plugin to show how to write a plugin.
@ -38,7 +40,7 @@ func (e Example) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
pw := NewResponsePrinter(w) pw := NewResponsePrinter(w)
// Export metric with the server label set to the current server handling the request. // Export metric with the server label set to the current server handling the request.
requestCount.WithLabelValues(metrics.WithServer(ctx)).Add(1) requestCount.WithLabelValues(metrics.WithServer(ctx)).Inc()
// Call next plugin (if any). // Call next plugin (if any).
return plugin.NextOrFailure(e.Name(), e.Next, ctx, pw, r) return plugin.NextOrFailure(e.Name(), e.Next, ctx, pw, r)
@ -47,8 +49,7 @@ func (e Example) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
// Name implements the Handler interface. // Name implements the Handler interface.
func (e Example) Name() string { return "example" } func (e Example) Name() string { return "example" }
// ResponsePrinter wrap a dns.ResponseWriter and will write example to standard output when // ResponsePrinter wrap a dns.ResponseWriter and will write example to standard output when WriteMsg is called.
// WriteMsg is called.
type ResponsePrinter struct { type ResponsePrinter struct {
dns.ResponseWriter dns.ResponseWriter
} }
@ -58,8 +59,7 @@ func NewResponsePrinter(w dns.ResponseWriter) *ResponsePrinter {
return &ResponsePrinter{ResponseWriter: w} return &ResponsePrinter{ResponseWriter: w}
} }
// WriteMsg calls the underlying ResponseWriter's WriteMsg method and prints "example" to standard // WriteMsg calls the underlying ResponseWriter's WriteMsg method and prints "example" to standard output.
// output.
func (r *ResponsePrinter) WriteMsg(res *dns.Msg) error { func (r *ResponsePrinter) WriteMsg(res *dns.Msg) error {
fmt.Fprintln(out, ex) fmt.Fprintln(out, ex)
return r.ResponseWriter.WriteMsg(res) return r.ResponseWriter.WriteMsg(res)

View File

@ -8,8 +8,7 @@ import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
) )
// requestCount exports a prometheus metric that is incremented every time // requestCount exports a prometheus metric that is incremented every time a query is seen by the example plugin.
// a query is seen by the example plugin.
var requestCount = prometheus.NewCounterVec(prometheus.CounterOpts{ var requestCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: plugin.Namespace, Namespace: plugin.Namespace,
Subsystem: "example", Subsystem: "example",