TUN-1525: cloudflared metrics for registration success/fail
This commit is contained in:
parent
850f804c47
commit
e025a4cd7b
|
@ -51,6 +51,9 @@ 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
|
||||||
|
regFail *prometheus.CounterVec
|
||||||
|
|
||||||
muxerMetrics *muxerMetrics
|
muxerMetrics *muxerMetrics
|
||||||
tunnelsHA tunnelsForHA
|
tunnelsHA tunnelsForHA
|
||||||
}
|
}
|
||||||
|
@ -342,6 +345,22 @@ func NewTunnelMetrics() *TunnelMetrics {
|
||||||
)
|
)
|
||||||
prometheus.MustRegister(serverLocations)
|
prometheus.MustRegister(serverLocations)
|
||||||
|
|
||||||
|
registerFail := prometheus.NewCounterVec(
|
||||||
|
prometheus.CounterOpts{
|
||||||
|
Name: "tunnel_register_fail",
|
||||||
|
Help: "Count of tunnel registration errors by type",
|
||||||
|
},
|
||||||
|
[]string{"error"},
|
||||||
|
)
|
||||||
|
prometheus.MustRegister(registerFail)
|
||||||
|
|
||||||
|
registerSuccess := prometheus.NewCounter(
|
||||||
|
prometheus.CounterOpts{
|
||||||
|
Name: "tunnel_register_success",
|
||||||
|
Help: "Count of successful tunnel registrations",
|
||||||
|
})
|
||||||
|
prometheus.MustRegister(registerSuccess)
|
||||||
|
|
||||||
return &TunnelMetrics{
|
return &TunnelMetrics{
|
||||||
haConnections: haConnections,
|
haConnections: haConnections,
|
||||||
totalRequests: totalRequests,
|
totalRequests: totalRequests,
|
||||||
|
@ -357,6 +376,8 @@ func NewTunnelMetrics() *TunnelMetrics {
|
||||||
oldServerLocations: make(map[string]string),
|
oldServerLocations: make(map[string]string),
|
||||||
muxerMetrics: newMuxerMetrics(),
|
muxerMetrics: newMuxerMetrics(),
|
||||||
tunnelsHA: NewTunnelsForHA(),
|
tunnelsHA: NewTunnelsForHA(),
|
||||||
|
regSuccess: registerSuccess,
|
||||||
|
regFail: registerFail,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -351,13 +351,9 @@ func RegisterTunnel(
|
||||||
for _, logLine := range registration.LogLines {
|
for _, logLine := range registration.LogLines {
|
||||||
config.Logger.Info(logLine)
|
config.Logger.Info(logLine)
|
||||||
}
|
}
|
||||||
if registration.Err == DuplicateConnectionError {
|
|
||||||
return dupConnRegisterTunnelError{}
|
if regErr := processRegisterTunnelError(registration.Err, registration.PermanentFailure, config.Metrics); regErr != nil {
|
||||||
} else if registration.Err != "" {
|
return regErr
|
||||||
return serverRegisterTunnelError{
|
|
||||||
cause: fmt.Errorf("Server error: %s", registration.Err),
|
|
||||||
permanent: registration.PermanentFailure,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if registration.TunnelID != "" {
|
if registration.TunnelID != "" {
|
||||||
|
@ -381,6 +377,22 @@ func RegisterTunnel(
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func processRegisterTunnelError(err string, permanentFailure bool, metrics *TunnelMetrics) error {
|
||||||
|
if err == "" {
|
||||||
|
metrics.regSuccess.Inc()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
metrics.regFail.WithLabelValues(err).Inc()
|
||||||
|
if err == DuplicateConnectionError {
|
||||||
|
return dupConnRegisterTunnelError{}
|
||||||
|
}
|
||||||
|
return serverRegisterTunnelError{
|
||||||
|
cause: fmt.Errorf("Server error: %s", err),
|
||||||
|
permanent: permanentFailure,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func UnregisterTunnel(muxer *h2mux.Muxer, gracePeriod time.Duration, logger *log.Logger) error {
|
func UnregisterTunnel(muxer *h2mux.Muxer, gracePeriod time.Duration, logger *log.Logger) error {
|
||||||
logger.Debug("initiating RPC stream to unregister")
|
logger.Debug("initiating RPC stream to unregister")
|
||||||
stream, err := muxer.OpenStream([]h2mux.Header{
|
stream, err := muxer.OpenStream([]h2mux.Header{
|
||||||
|
|
Loading…
Reference in New Issue