8000 refactor(bridge): share endpoint health probe and wrapperRef alias lookup by VLukiantsev · Pull Request #1077 · google/xmc · GitHub
[go: up one dir, main page]

Skip to content

refactor(bridge): share endpoint health probe and wrapperRef alias lookup - #1077

Merged
VLukiantsev merged 1 commit into
mainfrom
refactor/bridge-dry-leftovers
Oct 6, 2026
Merged

VLukiantsev merged 1 commit into
mainfrom
refactor/bridge-dry-leftovers

Conversation

@VLukiantsev
Copy link
Copy Markdown
Collaborator

Summary

Removes two duplicated pieces of logic in pkg/components/bridge:

  • The active endpoint health probe that BridgeProber.probe3PEndpoint and Reconciler.verifyEndpointHealth each implemented separately.
  • The wrapperRef key aliases that parseWrapperRef and ParseWrapperRef each declared.

Motivation & Context

These copies were found during the bridge SRP work. They aren't part of any file split, so they go in their own PR. Each copy could drift on its own; for example, a fix to the nil-result handling or a new key alias would have to be made twice.

Key Changes

  • New endpoint_health_probe.go: probeEndpointHealth(ctx, prober, endpoint, timeout).
    • Skips the probe (reports healthy) when the endpoint is empty or the prober is nil.
    • Returns probe errors unchanged, and turns a nil result into errNilProbeResult.
    • It takes a small endpointProber interface defined where it's used, which HealthProber and StatusDetectorHealthProber both satisfy.
  • Both callers now delegate to it and keep only their own message and reason mapping. Status, messages and timeouts don't change. The Reconciler passes a zero timeout, which BridgeProber.Probe replaces with the same configured default as before.
  • ParseWrapperRef now gets group, version, kind, name and namespace through parseWrapperRef and ToBridgeWrapperRef, so each alias pair is declared once. The JSONPath fields stay in ParseWrapperRef, the only function that uses them.
  • Tests:
    • TestProbeEndpointHealth;
    • TestVerifyEndpointHealth, covering every Reconciler reason and message (no direct coverage before);
    • a "probe error" case in TestBridgeProber_ProbeHealthMessageFallbacks;
    • TestParseWrapperRef_KeyAliases, covering which key wins over its alias and the fallback.

Assumptions

  • Different messages are intentional. The two callers' error and unhealthy messages differ (e.g. health probe error: ... vs Health probe failed for <ep>: ...). I treated that as deliberate per-caller behaviour and kept it, rather than picking one. If they should match, that's a one-line follow-up.
  • Not fixed here: a BridgeProber built without a healthProber reports healthy from ProbeHealth, but ProbeFailed through the Reconciler's Probe path. That inconsistency was already there and this PR doesn't change it.

Verification & Testing

  • bazel test //pkg/components/bridge:bridge_test --test_output=errors --runs_per_test=3: passes.
  • bazel build //pkg/components/... //cmd/xmc_bridge/...: passes.
  • Pre-commit (buildifier, gofmt, golangci-lint including dupl, test determinism checker, addlicense): passes.
  • Size: 72 prod / 212 test lines.

Related Issues / Bugs

N/A

TAG=agy
CONV=25ae2278-aa0f-44db-af8a-4f9deda0d399

…okup

Extract probeEndpointHealth (endpoint_health_probe.go) as the single
implementation of the active endpoint probe (skip on empty endpoint or
nil prober, call Probe, report a nil result as errNilProbeResult).
BridgeProber.probe3PEndpoint and Reconciler.verifyEndpointHealth now
delegate to it and keep only their caller-specific message/reason
mapping, so observable status, messages and timeouts are unchanged.

ParseWrapperRef now resolves target coordinates through parseWrapperRef
and ToBridgeWrapperRef, so the crdGroup/group, crdVersion/version,
crdKind/kind, targetName/name and targetNamespace/namespace aliases are
declared once.

Add table-driven tests for probeEndpointHealth, verifyEndpointHealth's
reason/message mapping, the BridgeProber probe-error message, and
wrapperRef alias precedence/fallback.

TAG=agy
CONV=25ae2278-aa0f-44db-af8a-4f9deda0d399
@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request consolidates active health probing logic by introducing a shared probeEndpointHealth helper function in endpoint_health_probe.go, refactoring bridge_prober.go and wrapper_reconciler.go to use it. It also refactors ParseWrapperRef in spec_parser.go to reuse existing parsing helpers and avoid duplicate key alias definitions, and adds corresponding unit tests. There are no review comments, and I have no feedback to provide.

@VLukiantsev
VLukiantsev marked this pull request as ready for review October 6, 2026 07:23
@github-actions
github-actions Bot requested a review from pachopepe October 6, 2026 07:23
@VLukiantsev
VLukiantsev added this pull request to the merge queue Oct 6, 2026
Merged via the queue into main with commit 604ee87 Oct 6, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0