TUN-2693: Metrics for ReconnectTunnel
This commit is contained in:
parent
dfe61fda88
commit
e31ff3a70f
|
@ -58,7 +58,7 @@ type TunnelMetrics struct {
|
||||||
// oldServerLocations stores the last server the tunnel was connected to
|
// oldServerLocations stores the last server the tunnel was connected to
|
||||||
oldServerLocations map[string]string
|
oldServerLocations map[string]string
|
||||||
|
|
||||||
regSuccess prometheus.Counter
|
regSuccess *prometheus.CounterVec
|
||||||
regFail *prometheus.CounterVec
|
regFail *prometheus.CounterVec
|
||||||
rpcFail *prometheus.CounterVec
|
rpcFail *prometheus.CounterVec
|
||||||
|
|
||||||
|
@ -428,7 +428,7 @@ func NewTunnelMetrics() *TunnelMetrics {
|
||||||
Name: "tunnel_register_fail",
|
Name: "tunnel_register_fail",
|
||||||
Help: "Count of tunnel registration errors by type",
|
Help: "Count of tunnel registration errors by type",
|
||||||
},
|
},
|
||||||
[]string{"error"},
|
[]string{"error", "rpcName"},
|
||||||
)
|
)
|
||||||
prometheus.MustRegister(registerFail)
|
prometheus.MustRegister(registerFail)
|
||||||
|
|
||||||
|
@ -443,13 +443,15 @@ func NewTunnelMetrics() *TunnelMetrics {
|
||||||
)
|
)
|
||||||
prometheus.MustRegister(userHostnamesCounts)
|
prometheus.MustRegister(userHostnamesCounts)
|
||||||
|
|
||||||
registerSuccess := prometheus.NewCounter(
|
registerSuccess := prometheus.NewCounterVec(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Namespace: metricsNamespace,
|
Namespace: metricsNamespace,
|
||||||
Subsystem: tunnelSubsystem,
|
Subsystem: tunnelSubsystem,
|
||||||
Name: "tunnel_register_success",
|
Name: "tunnel_register_success",
|
||||||
Help: "Count of successful tunnel registrations",
|
Help: "Count of successful tunnel registrations",
|
||||||
})
|
},
|
||||||
|
[]string{"rpcName"},
|
||||||
|
)
|
||||||
prometheus.MustRegister(registerSuccess)
|
prometheus.MustRegister(registerSuccess)
|
||||||
|
|
||||||
return &TunnelMetrics{
|
return &TunnelMetrics{
|
||||||
|
|
|
@ -40,6 +40,13 @@ const (
|
||||||
DuplicateConnectionError = "EDUPCONN"
|
DuplicateConnectionError = "EDUPCONN"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type registerRPCName string
|
||||||
|
|
||||||
|
const (
|
||||||
|
register registerRPCName = "register"
|
||||||
|
reconnect registerRPCName = "reconnect"
|
||||||
|
)
|
||||||
|
|
||||||
type TunnelConfig struct {
|
type TunnelConfig struct {
|
||||||
BuildInfo *buildinfo.BuildInfo
|
BuildInfo *buildinfo.BuildInfo
|
||||||
ClientID string
|
ClientID string
|
||||||
|
@ -364,10 +371,10 @@ func RegisterTunnel(
|
||||||
)
|
)
|
||||||
if registrationErr := registration.DeserializeError(); registrationErr != nil {
|
if registrationErr := registration.DeserializeError(); registrationErr != nil {
|
||||||
// RegisterTunnel RPC failure
|
// RegisterTunnel RPC failure
|
||||||
return processRegisterTunnelError(registrationErr, config.Metrics)
|
return processRegisterTunnelError(registrationErr, config.Metrics, register)
|
||||||
}
|
}
|
||||||
credentialManager.SetEventDigest(registration.EventDigest)
|
credentialManager.SetEventDigest(registration.EventDigest)
|
||||||
return processRegistrationSuccess(config, logger, connectionID, registration)
|
return processRegistrationSuccess(config, logger, connectionID, registration, register)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReconnectTunnel(
|
func ReconnectTunnel(
|
||||||
|
@ -402,12 +409,12 @@ func ReconnectTunnel(
|
||||||
)
|
)
|
||||||
if registrationErr := registration.DeserializeError(); registrationErr != nil {
|
if registrationErr := registration.DeserializeError(); registrationErr != nil {
|
||||||
// ReconnectTunnel RPC failure
|
// 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 {
|
for _, logLine := range registration.LogLines {
|
||||||
logger.Info(logLine)
|
logger.Info(logLine)
|
||||||
}
|
}
|
||||||
|
@ -432,16 +439,16 @@ func processRegistrationSuccess(config *TunnelConfig, logger *log.Entry, connect
|
||||||
config.Metrics.userHostnamesCounts.WithLabelValues(registration.Url).Inc()
|
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")
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func processRegisterTunnelError(err tunnelpogs.TunnelRegistrationError, metrics *TunnelMetrics) error {
|
func processRegisterTunnelError(err tunnelpogs.TunnelRegistrationError, metrics *TunnelMetrics, name registerRPCName) error {
|
||||||
if err.Error() == DuplicateConnectionError {
|
if err.Error() == DuplicateConnectionError {
|
||||||
metrics.regFail.WithLabelValues("dup_edge_conn").Inc()
|
metrics.regFail.WithLabelValues("dup_edge_conn", string(name)).Inc()
|
||||||
return dupConnRegisterTunnelError{}
|
return dupConnRegisterTunnelError{}
|
||||||
}
|
}
|
||||||
metrics.regFail.WithLabelValues("server_error").Inc()
|
metrics.regFail.WithLabelValues("server_error", string(name)).Inc()
|
||||||
return serverRegisterTunnelError{
|
return serverRegisterTunnelError{
|
||||||
cause: fmt.Errorf("Server error: %s", err.Error()),
|
cause: fmt.Errorf("Server error: %s", err.Error()),
|
||||||
permanent: err.IsPermanent(),
|
permanent: err.IsPermanent(),
|
||||||
|
|
Loading…
Reference in New Issue