Skip to content

Commit d52d04b

Browse files
Revert "Use dw dynamic config" (grafana#91846)
Revert "Use dw dynamic config (grafana#91222)" This reverts commit 0258842.
1 parent b4db8bb commit d52d04b

File tree

14 files changed

+70
-31
lines changed

14 files changed

+70
-31
lines changed

docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Most [generally available](https://grafana.com/docs/release-life-cycle/#general-
5050
| `panelMonitoring` | Enables panel monitoring through logs and measurements | Yes |
5151
| `formatString` | Enable format string transformer | Yes |
5252
| `transformationsVariableSupport` | Allows using variables in transformations | Yes |
53+
| `kubernetesPlaylists` | Use the kubernetes API in the frontend for playlists, and route /api/playlist requests to k8s | Yes |
5354
| `recoveryThreshold` | Enables feature recovery threshold (aka hysteresis) for threshold server-side expression | Yes |
5455
| `lokiStructuredMetadata` | Enables the loki data source to request structured metadata from the Loki server | Yes |
5556
| `managedPluginsInstall` | Install managed plugins directly from plugins catalog | Yes |

packages/grafana-data/src/types/featureToggles.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export interface FeatureToggles {
113113
disableClassicHTTPHistogram?: boolean;
114114
formatString?: boolean;
115115
transformationsVariableSupport?: boolean;
116+
kubernetesPlaylists?: boolean;
116117
kubernetesSnapshots?: boolean;
117118
kubernetesDashboards?: boolean;
118119
datasourceQueryTypes?: boolean;

packages/grafana-runtime/src/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ export class GrafanaBootConfig implements GrafanaConfig {
185185
cloudMigrationPollIntervalMs = 2000;
186186
reportingStaticContext?: Record<string, string>;
187187
exploreDefaultTimeOffset = '1h';
188-
unifiedStorage: Map<string, number> = new Map<string, number>();
189188

190189
/**
191190
* Language used in Grafana's UI. This is after the user's preference (or deteceted locale) is resolved to one of

pkg/api/playlist.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import (
1212
"github.com/grafana/grafana/pkg/api/dtos"
1313
"github.com/grafana/grafana/pkg/api/response"
1414
"github.com/grafana/grafana/pkg/api/routing"
15-
playlistalpha1 "github.com/grafana/grafana/pkg/apis/playlist/v0alpha1"
15+
"github.com/grafana/grafana/pkg/apis/playlist/v0alpha1"
1616
"github.com/grafana/grafana/pkg/middleware"
1717
internalplaylist "github.com/grafana/grafana/pkg/registry/apis/playlist"
1818
grafanaapiserver "github.com/grafana/grafana/pkg/services/apiserver"
1919
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
2020
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
21+
"github.com/grafana/grafana/pkg/services/featuremgmt"
2122
"github.com/grafana/grafana/pkg/services/playlist"
2223
"github.com/grafana/grafana/pkg/util/errhttp"
2324
"github.com/grafana/grafana/pkg/web"
@@ -26,8 +27,7 @@ import (
2627
func (hs *HTTPServer) registerPlaylistAPI(apiRoute routing.RouteRegister) {
2728
// Register the actual handlers
2829
apiRoute.Group("/playlists", func(playlistRoute routing.RouteRegister) {
29-
unifiedStorageOptions := hs.Cfg.UnifiedStorage
30-
if mode, ok := unifiedStorageOptions[playlistalpha1.GROUPRESOURCE]; ok && mode > 0 {
30+
if hs.Features.IsEnabledGlobally(featuremgmt.FlagKubernetesPlaylists) {
3131
// Use k8s client to implement legacy API
3232
handler := newPlaylistK8sHandler(hs)
3333
playlistRoute.Get("/", handler.searchPlaylists)
@@ -330,7 +330,7 @@ type playlistK8sHandler struct {
330330

331331
func newPlaylistK8sHandler(hs *HTTPServer) *playlistK8sHandler {
332332
return &playlistK8sHandler{
333-
gvr: playlistalpha1.PlaylistResourceInfo.GroupVersionResource(),
333+
gvr: v0alpha1.PlaylistResourceInfo.GroupVersionResource(),
334334
namespacer: request.GetNamespaceMapper(hs.Cfg),
335335
clientConfigProvider: hs.clientConfigProvider,
336336
}

pkg/services/apiserver/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
```ini
66
[feature_toggles]
7+
kubernetesPlaylists = true
78
```
89

910
Start Grafana:
@@ -61,10 +62,8 @@ For kubectl to work, grafana needs to run over https. To simplify development,
6162
app_mode = development
6263

6364
[feature_toggles]
64-
grafanaAPIServerEnsureKubectlAccess = true
65-
66-
[unified_storage]
67-
playlists.playlist.grafana.app = 2
65+
grafanaAPIServerEnsureKubectlAccess = true
66+
kubernetesPlaylists = true
6867
```
6968

7069
This will create a development kubeconfig and start a parallel ssl listener. It can be registered by
@@ -91,4 +90,4 @@ The folder structure aims to follow the patterns established in standard (https:
9190
* [pkg/apis](/pkg/apis) - where API resource types are defined. this is based on the structure of the [sample-apiserver](https://github.com/kubernetes/sample-apiserver/tree/master/pkg/apis)
9291
* [hack/update-codegen.sh](/hack#kubernetes-hack-alert) - this script is used to run [k8s codegen](https://github.com/kubernetes/code-generator/), which generates the code that is used by the API server to handle the types defined in `pkg/apis`. it is based on the [update-codegen.sh from sample-apiserver](https://github.com/kubernetes/sample-apiserver/blob/master/hack/update-codegen.sh)
9392
* [pkg/registry/apis](/pkg/registry/apis) - where all of the types in `pkg/apis` are registered with the API server by implementing the [builder](/pkg/services/apiserver/builder/common.go#L18) interface. this pattern is unique to grafana, and is needed to support using wire dependencies in legacy storage implementations. this is separated from `pkg/apis` to avoid issues with k8s codegen.
94-
* [pkg/cmd/grafana/apiserver](/pkg/cmd/grafana/apiserver) - this is where the apiserver is configured for the `grafana apiserver` CLI command, which can be used to launch standalone API servers. this will eventually be merged with the config in `pkg/services/apiserver` to reduce duplication.
93+
* [pkg/cmd/grafana/apiserver](/pkg/cmd/grafana/apiserver) - this is where the apiserver is configured for the `grafana apiserver` CLI command, which can be used to launch standalone API servers. this will eventually be merged with the config in `pkg/services/apiserver` to reduce duplication.

pkg/services/apiserver/config.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strconv"
88

99
playlist "github.com/grafana/grafana/pkg/apis/playlist/v0alpha1"
10+
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
1011
"github.com/grafana/grafana/pkg/services/apiserver/options"
1112
"github.com/grafana/grafana/pkg/services/featuremgmt"
1213
"github.com/grafana/grafana/pkg/setting"
@@ -54,16 +55,14 @@ func applyGrafanaConfig(cfg *setting.Cfg, features featuremgmt.FeatureToggles, o
5455
o.StorageOptions.StorageType = options.StorageType(apiserverCfg.Key("storage_type").MustString(string(options.StorageTypeLegacy)))
5556
o.StorageOptions.DataPath = apiserverCfg.Key("storage_path").MustString(filepath.Join(cfg.DataPath, "grafana-apiserver"))
5657
o.StorageOptions.Address = apiserverCfg.Key("address").MustString(o.StorageOptions.Address)
57-
58-
// unified storage modes
59-
unifiedStorageCfg := cfg.UnifiedStorage
60-
o.StorageOptions.DualWriterDesiredModes = unifiedStorageCfg
58+
o.StorageOptions.DualWriterDesiredModes = map[string]grafanarest.DualWriterMode{
59+
// TODO: use the new config from HGAPI after https://github.com/grafana/hosted-grafana/pull/5707
60+
playlist.GROUPRESOURCE: 2,
61+
}
6162

6263
// TODO: ensure backwards compatibility with production
63-
// remove this after changing the unified_storage key format in HGAPI
64-
if _, ok := o.StorageOptions.DualWriterDesiredModes[playlist.RESOURCE+"."+playlist.GROUP]; ok {
65-
o.StorageOptions.DualWriterDesiredModes[playlist.RESOURCE+"."+playlist.GROUP] = o.StorageOptions.DualWriterDesiredModes[playlist.GROUPRESOURCE]
66-
}
64+
// remove this after changing the unified_storage_mode key format in HGAPI
65+
o.StorageOptions.DualWriterDesiredModes[playlist.RESOURCE+"."+playlist.GROUP] = o.StorageOptions.DualWriterDesiredModes[playlist.GROUPRESOURCE]
6766

6867
o.ExtraOptions.DevMode = features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerEnsureKubectlAccess)
6968
o.ExtraOptions.ExternalAddress = host

pkg/services/featuremgmt/registry.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,14 @@ var (
721721
Owner: grafanaDatavizSquad,
722722
Expression: "true", // Enabled by default
723723
},
724+
{
725+
Name: "kubernetesPlaylists",
726+
Description: "Use the kubernetes API in the frontend for playlists, and route /api/playlist requests to k8s",
727+
Stage: FeatureStageGeneralAvailability,
728+
Owner: grafanaAppPlatformSquad,
729+
Expression: "true",
730+
RequiresRestart: true, // changes the API routing
731+
},
724732
{
725733
Name: "kubernetesSnapshots",
726734
Description: "Routes snapshot requests from /api to the /apis endpoint",

pkg/services/featuremgmt/toggles_gen.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ enableNativeHTTPHistogram,experimental,@grafana/grafana-backend-services-squad,f
9494
disableClassicHTTPHistogram,experimental,@grafana/grafana-backend-services-squad,false,true,false
9595
formatString,GA,@grafana/dataviz-squad,false,false,true
9696
transformationsVariableSupport,GA,@grafana/dataviz-squad,false,false,true
97+
kubernetesPlaylists,GA,@grafana/grafana-app-platform-squad,false,true,false
9798
kubernetesSnapshots,experimental,@grafana/grafana-app-platform-squad,false,true,false
9899
kubernetesDashboards,experimental,@grafana/grafana-app-platform-squad,false,false,true
99100
datasourceQueryTypes,experimental,@grafana/grafana-app-platform-squad,false,true,false

pkg/services/featuremgmt/toggles_gen.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ const (
387387
// Allows using variables in transformations
388388
FlagTransformationsVariableSupport = "transformationsVariableSupport"
389389

390+
// FlagKubernetesPlaylists
391+
// Use the kubernetes API in the frontend for playlists, and route /api/playlist requests to k8s
392+
FlagKubernetesPlaylists = "kubernetesPlaylists"
393+
390394
// FlagKubernetesSnapshots
391395
// Routes snapshot requests from /api to the /apis endpoint
392396
FlagKubernetesSnapshots = "kubernetesSnapshots"

pkg/services/featuremgmt/toggles_gen.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,6 @@
14381438
"name": "kubernetesPlaylists",
14391439
"resourceVersion": "1720021873452",
14401440
"creationTimestamp": "2023-10-05T19:00:36Z",
1441-
"deletionTimestamp": "2024-07-30T19:34:12Z",
14421441
"annotations": {
14431442
"grafana.app/updatedTimestamp": "2024-07-03 15:51:13.452477 +0000 UTC"
14441443
}

pkg/setting/setting.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/grafana/grafana-plugin-sdk-go/backend/gtime"
3030

3131
"github.com/grafana/grafana/pkg/apimachinery/identity"
32-
grafanarest "github.com/grafana/grafana/pkg/apiserver/rest"
3332
"github.com/grafana/grafana/pkg/infra/log"
3433
"github.com/grafana/grafana/pkg/util"
3534
"github.com/grafana/grafana/pkg/util/osutil"
@@ -522,9 +521,6 @@ type Cfg struct {
522521

523522
//Short Links
524523
ShortLinkExpiration int
525-
526-
// Unified Storage
527-
UnifiedStorage map[string]grafanarest.DualWriterMode
528524
}
529525

530526
type InstallPlugin struct {

pkg/tests/apis/playlist/playlist_test.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,24 @@ func TestIntegrationPlaylist(t *testing.T) {
7777
]`, disco)
7878
})
7979

80+
t.Run("with k8s api flag", func(t *testing.T) {
81+
doPlaylistTests(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
82+
AppModeProduction: true, // do not start extra port 6443
83+
DisableAnonymous: true,
84+
EnableFeatureToggles: []string{
85+
featuremgmt.FlagKubernetesPlaylists, // <<< The change we are testing!
86+
},
87+
}))
88+
})
89+
8090
t.Run("with dual write (file, mode 0)", func(t *testing.T) {
8191
doPlaylistTests(t, apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{
8292
AppModeProduction: true,
8393
DisableAnonymous: true,
8494
APIServerStorageType: "file", // write the files to disk
95+
EnableFeatureToggles: []string{
96+
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
97+
},
8598
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
8699
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode0,
87100
},
@@ -93,6 +106,9 @@ func TestIntegrationPlaylist(t *testing.T) {
93106
AppModeProduction: true,
94107
DisableAnonymous: true,
95108
APIServerStorageType: "file", // write the files to disk
109+
EnableFeatureToggles: []string{
110+
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
111+
},
96112
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
97113
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode1,
98114
},
@@ -104,6 +120,9 @@ func TestIntegrationPlaylist(t *testing.T) {
104120
AppModeProduction: true,
105121
DisableAnonymous: true,
106122
APIServerStorageType: "file", // write the files to disk
123+
EnableFeatureToggles: []string{
124+
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
125+
},
107126
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
108127
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode2,
109128
},
@@ -115,6 +134,9 @@ func TestIntegrationPlaylist(t *testing.T) {
115134
AppModeProduction: true,
116135
DisableAnonymous: true,
117136
APIServerStorageType: "file", // write the files to disk
137+
EnableFeatureToggles: []string{
138+
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
139+
},
118140
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
119141
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode3,
120142
},
@@ -128,6 +150,7 @@ func TestIntegrationPlaylist(t *testing.T) {
128150
APIServerStorageType: "unified", // use the entity api tables
129151
EnableFeatureToggles: []string{
130152
featuremgmt.FlagUnifiedStorage,
153+
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
131154
},
132155
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
133156
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode0,
@@ -142,6 +165,7 @@ func TestIntegrationPlaylist(t *testing.T) {
142165
APIServerStorageType: "unified", // use the entity api tables
143166
EnableFeatureToggles: []string{
144167
featuremgmt.FlagUnifiedStorage,
168+
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
145169
},
146170
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
147171
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode1,
@@ -156,6 +180,7 @@ func TestIntegrationPlaylist(t *testing.T) {
156180
APIServerStorageType: "unified", // use the entity api tables
157181
EnableFeatureToggles: []string{
158182
featuremgmt.FlagUnifiedStorage,
183+
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
159184
},
160185
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
161186
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode2,
@@ -170,6 +195,7 @@ func TestIntegrationPlaylist(t *testing.T) {
170195
APIServerStorageType: "unified", // use the entity api tables
171196
EnableFeatureToggles: []string{
172197
featuremgmt.FlagUnifiedStorage,
198+
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
173199
},
174200
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
175201
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode3,
@@ -185,6 +211,9 @@ func TestIntegrationPlaylist(t *testing.T) {
185211
AppModeProduction: true,
186212
DisableAnonymous: true,
187213
APIServerStorageType: "etcd", // requires etcd running on localhost:2379
214+
EnableFeatureToggles: []string{
215+
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
216+
},
188217
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
189218
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode0,
190219
},
@@ -209,7 +238,9 @@ func TestIntegrationPlaylist(t *testing.T) {
209238
AppModeProduction: true,
210239
DisableAnonymous: true,
211240
APIServerStorageType: "etcd", // requires etcd running on localhost:2379
212-
EnableFeatureToggles: []string{},
241+
EnableFeatureToggles: []string{
242+
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
243+
},
213244
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
214245
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode1,
215246
},
@@ -234,7 +265,9 @@ func TestIntegrationPlaylist(t *testing.T) {
234265
AppModeProduction: true,
235266
DisableAnonymous: true,
236267
APIServerStorageType: "etcd", // requires etcd running on localhost:2379
237-
EnableFeatureToggles: []string{},
268+
EnableFeatureToggles: []string{
269+
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
270+
},
238271
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
239272
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode2,
240273
},
@@ -259,7 +292,9 @@ func TestIntegrationPlaylist(t *testing.T) {
259292
AppModeProduction: true,
260293
DisableAnonymous: true,
261294
APIServerStorageType: "etcd", // requires etcd running on localhost:2379
262-
EnableFeatureToggles: []string{},
295+
EnableFeatureToggles: []string{
296+
featuremgmt.FlagKubernetesPlaylists, // Required so that legacy calls are also written
297+
},
263298
DualWriterDesiredModes: map[string]grafanarest.DualWriterMode{
264299
playlistv0alpha1.GROUPRESOURCE: grafanarest.Mode3,
265300
},

pkg/tests/testinfra/testinfra.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func CreateGrafDir(t *testing.T, opts ...GrafanaOpts) (string, string) {
387387
}
388388

389389
if o.DualWriterDesiredModes != nil {
390-
unifiedStorageMode, err := getOrCreateSection("unified_storage")
390+
unifiedStorageMode, err := getOrCreateSection("unified_storage_mode")
391391
require.NoError(t, err)
392392
for k, v := range o.DualWriterDesiredModes {
393393
_, err = unifiedStorageMode.NewKey(k, fmt.Sprint(v))

public/app/features/playlist/api.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,5 @@ export function searchPlaylists(playlists: Playlist[], query?: string): Playlist
209209
}
210210

211211
export function getPlaylistAPI() {
212-
if (config.unifiedStorage) {
213-
return config.unifiedStorage.has('playlist.grafana.app/playlists') ? new K8sAPI() : new LegacyAPI();
214-
}
215-
return new LegacyAPI();
212+
return config.featureToggles.kubernetesPlaylists ? new K8sAPI() : new LegacyAPI();
216213
}

0 commit comments

Comments
 (0)