PHOENIX-7872 Addendum record HA failover duration on the CRR-write path and add a connection-failed counter - #2605
Open
lokiore wants to merge 1 commit into
Conversation
…th and add a connection-failed counter The HA failover observability metrics added under PHOENIX-7872 recorded HA_FAILOVER_DURATION_MS inside FailoverPhoenixConnection.failover(long). That method is only reached through wrapActionDuringFailover -> FailoverPolicy .shouldFailover(), which returns false under the default ExplicitFailoverPolicy, or through the explicit static failover(Connection, long) helper. Neither runs during an autonomous, CRR-driven failover, so the duration metric never moved in production. Move the duration measurement to the path that actually drives failovers: refreshClusterRoleRecord, where the cluster-role transition is dispatched and where HA_FAILOVER_COUNT is already gated by shouldCountFailover. The dispatch block is wrapped in a try/finally so the duration is recorded on every exit (success, timeout, policy failure, or interrupt), avoiding a silent metric miss if a future exit path is added. The now-dead timing in failover(long) is removed. Add HA_FAILOVER_CONNECTION_FAILED_COUNTER, incremented at the single SQLException throw funnel in connectActive (no active cluster, cluster demoted mid-connect, or the underlying connect threw). This tracks real active-cluster connection failures regardless of the configured failover policy. Tests: three unit tests in HighAvailabilityGroupTest -- a counted role-flip transition records both HA_FAILOVER_COUNT and an HA_FAILOVER_DURATION_MS sample on the CRR-write path; a failed connectActive increments the connection-failed counter; a successful connectActive leaves it unchanged. HighAvailabilityGroupTest 16/16, FailoverPhoenixConnectionTest 8/8. Generated-by: Claude Code (Opus 4.8) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
lokiore
marked this pull request as ready for review
August 20, 2026 20:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Follow-up to the HA failover observability metrics added under PHOENIX-7872, correcting where two metrics are recorded on the HA client path.
HA_FAILOVER_DURATION_MSmoved to the CRR-write path. It was recorded insideFailoverPhoenixConnection.failover(long), which is only reached throughwrapActionDuringFailover→FailoverPolicy.shouldFailover()(returnsfalseunder the defaultExplicitFailoverPolicy) or the explicit staticfailover(Connection, long)helper — neither runs during an autonomous, cluster-role-record-driven failover. The measurement now lives inHighAvailabilityGroup.refreshClusterRoleRecord, where the cluster-role transition is actually dispatched and whereHA_FAILOVER_COUNTis already gated byshouldCountFailover. The dispatch block is wrapped in atry/finallyso the duration is recorded on every exit (success, timeout, policy failure, interrupt), which avoids a silent metric miss if a future exit path is added. The now-dead timing infailover(long)is removed.HA_FAILOVER_CONNECTION_FAILED_COUNTER(GLOBAL_HA_FAILOVER_CONNECTION_FAILED_COUNTER), incremented at the singleSQLExceptionthrow funnel inconnectActive(no active cluster, cluster demoted mid-connect, or the underlying connect threw).Class touch points:
FailoverPhoenixConnection— remove dead duration timing + now-unused import.HighAvailabilityGroup— record duration on the transition-dispatchtry/finally; increment the new counter on theconnectActivethrow funnel.MetricType/GlobalClientMetrics— add the new counter constant; correct theHA_FAILOVER_DURATION_MSdescription to reflect the CRR-write recording site.Why are the changes needed?
As placed,
HA_FAILOVER_DURATION_MSnever moved in production: the defaultExplicitFailoverPolicy.shouldFailover()returnsfalse, soFailoverPhoenixConnection.failover(long)is not auto-invoked during a real, CRR-driven failover. Recording the duration onrefreshClusterRoleRecordties it to the path that actually drives failovers, alongside the existingHA_FAILOVER_COUNT. The new connection-failed counter gives operators visibility into failed active-cluster connection attempts independent of the configured failover policy.Does this PR introduce any user-facing change?
No. Client-side metric placement/addition only; no API or query-behavior change. These metrics are on an unreleased feature branch.
How was this patch tested?
Three unit tests added to
HighAvailabilityGroupTest:testCountedTransitionRecordsFailoverCountAndDuration— a counted role-flip transition driven throughrefreshClusterRoleRecordincrementsHA_FAILOVER_COUNTand records anHA_FAILOVER_DURATION_MSsample on the CRR-write path.testConnectActiveFailureIncrementsFailedCounter— a failedconnectActive(no active cluster) increments the connection-failed counter on itsSQLExceptionfunnel.testConnectActiveSuccessLeavesFailedCounterUnchanged— a successfulconnectActiveleaves the counter unchanged (non-vacuous negative assertion).Results:
HighAvailabilityGroupTest16/16,FailoverPhoenixConnectionTest8/8.spotless:checkclean on the touched files.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)
🤖 Generated with Claude Code