Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward grafana meta values to downstream API #1072

Draft
wants to merge 6 commits into
base: dev-3.0.0
Choose a base branch
from

Conversation

yesoreyeram
Copy link
Collaborator

@yesoreyeram yesoreyeram commented Nov 28, 2024

This PR will allow datasource authors to pass grafana meta data such as user id, datasource uid to the underlying API as query parameters / headers.

Any value set by the user in query will be overriden by the values from the data source settings.

Fixes #1073
Fixes #867
Fixes #457

How to test this

image

Before changes

  • add a new infinity datasource instance
  • in datasource custom http header add a new key X-Grafana-User with value ${__user.login}
  • in datasource URL query parameter add a new key X-Grafana-Datasource-UID with value ${__ds.uid}
  • Add https://httpbin.org to the allowed hosts
  • Save and test the datasource
  • Create a query in explore with URL and backend parser option
  • Add https://httpbin.org/get as URL and run the query. Inspect headers and args in the result
image image

After changes

refresh the query and you will see actual values / interpolated values in the args / headers as shown below.

image image

also in query inspector

image

@yesoreyeram yesoreyeram force-pushed the grafana-headers-forwarding branch from 58a8f7a to fb1799b Compare November 28, 2024 13:41
@yesoreyeram yesoreyeram changed the title Support passing X-Grafana-User and X-Grafana-Datasource-UID as header… Forward grafana meta values as headers to downstream API Nov 28, 2024
@yesoreyeram yesoreyeram changed the title Forward grafana meta values as headers to downstream API Forward grafana meta values as headers/query parameters to downstream API Nov 28, 2024
@yesoreyeram yesoreyeram marked this pull request as ready for review November 28, 2024 16:10
@yesoreyeram yesoreyeram requested a review from a team as a code owner November 28, 2024 16:10
@yesoreyeram yesoreyeram changed the base branch from main to dev-3.0.0 December 1, 2024 23:22
@yesoreyeram yesoreyeram changed the title Forward grafana meta values as headers/query parameters to downstream API Forward grafana meta values as headers/query params to downstream API Dec 1, 2024
@yesoreyeram yesoreyeram changed the title Forward grafana meta values as headers/query params to downstream API Forward grafana meta values to downstream API Dec 1, 2024
@yesoreyeram yesoreyeram marked this pull request as draft December 1, 2024 23:28
@yesoreyeram yesoreyeram added this to the Version 3.0 milestone Dec 9, 2024
@yesoreyeram yesoreyeram self-assigned this Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use global variable in Authentication
2 participants