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 a8007bd3342..22b0220bf3d 100644 --- a/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md +++ b/docs/sources/setup-grafana/configure-grafana/feature-toggles/index.md @@ -170,6 +170,7 @@ Experimental features might be changed or removed without prior notice. | `queryService` | Register /apis/query.grafana.app/ -- will eventually replace /api/ds/query | | `queryServiceRewrite` | Rewrite requests targeting /ds/query to the query service | | `queryServiceFromUI` | Routes requests to the new query service | +| `queryServiceFromExplore` | Routes explore requests to the new query service | | `cachingOptimizeSerializationMemoryUsage` | If enabled, the caching backend gradually serializes query responses for the cache, comparing against the configured `[caching]max_value_mb` value as it goes. This can can help prevent Grafana from running out of memory while attempting to cache very large query responses. | | `prometheusCodeModeMetricNamesSearch` | Enables search for metric names in Code Mode, to improve performance when working with an enormous number of metric names | | `alertmanagerRemoteSecondary` | Enable Grafana to sync configuration and state with a remote Alertmanager. | diff --git a/packages/grafana-data/src/types/featureToggles.gen.ts b/packages/grafana-data/src/types/featureToggles.gen.ts index 64596504fce..7170521f9df 100644 --- a/packages/grafana-data/src/types/featureToggles.gen.ts +++ b/packages/grafana-data/src/types/featureToggles.gen.ts @@ -407,6 +407,10 @@ export interface FeatureToggles { */ queryServiceFromUI?: boolean; /** + * Routes explore requests to the new query service + */ + queryServiceFromExplore?: boolean; + /** * Runs CloudWatch metrics queries as separate batches */ cloudWatchBatchQueries?: boolean; diff --git a/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts b/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts index 2ce4b88e85f..7ce7e9aa52d 100644 --- a/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts +++ b/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts @@ -17,6 +17,7 @@ import { parseLiveChannelAddress, ScopedVars, AdHocVariableFilter, + CoreApp, } from '@grafana/data'; import { reportInteraction } from '../analytics/utils'; @@ -208,6 +209,18 @@ class DataSourceWithBackend< let url = '/api/ds/query?ds_type=' + this.type; + // Use the new query service for explore + if (config.featureToggles.queryServiceFromExplore && request.app === CoreApp.Explore) { + // make sure query-service is enabled on the backend + const isQueryServiceEnabled = config.featureToggles.queryService; + const isExperimentalAPIsEnabled = config.featureToggles.grafanaAPIServerWithExperimentalAPIs; + if (!isQueryServiceEnabled && !isExperimentalAPIsEnabled) { + console.warn('feature toggle queryServiceFromExplore also requires the queryService to be running'); + } else { + url = `/apis/query.grafana.app/v0alpha1/namespaces/${config.namespace}/query?ds_type=${this.type}`; + } + } + // Use the new query service if (config.featureToggles.queryServiceFromUI) { if (!(config.featureToggles.queryService || config.featureToggles.grafanaAPIServerWithExperimentalAPIs)) { diff --git a/pkg/services/featuremgmt/registry.go b/pkg/services/featuremgmt/registry.go index 727ffe32223..f28f1aa23b0 100644 --- a/pkg/services/featuremgmt/registry.go +++ b/pkg/services/featuremgmt/registry.go @@ -684,6 +684,13 @@ var ( Owner: grafanaAppPlatformSquad, FrontendOnly: true, // and can change at startup }, + { + Name: "queryServiceFromExplore", + Description: "Routes explore requests to the new query service", + Stage: FeatureStageExperimental, + Owner: grafanaDatasourcesCoreServicesSquad, + FrontendOnly: true, + }, { Name: "cloudWatchBatchQueries", Description: "Runs CloudWatch metrics queries as separate batches", diff --git a/pkg/services/featuremgmt/toggles_gen.csv b/pkg/services/featuremgmt/toggles_gen.csv index ef7cbcfdd96..23ecb8bede8 100644 --- a/pkg/services/featuremgmt/toggles_gen.csv +++ b/pkg/services/featuremgmt/toggles_gen.csv @@ -90,6 +90,7 @@ datasourceQueryTypes,experimental,@grafana/grafana-app-platform-squad,false,true queryService,experimental,@grafana/grafana-app-platform-squad,false,true,false queryServiceRewrite,experimental,@grafana/grafana-app-platform-squad,false,true,false queryServiceFromUI,experimental,@grafana/grafana-app-platform-squad,false,false,true +queryServiceFromExplore,experimental,@grafana/grafana-datasources-core-services,false,false,true cloudWatchBatchQueries,preview,@grafana/aws-datasources,false,false,false recoveryThreshold,GA,@grafana/alerting-squad,false,true,false lokiStructuredMetadata,GA,@grafana/observability-logs,false,false,false diff --git a/pkg/services/featuremgmt/toggles_gen.go b/pkg/services/featuremgmt/toggles_gen.go index 89e6a99d839..da3ba572ea8 100644 --- a/pkg/services/featuremgmt/toggles_gen.go +++ b/pkg/services/featuremgmt/toggles_gen.go @@ -371,6 +371,10 @@ const ( // Routes requests to the new query service FlagQueryServiceFromUI = "queryServiceFromUI" + // FlagQueryServiceFromExplore + // Routes explore requests to the new query service + FlagQueryServiceFromExplore = "queryServiceFromExplore" + // FlagCloudWatchBatchQueries // Runs CloudWatch metrics queries as separate batches FlagCloudWatchBatchQueries = "cloudWatchBatchQueries" diff --git a/pkg/services/featuremgmt/toggles_gen.json b/pkg/services/featuremgmt/toggles_gen.json index b5a04e9938f..1eb711cbca6 100644 --- a/pkg/services/featuremgmt/toggles_gen.json +++ b/pkg/services/featuremgmt/toggles_gen.json @@ -3660,6 +3660,19 @@ "requiresRestart": true } }, + { + "metadata": { + "name": "queryServiceFromExplore", + "resourceVersion": "1743513714582", + "creationTimestamp": "2025-04-01T13:21:54Z" + }, + "spec": { + "description": "Routes explore requests to the new query service", + "stage": "experimental", + "codeowner": "@grafana/grafana-datasources-core-services", + "frontend": true + } + }, { "metadata": { "name": "queryServiceFromUI",