diff --git a/pkg/services/apiserver/builder/helper.go b/pkg/services/apiserver/builder/helper.go index 902ad4f5646..0e83cb4741c 100644 --- a/pkg/services/apiserver/builder/helper.go +++ b/pkg/services/apiserver/builder/helper.go @@ -178,6 +178,8 @@ func InstallAPIs( // this is needed to support setting a default RESTOptionsGetter for new APIs that don't // support the legacy storage type. var dualWrite grafanarest.DualWriteBuilder + + // nolint:staticcheck if storageOpts.StorageType != options.StorageTypeLegacy { dualWrite = func(gr schema.GroupResource, legacy grafanarest.LegacyStorage, storage grafanarest.Storage) (grafanarest.Storage, error) { key := gr.String() // ${resource}.{group} eg playlists.playlist.grafana.app diff --git a/pkg/services/apiserver/config.go b/pkg/services/apiserver/config.go index 66ed0b6a4eb..e8f41b685a8 100644 --- a/pkg/services/apiserver/config.go +++ b/pkg/services/apiserver/config.go @@ -50,7 +50,8 @@ func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o o.RecommendedOptions.Admission = nil o.RecommendedOptions.CoreAPI = nil - o.StorageOptions.StorageType = options.StorageType(apiserverCfg.Key("storage_type").MustString(string(options.StorageTypeLegacy))) + // nolint:staticcheck + o.StorageOptions.StorageType = options.StorageType(apiserverCfg.Key("storage_type").MustString(string(options.StorageTypeUnified))) o.StorageOptions.DataPath = apiserverCfg.Key("storage_path").MustString(filepath.Join(cfg.DataPath, "grafana-apiserver")) o.StorageOptions.Address = apiserverCfg.Key("address").MustString(o.StorageOptions.Address) o.StorageOptions.BlobStoreURL = apiserverCfg.Key("blob_url").MustString(o.StorageOptions.BlobStoreURL) diff --git a/pkg/services/apiserver/options/storage.go b/pkg/services/apiserver/options/storage.go index d8ee2674aa5..4841112fedf 100644 --- a/pkg/services/apiserver/options/storage.go +++ b/pkg/services/apiserver/options/storage.go @@ -17,9 +17,11 @@ type StorageType string const ( StorageTypeFile StorageType = "file" StorageTypeEtcd StorageType = "etcd" - StorageTypeLegacy StorageType = "legacy" StorageTypeUnified StorageType = "unified" StorageTypeUnifiedGrpc StorageType = "unified-grpc" + + // Deprecated: legacy is a shim that is no longer necessary + StorageTypeLegacy StorageType = "legacy" ) type StorageOptions struct { @@ -45,7 +47,7 @@ type StorageOptions struct { func NewStorageOptions() *StorageOptions { return &StorageOptions{ - StorageType: StorageTypeLegacy, + StorageType: StorageTypeUnified, Address: "localhost:10000", } } @@ -59,9 +61,13 @@ func (o *StorageOptions) AddFlags(fs *pflag.FlagSet) { func (o *StorageOptions) Validate() []error { errs := []error{} switch o.StorageType { - case StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc: + // nolint:staticcheck + case StorageTypeLegacy: + // no-op + case StorageTypeFile, StorageTypeEtcd, StorageTypeUnified, StorageTypeUnifiedGrpc: // no-op default: + // nolint:staticcheck errs = append(errs, fmt.Errorf("--grafana-apiserver-storage-type must be one of %s, %s, %s, %s, %s", StorageTypeFile, StorageTypeEtcd, StorageTypeLegacy, StorageTypeUnified, StorageTypeUnifiedGrpc)) } @@ -84,6 +90,7 @@ func (o *StorageOptions) ApplyTo(serverConfig *genericapiserver.RecommendedConfi // EnforceFeatureToggleAfterMode1 makes sure there is a feature toggle set for resources with DualWriterMode > 1. // This is needed to ensure that we use the K8s client before enabling dual writing. func (o *StorageOptions) EnforceFeatureToggleAfterMode1(features featuremgmt.FeatureToggles) error { + // nolint:staticcheck if o.StorageType != StorageTypeLegacy { for rg, s := range o.UnifiedStorageConfig { if s.DualWriterMode > 1 { diff --git a/pkg/services/apiserver/options/storage_test.go b/pkg/services/apiserver/options/storage_test.go index 72e052eeb03..540dcac4fdc 100644 --- a/pkg/services/apiserver/options/storage_test.go +++ b/pkg/services/apiserver/options/storage_test.go @@ -3,9 +3,10 @@ package options import ( "testing" + "github.com/stretchr/testify/assert" + "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/setting" - "github.com/stretchr/testify/assert" ) func TestStorageOptions_CheckFeatureToggle(t *testing.T) { @@ -18,7 +19,7 @@ func TestStorageOptions_CheckFeatureToggle(t *testing.T) { }{ { name: "with legacy storage", - StorageType: StorageTypeLegacy, + StorageType: StorageTypeLegacy, // nolint:staticcheck UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{"playlists.playlist.grafana.app": {DualWriterMode: 2}}, features: featuremgmt.WithFeatures(), }, diff --git a/pkg/storage/unified/client.go b/pkg/storage/unified/client.go index 3c45d2135e4..558a0b05187 100644 --- a/pkg/storage/unified/client.go +++ b/pkg/storage/unified/client.go @@ -41,7 +41,7 @@ func ProvideUnifiedStorageClient( // See: apiserver.ApplyGrafanaConfig(cfg, features, o) apiserverCfg := cfg.SectionWithEnvOverrides("grafana-apiserver") client, err := newClient(options.StorageOptions{ - StorageType: options.StorageType(apiserverCfg.Key("storage_type").MustString(string(options.StorageTypeLegacy))), + StorageType: options.StorageType(apiserverCfg.Key("storage_type").MustString(string(options.StorageTypeUnified))), DataPath: apiserverCfg.Key("storage_path").MustString(filepath.Join(cfg.DataPath, "grafana-apiserver")), Address: apiserverCfg.Key("address").MustString(""), // client address BlobStoreURL: apiserverCfg.Key("blob_url").MustString(""), diff --git a/pkg/tests/api/alerting/api_alertmanager_test.go b/pkg/tests/api/alerting/api_alertmanager_test.go index a4dcb3862b5..d51faf1c531 100644 --- a/pkg/tests/api/alerting/api_alertmanager_test.go +++ b/pkg/tests/api/alerting/api_alertmanager_test.go @@ -22,7 +22,6 @@ import ( "github.com/grafana/grafana/pkg/expr" "github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/tracing" - "github.com/grafana/grafana/pkg/services/apiserver/options" apimodels "github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions" ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models" ngstore "github.com/grafana/grafana/pkg/services/ngalert/store" @@ -702,7 +701,6 @@ func TestIntegrationDeleteFolderWithRules(t *testing.T) { DisableAnonymous: true, ViewersCanEdit: true, AppModeProduction: true, - APIServerStorageType: options.StorageTypeLegacy, } // Setup Grafana and its Database