Skip to content

frontend: apiDiscovery: Log every fallback or skipped fetch#6033

Open
WasThatRudy wants to merge 1 commit into
kubernetes-sigs:mainfrom
WasThatRudy:fix/api-discovery-silent-error-swallow
Open

frontend: apiDiscovery: Log every fallback or skipped fetch#6033
WasThatRudy wants to merge 1 commit into
kubernetes-sigs:mainfrom
WasThatRudy:fix/api-discovery-silent-error-swallow

Conversation

@WasThatRudy

Copy link
Copy Markdown
Contributor

Summary

Fixes #4840. Three catch blocks in frontend/src/lib/k8s/api/v2/apiDiscovery.tsx silently swallowed their errors:

  • The outer aggregated-discovery try/catch set useFallback = true with no log line — a thrown error during aggregated discovery left no trace, and the legacy path was taken without any breadcrumb.
  • The two .catch(() => null) callbacks on the legacy /api and /apis fetches dropped their rejection reasons on the floor; if either rejected, every dependent resource fetch was skipped with nothing in the console to explain why.

Both kinds of failure surface as "resources missing in the UI" with zero console output, which makes the underlying network or RBAC condition extremely hard to diagnose.

Changes

All logging is console.debug to match the existing logs already present on the per-group fetch path (processLegacyApiResourceList already had debug logs from earlier work).

Location Was Now
Outer aggregated catch (error) flips useFallback only logs Aggregated API discovery threw for cluster <name> with the error
Aggregated-but-unusable-payload branch (!apiAggregatedOk || !apisAggregatedOk) flips useFallback only logs each side separately with the rejection reason (for rejected settlements) or the offending value (for fulfilled-but-malformed payloads) so the reader can tell which call returned what
Legacy /api fetch .catch(() => null) silently null logs Legacy /api discovery fetch failed for cluster <name> with the error, then null
Legacy /apis fetch .catch(() => null) silently null logs Legacy /apis discovery fetch failed for cluster <name> with the error, then null

Test plan

  • Added 4 regression tests under apiDiscovery > logs the cause of every fallback or skipped fetch:
    • aggregated /api rejection → log + rejection reason captured
    • aggregated returns fulfilled-but-malformed payload ({ unexpected: 'shape' }) → unusable-payload log
    • legacy /api rejection → log + rejection reason captured
    • legacy /apis rejection → log + rejection reason captured
  • All 8 pre-existing tests pass (12/12 in the file). Two of the pre-existing tests now produce expected debug output in stdout, since they use mockFetchError (status 500 / not-ok) which is exactly the malformed-payload path the new log targets — this is visible but not a failure.
  • npm run tsc clean.
  • npx eslint -c .eslintrc.ci.cjs --max-warnings 0 clean.
  • Manual: with browser devtools' Verbose log level enabled, open Headlamp against a cluster that rate-limits or blocks discovery; the cluster's discovery failure now appears in the console with the cluster name and the underlying error.

Notes for the reviewer

