Skip to content

Commit

Permalink
Prometheus: Remove cache, pass headers in request, simplify client cr…
Browse files Browse the repository at this point in the history
…eation for resource calls and custom client (#51436)

* Remove cache, pass headers in request, simplify client creation

* Add test for http options creation
  • Loading branch information
aocenas committed Jul 4, 2022
1 parent b7e22c3 commit 3df34fe
Show file tree
Hide file tree
Showing 17 changed files with 238 additions and 918 deletions.
3 changes: 2 additions & 1 deletion pkg/services/featuremgmt/manager.go
Expand Up @@ -162,7 +162,8 @@ func (fm *FeatureManager) HandleGetSettings(c *models.ReqContext) {
}

// WithFeatures is used to define feature toggles for testing.
// The arguments are a list of strings that are optionally followed by a boolean value
// The arguments are a list of strings that are optionally followed by a boolean value for example:
// WithFeatures([]interface{}{"my_feature", "other_feature"}) or WithFeatures([]interface{}{"my_feature", true})
func WithFeatures(spec ...interface{}) *FeatureManager {
count := len(spec)
enabled := make(map[string]bool, count)
Expand Down
6 changes: 3 additions & 3 deletions pkg/tsdb/prometheus/buffered/client.go
Expand Up @@ -5,11 +5,11 @@ import (
"net/http"
"strings"

"github.com/grafana/grafana-azure-sdk-go/azsettings"
"github.com/grafana/grafana-plugin-sdk-go/backend"
sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tsdb/prometheus/buffered/azureauth"
"github.com/grafana/grafana/pkg/tsdb/prometheus/middleware"
"github.com/grafana/grafana/pkg/tsdb/prometheus/utils"
Expand All @@ -20,7 +20,7 @@ import (

// CreateTransportOptions creates options for the http client. Probably should be shared and should not live in the
// buffered package.
func CreateTransportOptions(settings backend.DataSourceInstanceSettings, cfg *setting.Cfg, features featuremgmt.FeatureToggles, logger log.Logger) (*sdkhttpclient.Options, error) {
func CreateTransportOptions(settings backend.DataSourceInstanceSettings, azureSettings *azsettings.AzureSettings, features featuremgmt.FeatureToggles, logger log.Logger) (*sdkhttpclient.Options, error) {
opts, err := settings.HTTPClientOptions()
if err != nil {
return nil, err
Expand All @@ -41,7 +41,7 @@ func CreateTransportOptions(settings backend.DataSourceInstanceSettings, cfg *se

// Azure authentication is experimental (#35857)
if features.IsEnabled(featuremgmt.FlagPrometheusAzureAuth) {
err = azureauth.ConfigureAzureAuthentication(settings, cfg.Azure, &opts)
err = azureauth.ConfigureAzureAuthentication(settings, azureSettings, &opts)
if err != nil {
return nil, fmt.Errorf("error configuring Azure auth: %v", err)
}
Expand Down
27 changes: 27 additions & 0 deletions pkg/tsdb/prometheus/buffered/client_test.go
@@ -0,0 +1,27 @@
package buffered

import (
"testing"

"github.com/grafana/grafana-azure-sdk-go/azsettings"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/infra/log/logtest"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/stretchr/testify/require"
)

func TestCreateTransportOptions(t *testing.T) {
t.Run("creates correct options object", func(t *testing.T) {
settings := backend.DataSourceInstanceSettings{
BasicAuthEnabled: false,
BasicAuthUser: "",
JSONData: []byte(`{"httpHeaderName1": "foo"}`),
DecryptedSecureJSONData: map[string]string{
"httpHeaderValue1": "bar",
},
}
opts, err := CreateTransportOptions(settings, &azsettings.AzureSettings{}, featuremgmt.WithFeatures(), &logtest.Fake{})
require.NoError(t, err)
require.Equal(t, map[string]string{"foo": "bar"}, opts.Headers)
})
}
55 changes: 0 additions & 55 deletions pkg/tsdb/prometheus/client/cache.go

This file was deleted.

135 changes: 0 additions & 135 deletions pkg/tsdb/prometheus/client/cache_test.go

This file was deleted.

0 comments on commit 3df34fe

Please sign in to comment.