Skip to content

fix: fallback between /resources and /proxy datasource endpoints#562

Open
sd2k wants to merge 2 commits intomainfrom
fix-524
Open

fix: fallback between /resources and /proxy datasource endpoints#562
sd2k wants to merge 2 commits intomainfrom
fix-524

Conversation

@sd2k
Copy link
Collaborator

@sd2k sd2k commented Feb 10, 2026

Summary

  • Adds a datasourceFallbackTransport that automatically retries with the alternate datasource proxy endpoint when the primary returns 403 or 500
  • Prometheus tries /api/datasources/uid/{uid}/resources first, falls back to /api/datasources/proxy/uid/{uid}
  • Loki tries /api/datasources/proxy/uid/{uid} first, falls back to /api/datasources/uid/{uid}/resources
  • Caches which endpoint works per-datasource to avoid repeated failures

Context

Different managed Grafana deployments support different datasource proxy endpoints:

  • Azure Managed Grafana requires /api/datasources/uid/{uid}/resources (the /proxy path returns 403)
  • AWS Managed Grafana requires /api/datasources/proxy/uid/{uid} (the /resources path returns 500 for POST)

PR #483 switched Prometheus to /resources to fix Azure, but this broke AWS. This PR makes both work transparently.

Test plan

  • Unit tests for fallback transport (primary success, fallback on 403/500, caching, POST body preservation, no retry on other errors)
  • Integration test with self-hosted Grafana (both endpoints work, no fallback needed)
  • Manual verification on AWS Managed Grafana
  • Manual verification on Azure Managed Grafana

Fixes #524

🤖 Generated with Claude Code


Note

Medium Risk
Touches core HTTP request routing for Prometheus/Loki datasource calls and adds automatic retry/caching behavior, which could mask real 403/500s or change request semantics if path rewriting/body replay has edge cases.

Overview
Adds a new datasourceFallbackTransport http.RoundTripper that rewrites datasource request paths and automatically retries against an alternate endpoint on 403 or 500, buffering/replaying request bodies and caching which base path requires fallback to avoid repeated failures.

Updates Prometheus and Loki clients to build datasource base paths via datasourceProxyPaths and wrap their HTTP transports with this fallback logic (Prometheus: /resources -> /proxy; Loki: /proxy -> /resources) to improve compatibility across managed Grafana deployments.

Written by Cursor Bugbot for commit c0c0e37. This will update automatically on new commits. Configure here.

Different managed Grafana deployments support different datasource proxy
endpoints: Azure requires /resources while AWS requires /proxy. When the
primary endpoint returns 403 or 500, automatically retry with the
alternate endpoint and cache the result for subsequent requests.

Fixes #524

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

MCP Token Analysis

Passed

Metric Value
Baseline 14373 tokens
Current 14373 tokens
Change +0 (+0.0%)

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.

403 Forbidden on Prometheus/Loki query tools (datasource resources proxy) while same token works for /api/ds/query and from curl

1 participant