From b371eb679dcf9dd14a5a819f80b3e3b624fdfe7f Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sat, 18 Jan 2020 08:39:02 +0100 Subject: [PATCH] Add metrics Signed-off-by: Miek Gieben --- plugin/traffic/README.md | 8 +++++++- plugin/traffic/setup.go | 2 ++ plugin/traffic/xds/client.go | 1 + plugin/traffic/xds/metrics.go | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 plugin/traffic/xds/metrics.go diff --git a/plugin/traffic/README.md b/plugin/traffic/README.md index e973a7968..968d43d2d 100644 --- a/plugin/traffic/README.md +++ b/plugin/traffic/README.md @@ -91,6 +91,13 @@ What metrics should we do? If any? Number of clusters? Number of endpoints and h This plugin report readiness to the ready plugin. This will happen after a gRPC stream has been established to the control plane. +## Metrics + +If monitoring is enabled (via the *prometheus* plugin) then the following metric are exported: + +* `coredns_traffic_clusters_tracked{}` the number of tracked clusters. + + ## Examples ~~~ @@ -123,7 +130,6 @@ is not implemented. ## TODO -* metrics? * credentials (other than TLS) - how/what? * is the protocol correctly implemented? Should we not have a 10s tick, but wait for responses from the control plane? diff --git a/plugin/traffic/setup.go b/plugin/traffic/setup.go index bfd9683a4..4557faa7e 100644 --- a/plugin/traffic/setup.go +++ b/plugin/traffic/setup.go @@ -9,6 +9,7 @@ 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/coredns/coredns/plugin/pkg/parse" pkgtls "github.com/coredns/coredns/plugin/pkg/tls" @@ -38,6 +39,7 @@ func setup(c *caddy.Controller) error { c.OnStartup(func() error { go t.c.Run() + metrics.MustRegister(c, xds.ClusterGauge) return nil }) c.OnShutdown(func() error { return t.c.Stop() }) diff --git a/plugin/traffic/xds/client.go b/plugin/traffic/xds/client.go index d70832de7..acb395a12 100644 --- a/plugin/traffic/xds/client.go +++ b/plugin/traffic/xds/client.go @@ -191,6 +191,7 @@ func (c *Client) receive(stream adsStream) error { a.SetClusterLoadAssignment(cluster.GetName(), nil) } log.Debugf("Cluster discovery processed with %d resources, version %q and nonce %q", len(resp.GetResources()), c.Version(cdsURL), c.Nonce(cdsURL)) + ClusterGauge.WithLabelValues().Set(float64(len(resp.GetResources()))) // set our local administration and ack the reply. Empty version would signal NACK. c.SetNonce(cdsURL, resp.GetNonce()) c.SetVersion(cdsURL, resp.GetVersionInfo()) diff --git a/plugin/traffic/xds/metrics.go b/plugin/traffic/xds/metrics.go new file mode 100644 index 000000000..0d9175497 --- /dev/null +++ b/plugin/traffic/xds/metrics.go @@ -0,0 +1,17 @@ +package xds + +import ( + "github.com/coredns/coredns/plugin" + + "github.com/prometheus/client_golang/prometheus" +) + +var ( + // ClusterGauge is the number of clusters we are currently tracking. + ClusterGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: plugin.Namespace, + Subsystem: "traffic", + Name: "clusters_tracked", + Help: "Gauge of tracked clusters.", + }, []string{""}) +)