Skip to content

fix: make plan to svg more comprehensive #1658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {Dialog, Link as ExternalLink, Flex, TextInput} from '@gravity-ui/uikit';
import {Dialog, Link as ExternalLink, Flex, TextInput, Tooltip} from '@gravity-ui/uikit';
import {zodResolver} from '@hookform/resolvers/zod';
import {Controller, useForm} from 'react-hook-form';

Expand All @@ -11,8 +11,10 @@ import {
} from '../../../../store/reducers/queryActions/queryActions';
import type {QuerySettings} from '../../../../types/store/query';
import {cn} from '../../../../utils/cn';
import {USE_SHOW_PLAN_SVG_KEY} from '../../../../utils/constants';
import {
useQueryExecutionSettings,
useSetting,
useTypedDispatch,
useTypedSelector,
} from '../../../../utils/hooks';
Expand Down Expand Up @@ -77,6 +79,7 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm
resolver: zodResolver(querySettingsValidationSchema),
});

const [useShowPlanToSvg] = useSetting<boolean>(USE_SHOW_PLAN_SVG_KEY);
const enableTracingLevel = useTracingLevelOptionAvailable();

return (
Expand Down Expand Up @@ -178,22 +181,29 @@ function QuerySettingsForm({initialValues, onSubmit, onClose}: QuerySettingsForm
<label htmlFor="statisticsMode" className={b('field-title')}>
{QUERY_SETTINGS_FIELD_SETTINGS.statisticsMode.title}
</label>
<div className={b('control-wrapper', {statisticsMode: true})}>
<Controller
name="statisticsMode"
control={control}
render={({field}) => (
<QuerySettingsSelect
id="statisticsMode"
setting={field.value}
onUpdateSetting={field.onChange}
settingOptions={
QUERY_SETTINGS_FIELD_SETTINGS.statisticsMode.options
}
/>
)}
/>
</div>
<Tooltip
disabled={!useShowPlanToSvg}
openDelay={0}
content={i18n('tooltip_plan-to-svg-statistics')}
>
<div className={b('control-wrapper', {statisticsMode: true})}>
<Controller
name="statisticsMode"
control={control}
render={({field}) => (
<QuerySettingsSelect
id="statisticsMode"
disabled={useShowPlanToSvg}
setting={field.value}
onUpdateSetting={field.onChange}
settingOptions={
QUERY_SETTINGS_FIELD_SETTINGS.statisticsMode.options
}
/>
)}
/>
</div>
</Tooltip>
</Flex>
<Flex direction="row" alignItems="flex-start" className={b('dialog-row')}>
<label htmlFor="limitRows" className={b('field-title')}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface QuerySettingsSelectProps<T extends SelectType> {
id?: string;
setting: T;
settingOptions: QuerySettingSelectOption<T>[];
disabled?: boolean;
onUpdateSetting: (mode: T) => void;
}

Expand All @@ -34,6 +35,7 @@ export function QuerySettingsSelect<T extends SelectType>(props: QuerySettingsSe
<div className={b('selector')}>
<Select<T>
id={props.id}
disabled={props.disabled}
options={props.settingOptions}
value={[props.setting]}
onUpdate={(value) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"form.tracing-level": "Tracing level",
"form.limit-rows": "Limit rows",
"button-done": "Save",
"tooltip_plan-to-svg-statistics": "Statistics option is set to \"Full\" due to the enabled \"Execution plan\" experiment.\n To disable it, go to the \"Experiments\" section in the user settings.",
"button-cancel": "Cancel",
"form.timeout.seconds": "sec",
"form.validation.timeout": "Must be positive",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"form.statistics-mode": "Π Π΅ΠΆΠΈΠΌ сбора статистики",
"form.tracing-level": "Tracing level",
"form.limit-rows": "Π›ΠΈΠΌΠΈΡ‚ строк",
"tooltip_plan-to-svg-statistics": "ΠžΠΏΡ†ΠΈΡ статистики установлСна Π² Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ \"Full\" ΠΈΠ·-Π·Π° Π²ΠΊΠ»ΡŽΡ‡Π΅Π½Π½ΠΎΠ³ΠΎ экспСримСнта \"Execution plan\".\n Π§Ρ‚ΠΎΠ±Ρ‹ ΠΎΡ‚ΠΊΠ»ΡŽΡ‡ΠΈΡ‚ΡŒ Π΅Π³ΠΎ, ΠΏΠ΅Ρ€Π΅ΠΉΠ΄ΠΈΡ‚Π΅ Π² Ρ€Π°Π·Π΄Π΅Π» \"Experiments\" Π² настройках ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Ρ.",
"button-done": "Π“ΠΎΡ‚ΠΎΠ²ΠΎ",
"button-cancel": "ΠžΡ‚ΠΌΠ΅Π½ΠΈΡ‚ΡŒ",
"form.timeout.seconds": "сСк",
Expand Down
4 changes: 2 additions & 2 deletions src/containers/UserSettings/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

"settings.enableNetworkTable.title": "Enable network table",

"settings.useShowPlanToSvg.title": "Plan to svg",
"settings.useShowPlanToSvg.description": " Show \"Plan to svg\" button in query result widow (if query was executed with full stats option).",
"settings.useShowPlanToSvg.title": "Execution plan",
"settings.useShowPlanToSvg.description": " Show \"Execution plan\" button in query result widow. Opens svg with execution plan in a new window.",

"settings.showDomainDatabase.title": "Show domain database",

Expand Down
22 changes: 19 additions & 3 deletions src/utils/hooks/useQueryExecutionSettings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';

import {useTracingLevelOptionAvailable} from '../../store/reducers/capabilities/hooks';
import type {QuerySettings} from '../../types/store/query';
import {QUERY_EXECUTION_SETTINGS_KEY} from '../constants';
import {DEFAULT_QUERY_SETTINGS, querySettingsRestoreSchema} from '../query';
import {QUERY_EXECUTION_SETTINGS_KEY, USE_SHOW_PLAN_SVG_KEY} from '../constants';
import {DEFAULT_QUERY_SETTINGS, STATISTICS_MODES, querySettingsRestoreSchema} from '../query';

import {useSetting} from './useSetting';

Expand All @@ -10,13 +12,27 @@ export const useQueryExecutionSettings = () => {
const [storageSettings, setSettings] = useSetting<QuerySettings>(QUERY_EXECUTION_SETTINGS_KEY);

const validatedSettings = querySettingsRestoreSchema.parse(storageSettings);
const [useShowPlanToSvg] = useSetting<boolean>(USE_SHOW_PLAN_SVG_KEY);

const setQueryExecutionSettings = React.useCallback(
(settings: QuerySettings) => {
setSettings({
...settings,
statisticsMode: useShowPlanToSvg
? validatedSettings.statisticsMode
: settings.statisticsMode,
});
},
[setSettings, useShowPlanToSvg, validatedSettings.statisticsMode],
);

const settings: QuerySettings = {
...validatedSettings,
statisticsMode: useShowPlanToSvg ? STATISTICS_MODES.full : validatedSettings.statisticsMode,
tracingLevel: enableTracingLevel
? validatedSettings.tracingLevel
: DEFAULT_QUERY_SETTINGS.tracingLevel,
};

return [settings, setSettings] as const;
return [settings, setQueryExecutionSettings] as const;
};
17 changes: 6 additions & 11 deletions tests/suites/tenant/queryEditor/planToSvg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {tenantName} from '../../../utils/constants';
import {toggleExperiment} from '../../../utils/toggleExperiment';
import {TenantPage} from '../TenantPage';

import {ButtonNames, QueryEditor} from './models/QueryEditor';
import {QueryEditor} from './models/QueryEditor';

test.describe('Test Plan to SVG functionality', async () => {
const testQuery = 'SELECT 1;'; // Simple query that will generate a plan
Expand All @@ -24,30 +24,25 @@ test.describe('Test Plan to SVG functionality', async () => {
const queryEditor = new QueryEditor(page);

// 1. Turn on Plan to SVG experiment
await toggleExperiment(page, 'on', 'Plan to SVG');
await toggleExperiment(page, 'on', 'Execution plan');

// 2. Set stats level to Full
await queryEditor.clickGearButton();
await queryEditor.settingsDialog.changeStatsLevel('Full');
await queryEditor.settingsDialog.clickButton(ButtonNames.Save);

// 3. Set query and run it
// 2. Set query and run it
await queryEditor.setQuery(testQuery);
await queryEditor.clickRunButton();

// 4. Wait for query execution to complete
// 3. Wait for query execution to complete
await expect(async () => {
const status = await queryEditor.getExecutionStatus();
expect(status).toBe('Completed');
}).toPass();

// 5. Check if Execution Plan button appears and click it
// 4. Check if Execution Plan button appears and click it
const executionPlanButton = page.locator('button:has-text("Execution plan")');
await expect(executionPlanButton).toBeVisible();
await executionPlanButton.click();
await page.waitForTimeout(1000); // Wait for new tab to open

// 6. Verify we're taken to a new tab with SVG content
// 5. Verify we're taken to a new tab with SVG content
const svgElement = page.locator('svg').first();
await expect(svgElement).toBeVisible();
});
Expand Down
Loading