Surface the reason when Prometheus metrics are unavailable - #2273
Draft
s1ckoleg wants to merge 4 commits into
Draft
Surface the reason when Prometheus metrics are unavailable#2273s1ckoleg wants to merge 4 commits into
s1ckoleg wants to merge 4 commits into
Conversation
added 4 commits
July 22, 2026 00:53
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.
Problem
When Prometheus metrics cannot be fetched, all detail-view charts show only the generic "Metrics not available at the moment". The real cause is invisible:
POST /api/metricsroute swallows every failure and returns HTTP 200 with{}, so the renderer cannot distinguish a fetch error from an empty result.error.cause, so even the logs only sayError: No Prometheus service foundorError: Metrics not availablewith no HTTP status and no Kubernetes error message (e.g. the RBACForbiddenbody).asyncComputedwrapper increate-time-ranged-metrics.tshas no rejection handler, sopendingnever resolves.In practice this makes RBAC-restricted clusters (users without
services list/services/proxypermissions) undiagnosable from inside the app: auto-detection fails, manual configuration fails, and the UI gives no hint why.Related: #1078, #1566.
Changes
One commit per independent fix:
provider.tsnow attach{ cause }, so the Kubernetes client error (with its HTTP status) survives the chain instead of being flattened into a string.metrics-error-classification.tsclassifies failures (not-found/access-denied/error) by walking the cause chain, and the warn log now includes the serialized cause chain (HTTP statuses, per-provider detection errors) instead of only the outer message.create-time-ranged-metrics.tsnow catches request rejections (always resolving, sinceasyncComputedhas no rejection handler) and exposes the failure as an observableerroralongsidevalue/pending.MetricsErrorInfowith a proper status code (503 not-found / 403 access-denied / carried status otherwise), andNoMetricsshows a reason-specific message ("No Prometheus service was found for this cluster." / "Access to Prometheus metrics was denied.") with an "Open cluster settings" link and the raw detail in the tooltip. The generic no-data state renders exactly as before. All directrequestMetricscall sites were audited and now handle rejection (cluster overview, nodes list) by falling back to the previous empty-metrics behavior.Compatibility
The successful response shape of
POST /api/metricsis unchanged. Extension callers ofRenderer.K8sApi.requestMetricskeep resolving with the same data on success; on failure they get a rejected promise (carrying a structured error body) instead of a silently empty object.Testing
create-time-ranged-metricsrejection/recovery,NoMetricsstates and settings-link navigation,JsonApiErrorParsed.dataaccessor, cluster overview metrics fallback.@freelensapp/coresuite: 2405 passed / 27 skipped (baseline before this branch: 2385 / 27), no regressions; full monorepo type-check clean; biome/trunk clean.Remaining before marking ready
lens.logshould contain the serialized cause (e.g. the KubernetesForbiddendetails).