From 644a16048f034f6bc79883678f1f1a4b48233483 Mon Sep 17 00:00:00 2001 From: Stephanie Hingtgen Date: Tue, 15 Oct 2024 13:30:05 -0600 Subject: [PATCH] K8s: add feature toggle for dashboard backend (#94753) --- .../feature-toggles/index.md | 1 + .../src/types/featureToggles.gen.ts | 1 + pkg/registry/apis/dashboard/register.go | 4 +-- pkg/services/featuremgmt/registry.go | 7 +++++ pkg/services/featuremgmt/toggles_gen.csv | 1 + pkg/services/featuremgmt/toggles_gen.go | 4 +++ pkg/services/featuremgmt/toggles_gen.json | 13 +++++++++ pkg/tests/apis/dashboard/dashboards_test.go | 27 ++++++++----------- 8 files changed, 40 insertions(+), 18 deletions(-) diff --git a/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md b/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md index 46c13858bb3..a2d48a065ef 100644 --- a/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md +++ b/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md @@ -165,6 +165,7 @@ Experimental features might be changed or removed without prior notice. | `disableClassicHTTPHistogram` | Disables classic HTTP Histogram (use with enableNativeHTTPHistogram) | | `kubernetesSnapshots` | Routes snapshot requests from /api to the /apis endpoint | | `kubernetesDashboards` | Use the kubernetes API in the frontend for dashboards | +| `kubernetesDashboardsAPI` | Use the kubernetes API in the backend for dashboards | | `kubernetesFolders` | Use the kubernetes API in the frontend for folders, and route /api/folders requests to k8s | | `grafanaAPIServerTestingWithExperimentalAPIs` | Facilitate integration testing of experimental APIs | | `datasourceQueryTypes` | Show query type endpoints in datasource API servers (currently hardcoded for testdata, expressions, and prometheus) | diff --git a/packages/grafana-data/src/types/featureToggles.gen.ts b/packages/grafana-data/src/types/featureToggles.gen.ts index 83738ec5cf1..964ccbc97f6 100644 --- a/packages/grafana-data/src/types/featureToggles.gen.ts +++ b/packages/grafana-data/src/types/featureToggles.gen.ts @@ -116,6 +116,7 @@ export interface FeatureToggles { kubernetesPlaylists?: boolean; kubernetesSnapshots?: boolean; kubernetesDashboards?: boolean; + kubernetesDashboardsAPI?: boolean; kubernetesFolders?: boolean; grafanaAPIServerTestingWithExperimentalAPIs?: boolean; datasourceQueryTypes?: boolean; diff --git a/pkg/registry/apis/dashboard/register.go b/pkg/registry/apis/dashboard/register.go index 26b38f0b791..d5ff691180a 100644 --- a/pkg/registry/apis/dashboard/register.go +++ b/pkg/registry/apis/dashboard/register.go @@ -56,8 +56,8 @@ func RegisterAPIService(cfg *setting.Cfg, features featuremgmt.FeatureToggles, tracing *tracing.TracingService, unified resource.ResourceClient, ) *DashboardsAPIBuilder { - if !features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs) { - return nil // skip registration unless opting into experimental apis + if !features.IsEnabledGlobally(featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs) && !features.IsEnabledGlobally(featuremgmt.FlagKubernetesDashboardsAPI) { + return nil // skip registration unless opting into experimental apis or dashboards in the k8s api } softDelete := features.IsEnabledGlobally(featuremgmt.FlagDashboardRestore) diff --git a/pkg/services/featuremgmt/registry.go b/pkg/services/featuremgmt/registry.go index 9034ce2fb89..d9766ec870e 100644 --- a/pkg/services/featuremgmt/registry.go +++ b/pkg/services/featuremgmt/registry.go @@ -743,6 +743,13 @@ var ( Owner: grafanaAppPlatformSquad, FrontendOnly: true, }, + { + Name: "kubernetesDashboardsAPI", + Description: "Use the kubernetes API in the backend for dashboards", + Stage: FeatureStageExperimental, + Owner: grafanaAppPlatformSquad, + RequiresRestart: true, // changes the API routing + }, { Name: "kubernetesFolders", Description: "Use the kubernetes API in the frontend for folders, and route /api/folders requests to k8s", diff --git a/pkg/services/featuremgmt/toggles_gen.csv b/pkg/services/featuremgmt/toggles_gen.csv index e65a21dd9b5..978bcbdb39b 100644 --- a/pkg/services/featuremgmt/toggles_gen.csv +++ b/pkg/services/featuremgmt/toggles_gen.csv @@ -97,6 +97,7 @@ transformationsVariableSupport,GA,@grafana/dataviz-squad,false,false,true kubernetesPlaylists,GA,@grafana/grafana-app-platform-squad,false,true,false kubernetesSnapshots,experimental,@grafana/grafana-app-platform-squad,false,true,false kubernetesDashboards,experimental,@grafana/grafana-app-platform-squad,false,false,true +kubernetesDashboardsAPI,experimental,@grafana/grafana-app-platform-squad,false,true,false kubernetesFolders,experimental,@grafana/search-and-storage,false,false,false grafanaAPIServerTestingWithExperimentalAPIs,experimental,@grafana/search-and-storage,false,false,false datasourceQueryTypes,experimental,@grafana/grafana-app-platform-squad,false,true,false diff --git a/pkg/services/featuremgmt/toggles_gen.go b/pkg/services/featuremgmt/toggles_gen.go index 31fe284f57f..221a413cdb3 100644 --- a/pkg/services/featuremgmt/toggles_gen.go +++ b/pkg/services/featuremgmt/toggles_gen.go @@ -399,6 +399,10 @@ const ( // Use the kubernetes API in the frontend for dashboards FlagKubernetesDashboards = "kubernetesDashboards" + // FlagKubernetesDashboardsAPI + // Use the kubernetes API in the backend for dashboards + FlagKubernetesDashboardsAPI = "kubernetesDashboardsAPI" + // FlagKubernetesFolders // Use the kubernetes API in the frontend for folders, and route /api/folders requests to k8s FlagKubernetesFolders = "kubernetesFolders" diff --git a/pkg/services/featuremgmt/toggles_gen.json b/pkg/services/featuremgmt/toggles_gen.json index f0486fc919b..35140c0d400 100644 --- a/pkg/services/featuremgmt/toggles_gen.json +++ b/pkg/services/featuremgmt/toggles_gen.json @@ -1644,6 +1644,19 @@ "frontend": true } }, + { + "metadata": { + "name": "kubernetesDashboardsAPI", + "resourceVersion": "1729017284006", + "creationTimestamp": "2024-10-15T18:34:44Z" + }, + "spec": { + "description": "Use the kubernetes API in the backend for dashboards", + "stage": "experimental", + "codeowner": "@grafana/grafana-app-platform-squad", + "requiresRestart": true + } + }, { "metadata": { "name": "kubernetesFeatureToggles", diff --git a/pkg/tests/apis/dashboard/dashboards_test.go b/pkg/tests/apis/dashboard/dashboards_test.go index 5bab84bf236..9031f2d94b9 100644 --- a/pkg/tests/apis/dashboard/dashboards_test.go +++ b/pkg/tests/apis/dashboard/dashboards_test.go @@ -117,10 +117,9 @@ func TestIntegrationDashboardsApp(t *testing.T) { t.Run("with dual writer mode 0", func(t *testing.T) { helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ - AppModeProduction: false, // required for experimental APIs - DisableAnonymous: true, + DisableAnonymous: true, EnableFeatureToggles: []string{ - featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, // Required to start the example service + featuremgmt.FlagKubernetesDashboardsAPI, featuremgmt.FlagKubernetesDashboards, }, UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ @@ -134,10 +133,9 @@ func TestIntegrationDashboardsApp(t *testing.T) { t.Run("with dual writer mode 1", func(t *testing.T) { helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ - AppModeProduction: false, // required for experimental APIs - DisableAnonymous: true, + DisableAnonymous: true, EnableFeatureToggles: []string{ - featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, // Required to start the example service + featuremgmt.FlagKubernetesDashboardsAPI, featuremgmt.FlagKubernetesDashboards, }, UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ @@ -151,10 +149,9 @@ func TestIntegrationDashboardsApp(t *testing.T) { t.Run("with dual writer mode 2", func(t *testing.T) { helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ - AppModeProduction: false, // required for experimental APIs - DisableAnonymous: true, + DisableAnonymous: true, EnableFeatureToggles: []string{ - featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, // Required to start the example service + featuremgmt.FlagKubernetesDashboardsAPI, featuremgmt.FlagKubernetesDashboards, }, UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ @@ -168,10 +165,9 @@ func TestIntegrationDashboardsApp(t *testing.T) { t.Run("with dual writer mode 3", func(t *testing.T) { helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ - AppModeProduction: false, // required for experimental APIs - DisableAnonymous: true, + DisableAnonymous: true, EnableFeatureToggles: []string{ - featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, // Required to start the example service + featuremgmt.FlagKubernetesDashboardsAPI, featuremgmt.FlagKubernetesDashboards, }, UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ @@ -185,10 +181,9 @@ func TestIntegrationDashboardsApp(t *testing.T) { t.Run("with dual writer mode 4", func(t *testing.T) { helper := apis.NewK8sTestHelper(t, testinfra.GrafanaOpts{ - AppModeProduction: false, // required for experimental APIs - DisableAnonymous: true, + DisableAnonymous: true, EnableFeatureToggles: []string{ - featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, // Required to start the example service + featuremgmt.FlagKubernetesDashboardsAPI, featuremgmt.FlagKubernetesDashboards, }, UnifiedStorageConfig: map[string]setting.UnifiedStorageConfig{ @@ -204,7 +199,7 @@ func TestIntegrationDashboardsApp(t *testing.T) { AppModeProduction: false, // required for experimental APIs DisableAnonymous: true, EnableFeatureToggles: []string{ - featuremgmt.FlagGrafanaAPIServerWithExperimentalAPIs, // Required to start the example service + featuremgmt.FlagKubernetesDashboardsAPI, // Required to start the example service }, })