FeatureToggles: Add context and and an explicit global check (#78081)

This commit is contained in:
Ryan McKinley
2023-11-14 12:50:27 -08:00
committed by GitHub
parent c887ef2c9a
commit f69fd3726b
94 changed files with 228 additions and 208 deletions
+3 -2
View File
@@ -14,6 +14,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
"github.com/grafana/grafana-plugin-sdk-go/backend/tracing"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/tsdb/intervalv2"
"github.com/grafana/grafana/pkg/tsdb/prometheus/client"
@@ -73,7 +74,7 @@ func New(
// standard deviation sampler is the default for backwards compatibility
exemplarSampler := exemplar.NewStandardDeviationSampler
if features.IsEnabled(featuremgmt.FlagDisablePrometheusExemplarSampling) {
if features.IsEnabledGlobally(featuremgmt.FlagDisablePrometheusExemplarSampling) {
exemplarSampler = exemplar.NewNoOpSampler
}
@@ -85,7 +86,7 @@ func New(
TimeInterval: timeInterval,
ID: settings.ID,
URL: settings.URL,
enableDataplane: features.IsEnabled(featuremgmt.FlagPrometheusDataplane),
enableDataplane: features.IsEnabledGlobally(featuremgmt.FlagPrometheusDataplane),
exemplarSampler: exemplarSampler,
}, nil
}
+3 -10
View File
@@ -15,6 +15,7 @@ import (
p "github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/tsdb/prometheus/kinds/dataquery"
"github.com/grafana/kindsys"
@@ -23,6 +24,7 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tsdb/prometheus/client"
"github.com/grafana/grafana/pkg/tsdb/prometheus/models"
@@ -440,8 +442,7 @@ func setup() (*testContext, error) {
JSONData: json.RawMessage(`{"timeInterval": "15s"}`),
}
features := &fakeFeatureToggles{flags: map[string]bool{"prometheusBufferedClient": false}}
features := featuremgmt.WithFeatures()
opts, err := client.CreateTransportOptions(context.Background(), settings, &setting.Cfg{}, log.New())
if err != nil {
return nil, err
@@ -460,14 +461,6 @@ func setup() (*testContext, error) {
}, nil
}
type fakeFeatureToggles struct {
flags map[string]bool
}
func (f *fakeFeatureToggles) IsEnabled(feature string) bool {
return f.flags[feature]
}
type fakeHttpClientProvider struct {
httpclient.Provider
opts httpclient.Options