AzureMonitor: Add custom header support to Azure Monitor (#60269)

* Add integration test for Azure Monitor

- Add Azure Monitor to datasource types
- Update instance creation to correctly set HTTP client options
- Combine custom azure headers and custom grafana headers on HTTP client creation
- Update HTTP client tests

* Test custom azure headers
This commit is contained in:
Andreas Christou
2022-12-14 15:09:11 +00:00
committed by GitHub
parent e3805e1309
commit c81df0dec0
5 changed files with 164 additions and 11 deletions
+5 -5
View File
@@ -13,9 +13,9 @@ import (
"github.com/grafana/grafana/pkg/tsdb/azuremonitor/types"
)
func newHTTPClient(route types.AzRoute, model types.DatasourceInfo, cfg *setting.Cfg, clientProvider httpclient.Provider) (*http.Client, error) {
opts := sdkhttpclient.Options{
Headers: route.Headers,
func newHTTPClient(route types.AzRoute, model types.DatasourceInfo, cfg *setting.Cfg, clientProvider httpclient.Provider, httpClientOptions sdkhttpclient.Options) (*http.Client, error) {
for header, value := range route.Headers {
httpClientOptions.Headers[header] = value
}
// Use Azure credentials if the route has OAuth scopes configured
@@ -23,8 +23,8 @@ func newHTTPClient(route types.AzRoute, model types.DatasourceInfo, cfg *setting
if cred, ok := model.Credentials.(*azcredentials.AzureClientSecretCredentials); ok && cred.ClientSecret == "" {
return nil, fmt.Errorf("unable to initialize HTTP Client: clientSecret not found")
}
azhttpclient.AddAzureAuthentication(&opts, cfg.Azure, model.Credentials, route.Scopes)
azhttpclient.AddAzureAuthentication(&httpClientOptions, cfg.Azure, model.Credentials, route.Scopes)
}
return clientProvider.New(opts)
return clientProvider.New(httpClientOptions)
}