Skip to content
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

PMM-11673-fix-psmdb-configuration: fix configuration in api #657

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Databases } from 'app/percona/shared/core';
export const PXCDefailtConfiguration =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: PXCDefaultConfiguration

'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<Record<Databases, string>> = {
[Databases.mysql]: PXCDefailtConfiguration,
[Databases.mongodb]: PSMDBDefaultConfiguration,
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const DBClusterBasicOptions: FC<DBClusterBasicOptionsProps> = ({ 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
}, []);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { render, screen, waitFor } from '@testing-library/react';
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
import React from 'react';
import { Provider } from 'react-redux';
import { Router } from 'react-router-dom';

import { locationService } from '@grafana/runtime/src';
import { PSMDBDefaultConfiguration } from 'app/percona/dbaas/components/DBCluster/EditDBClusterPage/DBClusterAdvancedOptions/Configurations/Configuration.constants';
import { configureStore } from 'app/store/configureStore';
import { StoreState } from 'app/types';

Expand Down Expand Up @@ -171,4 +172,45 @@ describe('EditDBClusterPage::', () => {

expect(screen.getByTestId('empty-block')).toBeInTheDocument();
});

it('show default database configuration in create mode', async () => {
locationService.push(DB_CLUSTER_CREATION_URL);

render(
<Provider
store={configureStore({
percona: {
user: { isAuthorized: true },
settings: {
loading: false,
result: { isConnectedToPortal: true, alertingEnabled: true, dbaasEnabled: true },
},
kubernetes: {
loading: false,
result: [
{
kubernetesClusterName: 'cluster1',
status: KubernetesClusterStatus.ok,
operators: {
psmdb: { status: KubernetesOperatorStatus.ok, version: '1', availableVersion: '1' },
pxc: { status: KubernetesOperatorStatus.ok, version: '1', availableVersion: '1' },
},
},
],
},
},
} as StoreState)}
>
<Router history={locationService.getHistory()}>
<EditDBClusterPage kubernetes={kubernetesStub} />
</Router>
</Provider>
);

expect(screen.findByRole('form')).toBeTruthy();
const advancedSettingsButton = screen.getByTestId('dbCluster-advanced-settings');
await waitFor(() => fireEvent.click(advancedSettingsButton));

expect(screen.getByTestId('configuration-textarea-input')).toContainHTML(PSMDBDefaultConfiguration);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -93,6 +95,11 @@ export const EditDBClusterPage: FC<EditDBClusterPageProps> = () => {
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 }) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { logger } from 'app/percona/shared/helpers/logger';

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';
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
}
Expand All @@ -169,6 +170,7 @@ const toAPI = (dbCluster: DBCluster): DBClusterPayload => ({
},
storage_class: dbCluster.storageClass,
disk_size: dbCluster.disk * BILLION,
configuration: dbCluster.configuration,
},
image: dbCluster.databaseImage,
...(dbCluster.backup && {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
}
Expand Down