← Back to Pull requests

Handle vSphere vSAN collection errors per cluster instead of per vCenter #25435

Closed
unknown closed this pull request without merging on Oct 06, 2026 00:06 UTC
View on GitHub
unknown unknown commented on Sep 30, 2026 00:39 UTC
Author

What does this PR do?

Makes vSAN metric collection tolerate a failure on a single cluster.

get_vsan_metrics loops over every vSAN-enabled cluster and accumulates results into local lists. Nothing inside the loop caught errors, so an exception from one cluster unwound the whole function and discarded every result already gathered. The only handler was a single broad except Exception wrapping the entire collection in collect_vsan_metrics, which logs a warning. One unhealthy cluster therefore cost the whole vCenter its vSAN metrics on every run.

@smart_retry compounded the problem instead of relieving it. It calls smart_connect, which runs connect.Disconnect on the previous session, then re-invokes the function with the same arguments. Those arguments include the cluster managed objects, which remain bound to the now logged-out session, so the retry failed immediately on the first cluster_reference.name property fetch with NotAuthenticated. This is specific to get_vsan_metrics: every other @smart_retry method re-reads self._conn, so reconnecting actually helps them. Because the original exception is only logged at DEBUG, the warning users actually saw was the retry's NotAuthenticated against whichever cluster happened to be first in the list, not the real cause.

Changes:

  • Extract the body of the per-cluster loop into _get_cluster_vsan_metrics and wrap the call in a try/except. A failing cluster is skipped with a warning naming the cluster and the real error; the remaining clusters are still collected.

  • Remove @smart_retry from get_vsan_metrics, since a retry there cannot succeed.

  • Add cluster_display_name, which falls back to the managed object id when reading name fails. name is a property fetch against vCenter, so it raises when the session is gone — without the fallback the warning handler itself would raise and we would be back to losing the run.
  • No metric, tag, or config change: the metrics emitted for a healthy cluster are identical.

    One caveat worth calling out for review. The escalation also reports an AttributeError: groupId on vCenter 9.0.2, which suggests QueryClusterHealth returns a different payload shape there. This PR makes that failure visible and contained — the cluster is skipped with a clear log line rather than taking the vCenter down with it — but it does not make vSAN collection work on 9.x. Establishing the 9.x response shape needs a real 9.0.2 vCenter and is left as follow-up.

    Motivation

    Reported in AGENT-17268. A customer lost all vSAN metrics across a vCenter because one decommissioned cluster had no vSAN stats primary:

    18:01:42 ... Querying vSAN metrics for cluster IADC01
    18:01:47 ... An exception occurred when executing get_vsan_metrics: (vim.fault.NotFound)
       key = 'com.vmware.vsan.perfsvc.fault.masternotfound',
       message = 'Stats primary cannot be found in the cluster.'
       ... Refreshing the connection to vCenter and retrying
    18:01:47 ... WARN (vsphere.py:593) | Unable to fetch vSAN metrics (vim.fault.NotAuthenticated)
       object = 'vim.ClusterComputeResource:domain-c3489'
    

    The NotAuthenticated on domain-c3489 is the retry failing against a different cluster — the first in the list — which is why the actual masternotfound cause was invisible at default log level. The customer only resolved it by removing the cluster from vCenter.

    Tests were written first and cover the three observable failures: a cluster whose QueryClusterHealth or QueryVsanPerf raises, a cluster returning a health group without groupId, and a cluster whose name is unreadable. Each asserts the other clusters still report and that the real error reaches the warning log.

    Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)

  • Add qa/required if this PR needs QA validation, or qa/skip-qa if it does not. Exactly one of the two is required.

  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged
  • 🤖 Generated with Claude Code

    Diff: 532 lines (+399 / -133) across 6 files Reviewer: HadhemiDD Review duration: 8607m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.48) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 532 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.376
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #25435"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.9% (MEDIUM) · Higher = larger blast radius
    47.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.7% · Safe to merge
    20.7%