mirror of https://github.com/grafana/grafana.git
Remove `sqlDatasourceDatabaseSelection` feature toggle (#109391)
* Remove `sqlDatasourceDatabaseSelection` feature toggle * Update e2e tests
This commit is contained in:
parent
6c106a85ac
commit
db0a1bc30f
|
@ -70,7 +70,7 @@ Grafana’s query editors are unique for each data source. For general informati
|
|||
The MySQL query editor is located on the [Explore page](ref:explore). You can also access the MySQL query editor from a dashboard panel. Click the ellipsis in the upper right of the panel and select **Edit**.
|
||||
|
||||
{{< admonition type="note" >}}
|
||||
If a default database is configured in the **Data Source Configuration page**, or via a provisioning configuration file, users will be restricted to querying only that pre-configured database. This feature is behind a feature flag and is available once you enable `sqlDatasourceDatabaseSelection`.
|
||||
If a default database is configured in the **Data Source Configuration page**, or via a provisioning configuration file, users will be restricted to querying only that pre-configured database.
|
||||
{{< /admonition >}}
|
||||
|
||||
## MySQL query editor components
|
||||
|
|
|
@ -90,7 +90,6 @@ Most [generally available](https://grafana.com/docs/release-life-cycle/#general-
|
|||
| `refactorVariablesTimeRange` | Refactor time range variables flow to reduce number of API calls made when query variables are chained |
|
||||
| `faroDatasourceSelector` | Enable the data source selector within the Frontend Apps section of the Frontend Observability |
|
||||
| `enableDatagridEditing` | Enables the edit functionality in the datagrid panel |
|
||||
| `sqlDatasourceDatabaseSelection` | Enables previous SQL data source dataset dropdown behavior |
|
||||
| `reportingRetries` | Enables rendering retries for the reporting feature |
|
||||
| `externalServiceAccounts` | Automatic service account and token setup for plugins |
|
||||
| `cloudWatchBatchQueries` | Runs CloudWatch metrics queries as separate batches |
|
||||
|
|
|
@ -64,7 +64,7 @@ export const datasetResponse = {
|
|||
},
|
||||
fields: [{ name: 'TABLE_SCHEMA', type: 'string', typeInfo: { frame: 'string', nullable: true } }],
|
||||
},
|
||||
data: { values: [['DataMaker', 'mysql', 'performance_schema', 'sys']] },
|
||||
data: { values: [['grafana', 'mysql', 'performance_schema', 'sys']] },
|
||||
},
|
||||
],
|
||||
},
|
||||
|
|
|
@ -48,7 +48,7 @@ test.describe(
|
|||
await expect(
|
||||
explorePage.getByGrafanaSelector(selectors.components.CodeEditor.container).getByRole('textbox')
|
||||
).toHaveValue(
|
||||
`SELECT\n $__timeGroupAlias(createdAt, $__interval),\n AVG(\`bigint\`)\nFROM\n DataMaker.normalTable\nLIMIT\n 50`
|
||||
`SELECT\n $__timeGroupAlias(createdAt, $__interval),\n AVG(\`bigint\`)\nFROM\n grafana.normalTable\nLIMIT\n 50`
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -83,9 +83,7 @@ test.describe(
|
|||
// Validate that the timeFilter macro was added
|
||||
await expect(
|
||||
explorePage.getByGrafanaSelector(selectors.components.CodeEditor.container).getByRole('textbox')
|
||||
).toHaveValue(
|
||||
`SELECT\n createdAt\nFROM\n DataMaker.normalTable\nWHERE\n $__timeFilter(createdAt)\nLIMIT\n 50`
|
||||
);
|
||||
).toHaveValue(`SELECT\n createdAt\nFROM\n grafana.normalTable\nWHERE\n $__timeFilter(createdAt)\nLIMIT\n 50`);
|
||||
|
||||
// Validate that the timeFilter macro was removed when changed to equals operator
|
||||
await explorePage.getByGrafanaSelector(selectors.components.SQLQueryEditor.filterOperator).click();
|
||||
|
@ -96,7 +94,7 @@ test.describe(
|
|||
|
||||
await expect(
|
||||
explorePage.getByGrafanaSelector(selectors.components.CodeEditor.container).getByRole('textbox')
|
||||
).not.toHaveValue(`SELECT\n createdAt\nFROM\n DataMaker.normalTable\nWHERE\n createdAt = NULL\nLIMIT\n 50`);
|
||||
).not.toHaveValue(`SELECT\n createdAt\nFROM\n grafana.normalTable\nWHERE\n createdAt = NULL\nLIMIT\n 50`);
|
||||
});
|
||||
|
||||
test('visual query builder should not crash when filter is set to select_any_in', async ({ explorePage, page }) => {
|
||||
|
@ -114,7 +112,7 @@ test.describe(
|
|||
uid: 'P4FDCC188E688367F',
|
||||
},
|
||||
format: 'table',
|
||||
rawSql: "SELECT * FROM DataMaker.normalTable WHERE name IN ('a') LIMIT 50 ",
|
||||
rawSql: "SELECT * FROM grafana.normalTable WHERE name IN ('a') LIMIT 50 ",
|
||||
editorMode: 'builder',
|
||||
sql: {
|
||||
columns: [
|
||||
|
@ -157,7 +155,7 @@ test.describe(
|
|||
},
|
||||
whereString: "name IN ('a')",
|
||||
},
|
||||
dataset: 'DataMaker',
|
||||
dataset: 'grafana',
|
||||
table: 'normalTable',
|
||||
},
|
||||
],
|
||||
|
@ -170,7 +168,7 @@ test.describe(
|
|||
// Validate the query
|
||||
await expect(
|
||||
explorePage.getByGrafanaSelector(selectors.components.CodeEditor.container).getByRole('textbox')
|
||||
).toHaveValue(`SELECT\n *\nFROM\n DataMaker.normalTable\nWHERE\n name IN ('a')\nLIMIT\n 50`);
|
||||
).toHaveValue(`SELECT\n *\nFROM\n grafana.normalTable\nWHERE\n name IN ('a')\nLIMIT\n 50`);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
|
@ -161,10 +161,6 @@ export interface FeatureToggles {
|
|||
*/
|
||||
pluginsFrontendSandbox?: boolean;
|
||||
/**
|
||||
* Enables previous SQL data source dataset dropdown behavior
|
||||
*/
|
||||
sqlDatasourceDatabaseSelection?: boolean;
|
||||
/**
|
||||
* Enables writing multiple items from a single query within Recorded Queries
|
||||
* @default true
|
||||
*/
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { useEffect } from 'react';
|
||||
import { useAsync } from 'react-use';
|
||||
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
|
@ -7,8 +6,6 @@ import { Select } from '@grafana/ui';
|
|||
|
||||
import { DB, ResourceSelectorProps, SQLDialect, toOption } from '../types';
|
||||
|
||||
import { isSqlDatasourceDatabaseSelectionFeatureFlagEnabled } from './QueryEditorFeatureFlag.utils';
|
||||
|
||||
export interface DatasetSelectorProps extends ResourceSelectorProps {
|
||||
db: DB;
|
||||
dataset: string | undefined;
|
||||
|
@ -37,13 +34,11 @@ export const DatasetSelector = ({
|
|||
const hasPreconfigCondition = !!preconfiguredDataset || dialect === 'postgres';
|
||||
|
||||
const state = useAsync(async () => {
|
||||
if (isSqlDatasourceDatabaseSelectionFeatureFlagEnabled()) {
|
||||
// If a default database is already configured for a MSSQL or MySQL data source, OR the data source is Postgres, no need to fetch other databases.
|
||||
if (hasPreconfigCondition) {
|
||||
// Set the current database to the preconfigured database.
|
||||
onChange(toOption(preconfiguredDataset));
|
||||
return [toOption(preconfiguredDataset)];
|
||||
}
|
||||
// If a default database is already configured for a MSSQL or MySQL data source, OR the data source is Postgres, no need to fetch other databases.
|
||||
if (hasPreconfigCondition) {
|
||||
// Set the current database to the preconfigured database.
|
||||
onChange(toOption(preconfiguredDataset));
|
||||
return [toOption(preconfiguredDataset)];
|
||||
}
|
||||
|
||||
// If there is no preconfigured database, but there is a selected dataset, set the current database to the selected dataset.
|
||||
|
@ -56,24 +51,6 @@ export const DatasetSelector = ({
|
|||
return datasets.map(toOption);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isSqlDatasourceDatabaseSelectionFeatureFlagEnabled()) {
|
||||
// Set default dataset when values are fetched
|
||||
if (!dataset) {
|
||||
if (state.value && state.value[0]) {
|
||||
onChange(state.value[0]);
|
||||
}
|
||||
} else {
|
||||
if (state.value && state.value.find((v) => v.value === dataset) === undefined) {
|
||||
// if value is set and newly fetched values does not contain selected value
|
||||
if (state.value.length > 0) {
|
||||
onChange(state.value[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [state.value, onChange, dataset]);
|
||||
|
||||
return (
|
||||
<Select
|
||||
aria-label={t('grafana-sql.components.dataset-selector.aria-label-dataset-selector', 'Dataset selector')}
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
import { config } from '@grafana/runtime';
|
||||
|
||||
export const isSqlDatasourceDatabaseSelectionFeatureFlagEnabled = () => {
|
||||
return !!config.featureToggles.sqlDatasourceDatabaseSelection;
|
||||
};
|
|
@ -13,7 +13,6 @@ import { SQLQuery, QueryFormat, QueryRowFilter, QUERY_FORMAT_OPTIONS, DB, SQLDia
|
|||
|
||||
import { ConfirmModal } from './ConfirmModal';
|
||||
import { DatasetSelector } from './DatasetSelector';
|
||||
import { isSqlDatasourceDatabaseSelectionFeatureFlagEnabled } from './QueryEditorFeatureFlag.utils';
|
||||
import { TableSelector } from './TableSelector';
|
||||
|
||||
export interface QueryHeaderProps {
|
||||
|
@ -117,11 +116,6 @@ export function QueryHeader({
|
|||
if (dialect === 'influx') {
|
||||
return false;
|
||||
}
|
||||
// If the feature flag is DISABLED, && the datasource is Postgres (`dialect = 'postgres`),
|
||||
// we want to hide the dropdown - as per previous behavior.
|
||||
if (!isSqlDatasourceDatabaseSelectionFeatureFlagEnabled() && dialect === 'postgres') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import { render, waitFor } from '@testing-library/react';
|
||||
|
||||
import { config } from '@grafana/runtime';
|
||||
|
||||
import { SQLExpression } from '../types';
|
||||
import { makeVariable } from '../utils/testHelpers';
|
||||
|
||||
|
@ -10,14 +8,6 @@ import { buildMockDatasetSelectorProps, buildMockTableSelectorProps } from './Sq
|
|||
import { TableSelector } from './TableSelector';
|
||||
import { removeQuotesForMultiVariables } from './visual-query-builder/SQLWhereRow';
|
||||
|
||||
beforeEach(() => {
|
||||
config.featureToggles.sqlDatasourceDatabaseSelection = true;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
config.featureToggles.sqlDatasourceDatabaseSelection = false;
|
||||
});
|
||||
|
||||
describe('DatasetSelector', () => {
|
||||
it('should only query the database when needed', async () => {
|
||||
const mockProps = buildMockDatasetSelectorProps();
|
||||
|
|
|
@ -35,8 +35,6 @@ import { MACRO_NAMES } from '../constants';
|
|||
import { DB, SQLQuery, SQLOptions, SqlQueryModel, QueryFormat } from '../types';
|
||||
import migrateAnnotation from '../utils/migration';
|
||||
|
||||
import { isSqlDatasourceDatabaseSelectionFeatureFlagEnabled } from './../components/QueryEditorFeatureFlag.utils';
|
||||
|
||||
export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLOptions> {
|
||||
id: number;
|
||||
responseParser: ResponseParser;
|
||||
|
@ -127,13 +125,11 @@ export abstract class SqlDatasource extends DataSourceWithBackend<SQLQuery, SQLO
|
|||
|
||||
query(request: DataQueryRequest<SQLQuery>): Observable<DataQueryResponse> {
|
||||
// This logic reenables the previous SQL behavior regarding what databases are available for the user to query.
|
||||
if (isSqlDatasourceDatabaseSelectionFeatureFlagEnabled()) {
|
||||
const databaseIssue = this.checkForDatabaseIssue(request);
|
||||
const databaseIssue = this.checkForDatabaseIssue(request);
|
||||
|
||||
if (!!databaseIssue) {
|
||||
const error = new Error(databaseIssue);
|
||||
return throwError(() => error);
|
||||
}
|
||||
if (!!databaseIssue) {
|
||||
const error = new Error(databaseIssue);
|
||||
return throwError(() => error);
|
||||
}
|
||||
|
||||
request.targets.forEach((target) => {
|
||||
|
|
|
@ -254,14 +254,6 @@ var (
|
|||
Stage: FeatureStagePrivatePreview,
|
||||
Owner: grafanaPluginsPlatformSquad,
|
||||
},
|
||||
{
|
||||
Name: "sqlDatasourceDatabaseSelection",
|
||||
Description: "Enables previous SQL data source dataset dropdown behavior",
|
||||
FrontendOnly: true,
|
||||
Stage: FeatureStagePublicPreview,
|
||||
Owner: grafanaOSSBigTent,
|
||||
HideFromAdminPage: true,
|
||||
},
|
||||
{
|
||||
Name: "recordedQueriesMulti",
|
||||
Description: "Enables writing multiple items from a single query within Recorded Queries",
|
||||
|
|
|
@ -32,7 +32,6 @@ faroDatasourceSelector,preview,@grafana/app-o11y,false,false,true
|
|||
enableDatagridEditing,preview,@grafana/dataviz-squad,false,false,true
|
||||
extraThemes,experimental,@grafana/grafana-frontend-platform,false,false,true
|
||||
pluginsFrontendSandbox,privatePreview,@grafana/plugins-platform-backend,false,false,false
|
||||
sqlDatasourceDatabaseSelection,preview,@grafana/oss-big-tent,false,false,true
|
||||
recordedQueriesMulti,GA,@grafana/observability-metrics,false,false,false
|
||||
logsExploreTableVisualisation,GA,@grafana/observability-logs,false,false,true
|
||||
awsDatasourcesTempCredentials,GA,@grafana/aws-datasources,false,false,false
|
||||
|
|
|
|
@ -139,10 +139,6 @@ const (
|
|||
// Enables the plugins frontend sandbox
|
||||
FlagPluginsFrontendSandbox = "pluginsFrontendSandbox"
|
||||
|
||||
// FlagSqlDatasourceDatabaseSelection
|
||||
// Enables previous SQL data source dataset dropdown behavior
|
||||
FlagSqlDatasourceDatabaseSelection = "sqlDatasourceDatabaseSelection"
|
||||
|
||||
// FlagRecordedQueriesMulti
|
||||
// Enables writing multiple items from a single query within Recorded Queries
|
||||
FlagRecordedQueriesMulti = "recordedQueriesMulti"
|
||||
|
|
|
@ -2927,7 +2927,8 @@
|
|||
"metadata": {
|
||||
"name": "sqlDatasourceDatabaseSelection",
|
||||
"resourceVersion": "1753448760331",
|
||||
"creationTimestamp": "2023-06-06T16:28:52Z"
|
||||
"creationTimestamp": "2023-06-06T16:28:52Z",
|
||||
"deletionTimestamp": "2025-08-08T12:18:29Z"
|
||||
},
|
||||
"spec": {
|
||||
"description": "Enables previous SQL data source dataset dropdown behavior",
|
||||
|
|
Loading…
Reference in New Issue