diff --git a/proxyd/consensus_poller.go b/proxyd/consensus_poller.go index a17945d1..1de6d167 100644 --- a/proxyd/consensus_poller.go +++ b/proxyd/consensus_poller.go @@ -732,13 +732,16 @@ func (cp *ConsensusPoller) setBackendState(be *Backend, peerCount uint64, inSync func (cp *ConsensusPoller) getConsensusCandidates() map[*Backend]*backendState { healthyPrimaries := cp.FilterCandidates(cp.backendGroup.Primaries()) - RecordHealthyCandidates(cp.backendGroup, len(healthyPrimaries)) + + healthyFallbacks := cp.FilterCandidates(cp.backendGroup.Fallbacks()) + RecordHealthyFallbackCandidates(cp.backendGroup, len(healthyFallbacks)) + if len(healthyPrimaries) > 0 { return healthyPrimaries } - return cp.FilterCandidates(cp.backendGroup.Fallbacks()) + return healthyFallbacks } // filterCandidates find out what backends are the candidates to be in the consensus group diff --git a/proxyd/metrics.go b/proxyd/metrics.go index b5f8b031..ce804c64 100644 --- a/proxyd/metrics.go +++ b/proxyd/metrics.go @@ -442,6 +442,14 @@ var ( "backend_group_name", }) + healthyFallbackCandidates = promauto.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: MetricsNamespace, + Name: "healthy_fallback_candidates", + Help: "Record the number of healthy fallback candidates", + }, []string{ + "backend_group_name", + }) + backendGroupFallbackBackend = promauto.NewGaugeVec(prometheus.GaugeOpts{ Namespace: MetricsNamespace, Name: "backend_group_fallback_backenend", @@ -605,6 +613,10 @@ func RecordHealthyCandidates(b *BackendGroup, candidates int) { healthyPrimaryCandidates.WithLabelValues(b.Name).Set(float64(candidates)) } +func RecordHealthyFallbackCandidates(b *BackendGroup, candidates int) { + healthyFallbackCandidates.WithLabelValues(b.Name).Set(float64(candidates)) +} + func RecordConsensusBackendPeerCount(b *Backend, peerCount uint64) { consensusPeerCountBackend.WithLabelValues(b.Name).Set(float64(peerCount)) }