console.debug is intentional — these are diagnostic breadcrumbs, not user-facing errors, and they match the level already used by the per-group fetch logs in the same function. Anyone investigating "missing resources" can flip devtools to Verbose and see exactly which call dropped.

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: WasThatRudy
Once this PR has been reviewed and has the lgtm label, please assign yolossn for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 15, 2026
@k8s-ci-robot k8s-ci-robot requested review from illume and skoeva June 15, 2026 15:12
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 15, 2026
@illume illume requested a review from Copilot June 16, 2026 09:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves observability of Kubernetes API discovery by adding console.debug breadcrumbs whenever aggregated discovery is unusable or legacy discovery fetches are skipped/fail, so “missing resources” scenarios have diagnosable console output (Fixes #4840).

Changes:

  • Add debug logging when aggregated discovery responses are rejected or malformed, and when the code falls back to legacy discovery.
  • Add debug logging for legacy /api and /apis fetch rejections (previously swallowed).
  • Add regression tests that pin the new logging behavior for aggregated and legacy failure modes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
frontend/src/lib/k8s/api/v2/apiDiscovery.tsx Adds console.debug logs covering aggregated-discovery unusable results and legacy discovery fetch failures before falling back/skipping.
frontend/src/lib/k8s/api/v2/apiDiscovery.test.ts Adds regression tests asserting the new debug logs are emitted for key fallback/skipped-fetch scenarios.

Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.test.ts
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.test.ts
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.test.ts
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.test.ts
@WasThatRudy WasThatRudy requested a review from Copilot June 16, 2026 22:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx Outdated
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.test.ts Outdated
@WasThatRudy WasThatRudy requested a review from Copilot June 16, 2026 22:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx Outdated
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx Outdated
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.test.ts Outdated
@WasThatRudy WasThatRudy requested a review from Copilot June 17, 2026 01:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx Outdated
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx Outdated
@WasThatRudy WasThatRudy requested a review from Copilot June 17, 2026 01:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx Outdated
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx Outdated
@WasThatRudy WasThatRudy requested a review from Copilot June 17, 2026 02:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx Outdated
WasThatRudy added a commit to WasThatRudy/headlamp that referenced this pull request Jun 17, 2026
Apply two patterns the maintainer review flagged on PR kubernetes-sigs#6033: codebase
uses American English uniformly (`serialize`, `colorize`, `optimize` —
zero `-ise` instances), and the duck-typed legacy/new CRD-API-group
lookup was duplicated between getBaseObject() and makeKubeObjectNode()
with identical bodies. Extract a `resolveCRDApiGroup` helper alongside
the other spec helpers in `crdSpec.ts` so both call sites share one
implementation and a future maintainer touching the legacy-plugin
contract only has to change it in one place.

Signed-off-by: Rudraksha Singh Sengar <rudraksharss@gmail.com>
@WasThatRudy WasThatRudy requested a review from Copilot June 17, 2026 04:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx Outdated
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.test.ts Outdated
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx Outdated
@WasThatRudy WasThatRudy requested a review from Copilot June 17, 2026 04:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx Outdated
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.test.ts
@WasThatRudy WasThatRudy force-pushed the fix/api-discovery-silent-error-swallow branch 4 times, most recently from 6fd7078 to 2634eb9 Compare June 17, 2026 04:57
@WasThatRudy WasThatRudy requested a review from Copilot June 17, 2026 05:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment on lines +110 to +120
function fetchLegacyOrLogFailure(
path: '/api' | '/apis',
cluster: string
): Promise<{ versions?: unknown[]; groups?: unknown[] } | null> {
return clusterFetch(path, { cluster })
.then(res => res.json())
.catch(err => {
console.debug(`Legacy ${path} discovery fetch or parse failed for cluster ${cluster}:`, err);
return null;
});
}
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx
Comment thread frontend/src/lib/k8s/api/v2/apiDiscovery.tsx
@WasThatRudy WasThatRudy force-pushed the fix/api-discovery-silent-error-swallow branch from 2634eb9 to dcdc510 Compare June 17, 2026 05:10
Three failure paths in cluster API discovery silently swallowed their
cause: the outer try/catch around aggregated discovery, the two
fulfilled-but-malformed payload checks, and the .catch(() => null)
handlers around the legacy /api and /apis fetches. Without those logs
a "missing resources in the UI" report was effectively undebuggable;
nothing told the user that aggregated discovery had quietly fallen
back to the legacy path or that the legacy fetch itself had failed.

Add a console.debug breadcrumb on every fallback or skipped fetch.
Bodies that arrive intact but with the wrong shape go through a
summarizer that logs the value's type plus a capped list of top-level
keys, so a real K8s discovery response (which can carry thousands of
entries) doesn't flood the devtools and bury the actual failure
signal. The summarizer iterates keys lazily with for...in so the
bound is honest at the computation layer, not just at the log-output
layer, and returns a discriminated PayloadSummary so call sites and
tests can pattern-match instead of duck-typing.

Add regression tests covering each failure mode and the
bounded-summary contract (truncation, null body, array body), pinning
the full discriminated shape so a future debug log carrying a keys
field can't accidentally satisfy the assertion.

Bug report: 4840.

Signed-off-by: Rudraksha Singh Sengar <rudraksharss@gmail.com>
@WasThatRudy WasThatRudy force-pushed the fix/api-discovery-silent-error-swallow branch from dcdc510 to dd7d019 Compare June 17, 2026 05:27
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 17, 2026

@illume illume left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for working on this.

Would you mind addressing the open Copilot review comments? Please mark each comment as resolved after addressing it.

@WasThatRudy WasThatRudy requested a review from Copilot June 17, 2026 09:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@WasThatRudy

Copy link
Copy Markdown
Contributor Author

@illume all the copilot comments have been resolved and the latest review has not generated any new comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Silent Error Swallowing in Discovery

4 participants