From e31ff3a70f6b201aa51901373ae4a5ac17ba2b51 Mon Sep 17 00:00:00 2001 From: Adam Chalmers Date: Tue, 28 Jan 2020 10:43:37 -0600 Subject: [PATCH] TUN-2693: Metrics for ReconnectTunnel --- origin/metrics.go | 10 ++++++---- origin/tunnel.go | 25 ++++++++++++++++--------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/origin/metrics.go b/origin/metrics.go index 6ce6e799..928cafb6 100644 --- a/origin/metrics.go +++ b/origin/metrics.go @@ -58,7 +58,7 @@ type TunnelMetrics struct { // oldServerLocations stores the last server the tunnel was connected to oldServerLocations map[string]string - regSuccess prometheus.Counter + regSuccess *prometheus.CounterVec regFail *prometheus.CounterVec rpcFail *prometheus.CounterVec @@ -428,7 +428,7 @@ func NewTunnelMetrics() *TunnelMetrics { Name: "tunnel_register_fail", Help: "Count of tunnel registration errors by type", }, - []string{"error"}, + []string{"error", "rpcName"}, ) prometheus.MustRegister(registerFail) @@ -443,13 +443,15 @@ func NewTunnelMetrics() *TunnelMetrics { ) prometheus.MustRegister(userHostnamesCounts) - registerSuccess := prometheus.NewCounter( + registerSuccess := prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: metricsNamespace, Subsystem: tunnelSubsystem, Name: "tunnel_register_success", Help: "Count of successful tunnel registrations", - }) + }, + []string{"rpcName"}, + ) prometheus.MustRegister(registerSuccess) return &TunnelMetrics{ diff --git a/origin/tunnel.go b/origin/tunnel.go index cc5716ef..402e1239 100644 --- a/origin/tunnel.go +++ b/origin/tunnel.go @@ -40,6 +40,13 @@ const ( DuplicateConnectionError = "EDUPCONN" ) +type registerRPCName string + +const ( + register registerRPCName = "register" + reconnect registerRPCName = "reconnect" +) + type TunnelConfig struct { BuildInfo *buildinfo.BuildInfo ClientID string @@ -364,10 +371,10 @@ func RegisterTunnel( ) if registrationErr := registration.DeserializeError(); registrationErr != nil { // RegisterTunnel RPC failure - return processRegisterTunnelError(registrationErr, config.Metrics) + return processRegisterTunnelError(registrationErr, config.Metrics, register) } credentialManager.SetEventDigest(registration.EventDigest) - return processRegistrationSuccess(config, logger, connectionID, registration) + return processRegistrationSuccess(config, logger, connectionID, registration, register) } func ReconnectTunnel( @@ -402,12 +409,12 @@ func ReconnectTunnel( ) if registrationErr := registration.DeserializeError(); registrationErr != nil { // ReconnectTunnel RPC failure - return processRegisterTunnelError(registrationErr, config.Metrics) + return processRegisterTunnelError(registrationErr, config.Metrics, reconnect) } - return processRegistrationSuccess(config, logger, connectionID, registration) + return processRegistrationSuccess(config, logger, connectionID, registration, reconnect) } -func processRegistrationSuccess(config *TunnelConfig, logger *log.Entry, connectionID uint8, registration *tunnelpogs.TunnelRegistration) error { +func processRegistrationSuccess(config *TunnelConfig, logger *log.Entry, connectionID uint8, registration *tunnelpogs.TunnelRegistration, name registerRPCName) error { for _, logLine := range registration.LogLines { logger.Info(logLine) } @@ -432,16 +439,16 @@ func processRegistrationSuccess(config *TunnelConfig, logger *log.Entry, connect config.Metrics.userHostnamesCounts.WithLabelValues(registration.Url).Inc() logger.Infof("Route propagating, it may take up to 1 minute for your new route to become functional") - config.Metrics.regSuccess.Inc() + config.Metrics.regSuccess.WithLabelValues(string(name)).Inc() return nil } -func processRegisterTunnelError(err tunnelpogs.TunnelRegistrationError, metrics *TunnelMetrics) error { +func processRegisterTunnelError(err tunnelpogs.TunnelRegistrationError, metrics *TunnelMetrics, name registerRPCName) error { if err.Error() == DuplicateConnectionError { - metrics.regFail.WithLabelValues("dup_edge_conn").Inc() + metrics.regFail.WithLabelValues("dup_edge_conn", string(name)).Inc() return dupConnRegisterTunnelError{} } - metrics.regFail.WithLabelValues("server_error").Inc() + metrics.regFail.WithLabelValues("server_error", string(name)).Inc() return serverRegisterTunnelError{ cause: fmt.Errorf("Server error: %s", err.Error()), permanent: err.IsPermanent(),