diff --git a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/Configurations/Configuration.constants.ts b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/Configurations/Configuration.constants.ts new file mode 100644 index 0000000000000..9c2088495b2f4 --- /dev/null +++ b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/Configurations/Configuration.constants.ts @@ -0,0 +1,12 @@ +import { Databases } from 'app/percona/shared/core'; +export const PXCDefailtConfiguration = + 'Configuration: [mysqld]\n' + + 'wsrep_provider_options="gcache.size=600M"\n' + + "wsrep_trx_fragment_unit='bytes'\n" + + 'wsrep_trx_fragment_size=3670018'; +export const PSMDBDefaultConfiguration = ' Configuration: \n' + ' operationProfiling:\n' + ' mode: slowOp'; + +export const DefaultDatabaseConfiguration: Partial> = { + [Databases.mysql]: PXCDefailtConfiguration, + [Databases.mongodb]: PSMDBDefaultConfiguration, +}; diff --git a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterBasicOptions/DBClusterBasicOptions.tsx b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterBasicOptions/DBClusterBasicOptions.tsx index 5764519adeff4..7ca71f8210e07 100644 --- a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterBasicOptions/DBClusterBasicOptions.tsx +++ b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterBasicOptions/DBClusterBasicOptions.tsx @@ -52,6 +52,7 @@ export const DBClusterBasicOptions: FC = ({ kubernet const onChangeDatabase = useCallback((databaseType) => { change(BasicOptionsFields.databaseType, databaseType); form.mutators.setClusterName(databaseType.value); + form.mutators.changeConfiguration(databaseType.value); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); diff --git a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/EditDBClusterPage.tsx b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/EditDBClusterPage.tsx index 3ef56109b314c..6b3580e9a0c94 100644 --- a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/EditDBClusterPage.tsx +++ b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/EditDBClusterPage.tsx @@ -5,7 +5,9 @@ import { Form } from 'react-final-form'; import { Redirect, useHistory } from 'react-router-dom'; import { Spinner, useStyles2 } from '@grafana/ui/src'; +import { DefaultDatabaseConfiguration } from 'app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/Configurations/Configuration.constants'; import { useShowPMMAddressWarning } from 'app/percona/shared/components/hooks/showPMMAddressWarning'; +import { Databases } from 'app/percona/shared/core'; import { useSelector, useDispatch } from 'app/types'; import { FeatureLoader } from '../../../../shared/components/Elements/FeatureLoader'; @@ -93,6 +95,11 @@ export const EditDBClusterPage: FC = () => { trimConfiguration: ([configuration]: string[], state, { changeValue }) => { changeValue(state, ConfigurationFields.configuration, () => configuration.trim()); }, + changeConfiguration: (databaseTypeValue: Databases, state, { changeValue }) => { + changeValue(state, ConfigurationFields.configuration, () => + databaseTypeValue ? DefaultDatabaseConfiguration[databaseTypeValue] : '' + ); + }, ...arrayMutators, }} render={({ form, handleSubmit, valid, pristine, ...props }) => ( diff --git a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/EditDBClusterPage.utils.ts b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/EditDBClusterPage.utils.ts index 41ee21c71c5b3..6e1070c9d5fdb 100644 --- a/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/EditDBClusterPage.utils.ts +++ b/public/app/percona/dbaas/components/DBCluster/EditDBClusterPage/EditDBClusterPage.utils.ts @@ -1,5 +1,8 @@ import { logger } from '@percona/platform-core'; +import { DefaultDatabaseConfiguration } from 'app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/Configurations/Configuration.constants'; +import { ConfigurationFields } from 'app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/Configurations/Configurations.types'; + import { DATABASE_LABELS } from '../../../../shared/core'; import { Kubernetes } from '../../Kubernetes/Kubernetes.types'; import { getActiveOperators, getDatabaseOptionFromOperator } from '../../Kubernetes/Kubernetes.utils'; @@ -37,8 +40,12 @@ export const getAddInitialValues = ( initialValues[BasicOptionsFields.kubernetesCluster] = initialCluster; if (activeOperators.length > 0) { const databaseDefaultOperator = getDatabaseOptionFromOperator(activeOperators[0]); + const defaultConfiguration = databaseDefaultOperator?.value + ? DefaultDatabaseConfiguration[databaseDefaultOperator?.value] + : ''; initialValues[BasicOptionsFields.databaseType] = databaseDefaultOperator; initialValues[BasicOptionsFields.name] = `${databaseDefaultOperator?.value}-${generateUID()}`; + initialValues[ConfigurationFields.configuration] = defaultConfiguration; } } } @@ -80,7 +87,10 @@ export const getEditInitialValues = ( cpu, disk, memory, - configuration: configuration?.params?.pxc?.configuration || configuration?.params?.replicaset?.configuration, + configuration: + selectedDBCluster?.configuration || + configuration?.params?.pxc?.configuration || + configuration?.params?.replicaset?.configuration, expose: configuration?.exposed, internetFacing: configuration?.internet_facing, sourceRanges: sourceRangesArray, diff --git a/public/app/percona/dbaas/components/DBCluster/PSMDB.service.ts b/public/app/percona/dbaas/components/DBCluster/PSMDB.service.ts index 4922b59286ca4..b7315b393ca10 100644 --- a/public/app/percona/dbaas/components/DBCluster/PSMDB.service.ts +++ b/public/app/percona/dbaas/components/DBCluster/PSMDB.service.ts @@ -150,6 +150,7 @@ export class PSMDBService extends DBClusterService { availableImage: dbCluster.available_image, template: dbCluster.template, sourceRanges: dbCluster.source_ranges, + configuration: dbCluster.params.replicaset?.configuration, }; } } diff --git a/public/app/percona/dbaas/components/DBCluster/XtraDB.service.ts b/public/app/percona/dbaas/components/DBCluster/XtraDB.service.ts index 6d40e91f01d8b..860771f4d000c 100644 --- a/public/app/percona/dbaas/components/DBCluster/XtraDB.service.ts +++ b/public/app/percona/dbaas/components/DBCluster/XtraDB.service.ts @@ -159,6 +159,7 @@ export class XtraDBService extends DBClusterService { availableImage: dbCluster.available_image, template: dbCluster.template, sourceRanges: dbCluster.source_ranges, + configuration: dbCluster.params.pxc?.configuration, }; } }