Docs: Update backend plugin forwarding of headers (#67913)

Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
Co-authored-by: Joseph Perez <45749060+josmperez@users.noreply.github.com>
This commit is contained in:
Marcus Efraimsson 2023-05-09 11:47:20 +02:00 committed by GitHub
parent b8093bd0d9
commit 04df92ab47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -291,7 +291,7 @@ To allow Grafana to pass the access token to the plugin, update the data source
When configured, Grafana can forward authorization HTTP headers such as `Authorization` or `X-ID-Token` to a backend data source. This information is available across the `QueryData`, `CallResource` and `CheckHealth` requests.
To get Grafana to forward the headers, create a HTTP client using the [Grafana Plugin SDK](https://pkg.go.dev/github.com/grafana/grafana-plugin-sdk-go/backend/httpclient). This package exposes request information which can be subsequently forwarded downstream and/or used directly within the plugin.
To get Grafana to forward the headers, create a HTTP client using the [Grafana plugin SDK for Go](https://pkg.go.dev/github.com/grafana/grafana-plugin-sdk-go/backend/httpclient) and set the `ForwardHTTPHeaders` option to `true` (by default, it's set to `false`). This package exposes request information which can be subsequently forwarded downstream and/or used directly within the plugin.
```go
func NewDatasource(settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
@ -299,6 +299,9 @@ func NewDatasource(settings backend.DataSourceInstanceSettings) (instancemgmt.In
if err != nil {
return nil, fmt.Errorf("http client options: %w", err)
}
opts.ForwardHTTPHeaders = true
// Important to reuse the same client for each query, to avoid using all available connections on a host
cl, err := httpclient.New(opts)
if err != nil {