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

Prometheus: Remove cache, pass headers in request, simplify client creation for resource calls and custom client #51436

Merged
merged 3 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/services/featuremgmt/manager.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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.

Loading