From 3389784a1babb655cbe9a495082828f14010cd8a Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Mon, 14 Oct 2024 12:18:11 +0200 Subject: [PATCH] update serverless tests, fix helper text for static --- .../model_management/deployment_setup.tsx | 27 ++++++++++++++-- .../services/ml/trained_models_table.ts | 27 ++++++++++++++++ .../search/ml/trained_models_list.ts | 31 +++++++++++++------ .../security/ml/trained_models_list.ts | 22 ++++++++----- 4 files changed, 88 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/ml/public/application/model_management/deployment_setup.tsx b/x-pack/plugins/ml/public/application/model_management/deployment_setup.tsx index 4c47a6af44d45..87fff2bf3eb75 100644 --- a/x-pack/plugins/ml/public/application/model_management/deployment_setup.tsx +++ b/x-pack/plugins/ml/public/application/model_management/deployment_setup.tsx @@ -221,7 +221,7 @@ export const DeploymentSetup: FC = ({ const helperText = useMemo(() => { const vcpuRange = deploymentParamsMapper.getVCPURange(config.vCPUUsage); - if (cloudInfo.isCloud && cloudInfo.isMlAutoscalingEnabled) { + if (cloudInfo.isCloud && cloudInfo.isMlAutoscalingEnabled && showNodeInfo) { // Running in cloud with ML autoscaling enabled if (config.adaptiveResources) { // With adaptive resources @@ -286,7 +286,7 @@ export const DeploymentSetup: FC = ({ } } } else if ( - (cloudInfo.isCloud && !cloudInfo.isMlAutoscalingEnabled) || + (cloudInfo.isCloud && !cloudInfo.isMlAutoscalingEnabled && showNodeInfo) || (!cloudInfo.isCloud && showNodeInfo) ) { // Running in cloud with autoscaling disabled or on-prem @@ -387,6 +387,29 @@ export const DeploymentSetup: FC = ({ } ); } + } else { + // Static allocations are allowed for Search projects + switch (config.vCPUUsage) { + case 'low': + return i18n.translate( + 'xpack.ml.trainedModels.modelsList.startDeployment.serverless.lowCpuStaticHelp', + { + defaultMessage: + 'This level set resources to {staticVCUs, plural, one {VCU} other {# VCUs}}, which may be suitable for development, testing, and demos depending on your parameters. It is not recommended for production use.', + values: { staticVCUs: vcuRange.static }, + } + ); + case 'medium': + case 'high': + return i18n.translate( + 'xpack.ml.trainedModels.modelsList.startDeployment.serverless.mediumCpuStaticHelp', + { + defaultMessage: + 'Your model will consume {staticVCUs, plural, one {VCU} other {# VCUs}}, even when not in use.', + values: { staticVCUs: vcuRange.static }, + } + ); + } } } }, [ diff --git a/x-pack/test/functional/services/ml/trained_models_table.ts b/x-pack/test/functional/services/ml/trained_models_table.ts index 4628e185a375c..450973c68f4c7 100644 --- a/x-pack/test/functional/services/ml/trained_models_table.ts +++ b/x-pack/test/functional/services/ml/trained_models_table.ts @@ -565,6 +565,33 @@ export function TrainedModelsTableProvider( await this.assertAdvancedConfigurationOpen(open); } + public async assertAdaptiveResourcesSwitchExists(expectExist: boolean) { + if (expectExist) { + await testSubjects.existOrFail('mlModelsStartDeploymentModalAdaptiveResources'); + } else { + await testSubjects.missingOrFail('mlModelsStartDeploymentModalAdaptiveResources'); + } + } + + public async toggleAdaptiveResourcesSwitch(enabled: boolean) { + await mlCommonUI.toggleSwitchIfNeeded( + 'mlModelsStartDeploymentModalAdaptiveResources', + enabled + ); + + await this.assertAdaptiveResourcesSwitchChecked(enabled); + } + + public async assertAdaptiveResourcesSwitchChecked(expectedValue: boolean) { + const isChecked = await testSubjects.isEuiSwitchChecked( + 'mlModelsStartDeploymentModalAdaptiveResources' + ); + expect(isChecked).to.eql( + expectedValue, + `Expected adaptive resources switch to be ${expectedValue ? 'checked' : 'unchecked'}` + ); + } + public async startDeploymentWithParams( modelId: string, params: { diff --git a/x-pack/test_serverless/functional/test_suites/search/ml/trained_models_list.ts b/x-pack/test_serverless/functional/test_suites/search/ml/trained_models_list.ts index d4f0b807609c9..1a273970bf1bf 100644 --- a/x-pack/test_serverless/functional/test_suites/search/ml/trained_models_list.ts +++ b/x-pack/test_serverless/functional/test_suites/search/ml/trained_models_list.ts @@ -11,12 +11,21 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const ml = getService('ml'); const PageObjects = getPageObjects(['svlCommonPage']); - describe('Trained models list', () => { + describe('Trained models list', function () { + const tinyElser = SUPPORTED_TRAINED_MODELS.TINY_ELSER; + before(async () => { await PageObjects.svlCommonPage.loginWithPrivilegedRole(); + await ml.api.importTrainedModel(tinyElser.name, tinyElser.name); + // Make sure the .ml-stats index is created in advance, see https://github.com/elastic/elasticsearch/issues/65846 + await ml.api.assureMlStatsIndexExists(); await ml.api.syncSavedObjects(); }); + after(async () => { + await ml.api.deleteAllTrainedModelsES(); + }); + describe('page navigation', () => { it('renders trained models list', async () => { await ml.navigation.navigateToMl(); @@ -25,18 +34,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await ml.testExecution.logTestStep( 'should display the stats bar and the analytics table with 1 installed trained model and built in elser models in the table' ); - await ml.trainedModels.assertStats(1); + await ml.trainedModels.assertStats(2); await ml.trainedModelsTable.assertTableIsPopulated(); }); }); describe('trained models table', () => { - const tinyElser = SUPPORTED_TRAINED_MODELS.TINY_ELSER; - - before(async () => { - await ml.api.importTrainedModel(tinyElser.name, tinyElser.name); - }); - it('sets correct VCU ranges for start model deployment', async () => { await ml.trainedModelsTable.openStartDeploymentModal(tinyElser.name); await ml.trainedModelsTable.toggleAdvancedConfiguration(true); @@ -54,7 +57,17 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { ); await ml.trainedModelsTable.setVCPULevel('high'); await ml.trainedModelsTable.assertVCPUHelperText( - 'Your model will scale up to a maximum of 4096 VCUs per hour based on your search or ingest load. It will automatically scale down when demand decreases, and you only pay for the resources you use.' + 'Your model will scale up to a maximum of 4,096 VCUs per hour based on your search or ingest load. It will automatically scale down when demand decreases, and you only pay for the resources you use.' + ); + + // Adaptive resources switch should be checked by default + await ml.trainedModelsTable.assertAdaptiveResourcesSwitchChecked(true); + + // Static allocations should be allowed for search projects + await ml.trainedModelsTable.toggleAdaptiveResourcesSwitch(false); + + await ml.trainedModelsTable.assertVCPUHelperText( + 'Your model will consume 4,096 VCUs, even when not in use.' ); }); }); diff --git a/x-pack/test_serverless/functional/test_suites/security/ml/trained_models_list.ts b/x-pack/test_serverless/functional/test_suites/security/ml/trained_models_list.ts index 3ef2379dd1ddc..3a6e1fcead8c1 100644 --- a/x-pack/test_serverless/functional/test_suites/security/ml/trained_models_list.ts +++ b/x-pack/test_serverless/functional/test_suites/security/ml/trained_models_list.ts @@ -14,11 +14,20 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const PageObjects = getPageObjects(['svlCommonPage']); describe('Trained models list', function () { + const tinyElser = SUPPORTED_TRAINED_MODELS.TINY_ELSER; + before(async () => { await PageObjects.svlCommonPage.loginWithRole(ServerlessRoleName.PLATFORM_ENGINEER); + await ml.api.importTrainedModel(tinyElser.name, tinyElser.name); + // Make sure the .ml-stats index is created in advance, see https://github.com/elastic/elasticsearch/issues/65846 + await ml.api.assureMlStatsIndexExists(); await ml.api.syncSavedObjects(); }); + after(async () => { + await ml.api.deleteAllTrainedModelsES(); + }); + describe('page navigation', () => { it('renders trained models list', async () => { await ml.navigation.navigateToMl(); @@ -28,22 +37,19 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await ml.testExecution.logTestStep( 'should display the stats bar and the analytics table with one trained model' ); - await ml.trainedModels.assertStats(1); + await ml.trainedModels.assertStats(2); await ml.trainedModelsTable.assertTableIsPopulated(); }); }); describe('trained models table', () => { - const tinyElser = SUPPORTED_TRAINED_MODELS.TINY_ELSER; - - before(async () => { - await ml.api.importTrainedModel(tinyElser.name, tinyElser.name); - }); - it('sets correct VCU ranges for start model deployment', async () => { await ml.trainedModelsTable.openStartDeploymentModal(tinyElser.name); await ml.trainedModelsTable.toggleAdvancedConfiguration(true); + // Adaptive resources switch should be hidden + await ml.trainedModelsTable.assertAdaptiveResourcesSwitchExists(false); + await ml.testExecution.logTestStep('should have correct default VCU level'); // Assert that the default selected level is Low await ml.trainedModelsTable.assertVCPULevel('low'); @@ -57,7 +63,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { ); await ml.trainedModelsTable.setVCPULevel('high'); await ml.trainedModelsTable.assertVCPUHelperText( - 'Your model will scale up to a maximum of 1024 VCUs per hour based on your search or ingest load. It will automatically scale down when demand decreases, and you only pay for the resources you use.' + 'Your model will scale up to a maximum of 1,024 VCUs per hour based on your search or ingest load. It will automatically scale down when demand decreases, and you only pay for the resources you use.' ); }); });