From 303777e682758076d6a8e1df6b82f97b3b2393a7 Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Wed, 12 Apr 2023 14:20:43 +0200 Subject: [PATCH] Elasticsearch: Add feature toggle to disable running queries trough backend (#66260) * Elasticsearch: Create feature toggle to disable running queries trough backend * Fix frontend tests running trough frontend * Update description of feature toggle --- .../feature-toggles/index.md | 61 +++++++++---------- .../src/types/featureToggles.gen.ts | 3 +- pkg/services/featuremgmt/registry.go | 18 ++---- pkg/services/featuremgmt/toggles_gen.csv | 3 +- pkg/services/featuremgmt/toggles_gen.go | 12 ++-- .../elasticsearch/datasource.test.ts | 6 ++ .../datasource/elasticsearch/datasource.ts | 13 ++-- 7 files changed, 52 insertions(+), 64 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 5b8a2f758e7..67f03b425c3 100644 --- a/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md +++ b/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md @@ -19,39 +19,39 @@ This page contains a list of available feature toggles. To learn how to turn on Some stable features are enabled by default. You can disable a stable feature by setting the feature flag to "false" in the configuration. -| Feature toggle name | Description | Enabled by default | -| ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | -| `disableEnvelopeEncryption` | Disable envelope encryption (emergency only) | | -| `database_metrics` | Add Prometheus metrics for database tables | | -| `featureHighlights` | Highlight Grafana Enterprise features | | -| `cloudWatchDynamicLabels` | Use dynamic labels instead of alias patterns in CloudWatch datasource | Yes | -| `dataConnectionsConsole` | Enables a new top-level page called Connections. This page is an experiment that provides a better experience when you install and configure data sources and other plugins. | Yes | -| `internationalization` | Enables internationalization | Yes | -| `topnav` | Enables new top navigation and page layouts | Yes | -| `cloudWatchCrossAccountQuerying` | Enables cross-account querying in CloudWatch datasources | Yes | -| `newPanelChromeUI` | Show updated look and feel of grafana-ui PanelChrome: panel header, icons, and menu | Yes | -| `accessTokenExpirationCheck` | Enable OAuth access_token expiration check and token refresh using the refresh_token | | -| `emptyDashboardPage` | Enable the redesigned user interface of a dashboard page that includes no panels | Yes | -| `disablePrometheusExemplarSampling` | Disable Prometheus exemplar sampling | | -| `logsSampleInExplore` | Enables access to the logs sample feature in Explore | Yes | +| Feature toggle name | Description | Enabled by default | +| ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | +| `disableEnvelopeEncryption` | Disable envelope encryption (emergency only) | | +| `database_metrics` | Add Prometheus metrics for database tables | | +| `featureHighlights` | Highlight Grafana Enterprise features | | +| `cloudWatchDynamicLabels` | Use dynamic labels instead of alias patterns in CloudWatch datasource | Yes | +| `dataConnectionsConsole` | Enables a new top-level page called Connections. This page is an experiment that provides a better experience when you install and configure data sources and other plugins. | Yes | +| `internationalization` | Enables internationalization | Yes | +| `topnav` | Enables new top navigation and page layouts | Yes | +| `cloudWatchCrossAccountQuerying` | Enables cross-account querying in CloudWatch datasources | Yes | +| `newPanelChromeUI` | Show updated look and feel of grafana-ui PanelChrome: panel header, icons, and menu | Yes | +| `accessTokenExpirationCheck` | Enable OAuth access_token expiration check and token refresh using the refresh_token | | +| `emptyDashboardPage` | Enable the redesigned user interface of a dashboard page that includes no panels | Yes | +| `disablePrometheusExemplarSampling` | Disable Prometheus exemplar sampling | | +| `logsSampleInExplore` | Enables access to the logs sample feature in Explore | Yes | +| `disableElasticsearchBackendQuerying` | Disable the processing of queries and responses in the Elasticsearch data source through backend | | ## Beta feature toggles -| Feature toggle name | Description | -| ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `trimDefaults` | Use cue schema to remove values that will be applied automatically | -| `panelTitleSearch` | Search for dashboards using panel title | -| `prometheusAzureOverrideAudience` | Experimental. Allow override default AAD audience for Azure Prometheus endpoint | -| `migrationLocking` | Lock database during migrations | -| `newDBLibrary` | Use jmoiron/sqlx rather than xorm for a few backend services | -| `validateDashboardsOnSave` | Validate dashboard JSON POSTed to api/dashboards/db | -| `autoMigrateOldPanels` | Migrate old angular panels to supported versions (graph, table-old, worldmap, etc) | -| `disableAngular` | Dynamic flag to disable angular at runtime. The preferred method is to set `angular_support_enabled` to `false` in the [security] settings, which allows you to change the state at runtime. | -| `grpcServer` | Run the GRPC server | -| `accessControlOnCall` | Access control primitives for OnCall | -| `alertingNoNormalState` | Stop maintaining state of alerts that are not firing | -| `disableElasticsearchBackendExploreQuery` | Disable executing of Elasticsearch Explore queries trough backend | -| `renderAuthJWT` | Uses JWT-based auth for rendering instead of relying on remote cache | +| Feature toggle name | Description | +| --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `trimDefaults` | Use cue schema to remove values that will be applied automatically | +| `panelTitleSearch` | Search for dashboards using panel title | +| `prometheusAzureOverrideAudience` | Experimental. Allow override default AAD audience for Azure Prometheus endpoint | +| `migrationLocking` | Lock database during migrations | +| `newDBLibrary` | Use jmoiron/sqlx rather than xorm for a few backend services | +| `validateDashboardsOnSave` | Validate dashboard JSON POSTed to api/dashboards/db | +| `autoMigrateOldPanels` | Migrate old angular panels to supported versions (graph, table-old, worldmap, etc) | +| `disableAngular` | Dynamic flag to disable angular at runtime. The preferred method is to set `angular_support_enabled` to `false` in the [security] settings, which allows you to change the state at runtime. | +| `grpcServer` | Run the GRPC server | +| `accessControlOnCall` | Access control primitives for OnCall | +| `alertingNoNormalState` | Stop maintaining state of alerts that are not firing | +| `renderAuthJWT` | Uses JWT-based auth for rendering instead of relying on remote cache | ## Alpha feature toggles @@ -82,7 +82,6 @@ Alpha features might be changed or removed without prior notice. | `athenaAsyncQueryDataSupport` | Enable async query data support for Athena | | `showDashboardValidationWarnings` | Show warnings when dashboards do not validate against the schema | | `mysqlAnsiQuotes` | Use double quotes to escape keyword in a MySQL query | -| `elasticsearchBackendMigration` | Use Elasticsearch as backend data source | | `showTraceId` | Show trace ids for requests | | `datasourceOnboarding` | Enable data source onboarding page | | `secureSocksDatasourceProxy` | Enable secure socks tunneling for supported core datasources | diff --git a/packages/grafana-data/src/types/featureToggles.gen.ts b/packages/grafana-data/src/types/featureToggles.gen.ts index d8fea398788..8e43df06807 100644 --- a/packages/grafana-data/src/types/featureToggles.gen.ts +++ b/packages/grafana-data/src/types/featureToggles.gen.ts @@ -63,7 +63,6 @@ export interface FeatureToggles { accessControlOnCall?: boolean; nestedFolders?: boolean; accessTokenExpirationCheck?: boolean; - elasticsearchBackendMigration?: boolean; showTraceId?: boolean; datasourceOnboarding?: boolean; emptyDashboardPage?: boolean; @@ -86,7 +85,6 @@ export interface FeatureToggles { prometheusResourceBrowserCache?: boolean; influxdbBackendMigration?: boolean; clientTokenRotation?: boolean; - disableElasticsearchBackendExploreQuery?: boolean; prometheusDataplane?: boolean; alertStateHistoryLokiSecondary?: boolean; alertStateHistoryLokiPrimary?: boolean; @@ -96,4 +94,5 @@ export interface FeatureToggles { pyroscopeFlameGraph?: boolean; externalServiceAuth?: boolean; dataplaneFrontendFallback?: boolean; + disableElasticsearchBackendQuerying?: boolean; } diff --git a/pkg/services/featuremgmt/registry.go b/pkg/services/featuremgmt/registry.go index 8751d8b34cb..80c1b20e915 100644 --- a/pkg/services/featuremgmt/registry.go +++ b/pkg/services/featuremgmt/registry.go @@ -303,12 +303,6 @@ var ( State: FeatureStateStable, Owner: grafanaAuthnzSquad, }, - { - Name: "elasticsearchBackendMigration", - Description: "Use Elasticsearch as backend data source", - State: FeatureStateAlpha, - Owner: grafanaObservabilityLogsSquad, - }, { Name: "showTraceId", Description: "Show trace ids for requests", @@ -457,12 +451,6 @@ var ( State: FeatureStateAlpha, Owner: grafanaAuthnzSquad, }, - { - Name: "disableElasticsearchBackendExploreQuery", - Description: "Disable executing of Elasticsearch Explore queries trough backend", - State: FeatureStateBeta, - Owner: grafanaObservabilityLogsSquad, - }, { Name: "prometheusDataplane", Description: "Changes responses to from Prometheus to be compliant with the dataplane specification. In particular it sets the numeric Field.Name from 'Value' to the value of the `__name__` label when present.", @@ -519,5 +507,11 @@ var ( FrontendOnly: true, Owner: grafanaObservabilityMetricsSquad, }, + { + Name: "disableElasticsearchBackendQuerying", + Description: "Disable the processing of queries and responses in the Elasticsearch data source through backend", + State: FeatureStateStable, + Owner: grafanaObservabilityLogsSquad, + }, } ) diff --git a/pkg/services/featuremgmt/toggles_gen.csv b/pkg/services/featuremgmt/toggles_gen.csv index b4a0d44b016..39e4fdd58b4 100644 --- a/pkg/services/featuremgmt/toggles_gen.csv +++ b/pkg/services/featuremgmt/toggles_gen.csv @@ -44,7 +44,6 @@ mysqlAnsiQuotes,alpha,@grafana/backend-platform,false,false,false,false accessControlOnCall,beta,@grafana/grafana-authnz-team,false,false,false,false nestedFolders,alpha,@grafana/backend-platform,true,false,false,false accessTokenExpirationCheck,stable,@grafana/grafana-authnz-team,false,false,false,false -elasticsearchBackendMigration,alpha,@grafana/observability-logs,false,false,false,false showTraceId,alpha,@grafana/observability-logs,false,false,false,false datasourceOnboarding,alpha,@grafana/dashboards-squad,false,false,false,false emptyDashboardPage,stable,@grafana/dashboards-squad,false,false,false,true @@ -67,7 +66,6 @@ timeSeriesTable,alpha,@grafana/app-o11y,false,false,false,true prometheusResourceBrowserCache,alpha,@grafana/observability-metrics,false,false,false,true influxdbBackendMigration,alpha,@grafana/observability-metrics,false,false,false,true clientTokenRotation,alpha,@grafana/grafana-authnz-team,false,false,false,false -disableElasticsearchBackendExploreQuery,beta,@grafana/observability-logs,false,false,false,false prometheusDataplane,alpha,@grafana/observability-metrics,false,false,false,false alertStateHistoryLokiSecondary,alpha,@grafana/alerting-squad,false,false,false,false alertStateHistoryLokiPrimary,alpha,@grafana/alerting-squad,false,false,false,false @@ -77,3 +75,4 @@ renderAuthJWT,beta,@grafana/grafana-as-code,false,false,false,false pyroscopeFlameGraph,alpha,@grafana/observability-traces-and-profiling,false,false,false,false externalServiceAuth,alpha,@grafana/grafana-authnz-team,true,false,false,false dataplaneFrontendFallback,alpha,@grafana/observability-metrics,false,false,false,true +disableElasticsearchBackendQuerying,stable,@grafana/observability-logs,false,false,false,false diff --git a/pkg/services/featuremgmt/toggles_gen.go b/pkg/services/featuremgmt/toggles_gen.go index f79f1cf9c9e..22518a70146 100644 --- a/pkg/services/featuremgmt/toggles_gen.go +++ b/pkg/services/featuremgmt/toggles_gen.go @@ -187,10 +187,6 @@ const ( // Enable OAuth access_token expiration check and token refresh using the refresh_token FlagAccessTokenExpirationCheck = "accessTokenExpirationCheck" - // FlagElasticsearchBackendMigration - // Use Elasticsearch as backend data source - FlagElasticsearchBackendMigration = "elasticsearchBackendMigration" - // FlagShowTraceId // Show trace ids for requests FlagShowTraceId = "showTraceId" @@ -279,10 +275,6 @@ const ( // Replaces the current in-request token rotation so that the client initiates the rotation FlagClientTokenRotation = "clientTokenRotation" - // FlagDisableElasticsearchBackendExploreQuery - // Disable executing of Elasticsearch Explore queries trough backend - FlagDisableElasticsearchBackendExploreQuery = "disableElasticsearchBackendExploreQuery" - // FlagPrometheusDataplane // Changes responses to from Prometheus to be compliant with the dataplane specification. In particular it sets the numeric Field.Name from 'Value' to the value of the `__name__` label when present. FlagPrometheusDataplane = "prometheusDataplane" @@ -318,4 +310,8 @@ const ( // FlagDataplaneFrontendFallback // Support dataplane contract field name change for transformations and field name matchers where the name is different FlagDataplaneFrontendFallback = "dataplaneFrontendFallback" + + // FlagDisableElasticsearchBackendQuerying + // Disable the processing of queries and responses in the Elasticsearch data source through backend + FlagDisableElasticsearchBackendQuerying = "disableElasticsearchBackendQuerying" ) diff --git a/public/app/plugins/datasource/elasticsearch/datasource.test.ts b/public/app/plugins/datasource/elasticsearch/datasource.test.ts index b470338f836..4936257d09c 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.test.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.test.ts @@ -43,6 +43,12 @@ jest.mock('@grafana/runtime', () => ({ }, }; }, + config: { + buildInfo: {}, + featureToggles: { + disableElasticsearchBackendQuerying: true, + }, + }, })); const TIMESRV_START = [2022, 8, 21, 6, 10, 10]; diff --git a/public/app/plugins/datasource/elasticsearch/datasource.ts b/public/app/plugins/datasource/elasticsearch/datasource.ts index 04f2183feb9..612da1585ff 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.ts @@ -501,8 +501,8 @@ export class ElasticDatasource } getLogRowContext = async (row: LogRowModel, options?: RowContextOptions): Promise<{ data: DataFrame[] }> => { - const { disableElasticsearchBackendExploreQuery, elasticsearchBackendMigration } = config.featureToggles; - if (!disableElasticsearchBackendExploreQuery || elasticsearchBackendMigration) { + const { disableElasticsearchBackendQuerying } = config.featureToggles; + if (!disableElasticsearchBackendQuerying) { const contextRequest = this.makeLogContextDataRequest(row, options); return lastValueFrom( @@ -679,13 +679,8 @@ export class ElasticDatasource } query(request: DataQueryRequest): Observable { - // Run request through backend if it is coming from Explore and disableElasticsearchBackendExploreQuery is not set - // or if elasticsearchBackendMigration feature toggle is enabled - const { elasticsearchBackendMigration, disableElasticsearchBackendExploreQuery } = config.featureToggles; - const shouldRunTroughBackend = - (request.app === CoreApp.Explore && !disableElasticsearchBackendExploreQuery) || elasticsearchBackendMigration; - - if (shouldRunTroughBackend) { + const { disableElasticsearchBackendQuerying } = config.featureToggles; + if (!disableElasticsearchBackendQuerying) { const start = new Date(); return super.query(request).pipe(tap((response) => trackQuery(response, request, start))); }