From c5bacf4d9526edea484053e884a959f71a5d39d2 Mon Sep 17 00:00:00 2001 From: Chung-Ting Huang Date: Mon, 18 Nov 2019 18:46:51 -0600 Subject: [PATCH] TUN-2563: Exposes config_version metrics --- supervisor/supervisor.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/supervisor/supervisor.go b/supervisor/supervisor.go index 28b32092..7ae111df 100644 --- a/supervisor/supervisor.go +++ b/supervisor/supervisor.go @@ -16,6 +16,7 @@ import ( "github.com/cloudflare/cloudflared/h2mux" "github.com/cloudflare/cloudflared/streamhandler" "github.com/cloudflare/cloudflared/tunnelrpc/pogs" + "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" ) @@ -28,6 +29,27 @@ type Supervisor struct { useConfigResultChan chan<- *pogs.UseConfigurationResult state *state logger *logrus.Entry + metrics metrics +} + +type metrics struct { + configVersion prometheus.Gauge +} + +func newMetrics() metrics { + configVersion := prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: "supervisor", + Subsystem: "supervisor", + Name: "config_version", + Help: "Latest configuration version received from Cloudflare", + }, + ) + prometheus.MustRegister( + configVersion, + ) + return metrics{ + configVersion: configVersion, + } } func NewSupervisor( @@ -70,6 +92,7 @@ func NewSupervisor( useConfigResultChan: useConfigResultChan, state: newState(defaultClientConfig), logger: logger.WithField("subsystem", "supervisor"), + metrics: newMetrics(), }, nil } @@ -131,6 +154,7 @@ func (s *Supervisor) notifySubsystemsNewConfig(newConfig *pogs.ClientConfig) *po Success: true, } } + s.metrics.configVersion.Set(float64(newConfig.Version)) s.state.updateConfig(newConfig) var tunnelHostnames []h2mux.TunnelHostname