Skip to content

Commit

Permalink
PMM-12608 Add auto discovery limit for PG (#695)
Browse files Browse the repository at this point in the history
* PMM-12608 Add auto discovery limit for PG

* PMM-12608 Adjust stat tracking styling

* PMM-12608 Fix custom value setting

* PMM-12608 Remove tooltip from autodiscovery

* PMM-12608 Address comments

* PMM-12608 Use enabled instead of disabled & tooltips

* PMM-12608 Match validation to table stats + fix table stats

* PMM-12608 Set default custom autodiscovery limit to 10

* PMM-12608 Add integer validation

* PMM-12608 Add option to disable autodiscovery

* PMM-12608 Fix unit tests
  • Loading branch information
matejkubinec authored and YashSartanpara1 committed Jan 24, 2024
1 parent d2bc764 commit 5e2a721
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export interface PostgreSQLPayload extends RemoteCommonPayload, TLSCommon {
tls_key: string;
agent_password: string;
max_query_length: number;
auto_discovery_limit: number;
}

export interface MySQLPayload extends RemoteCommonPayload, TLSCommon {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Messages } from './AdditionalOptions.messages';
import { TablestatOptionsInterface } from './AdditionalOptions.types';
import { AutoDiscoveryOptionsInterface, TablestatOptionsInterface } from './AdditionalOptions.types';

export const tablestatOptions = [
{
Expand All @@ -15,3 +15,18 @@ export const tablestatOptions = [
label: Messages.form.tablestatOptions.custom,
},
];

export const autoDiscoveryOptions = [
{
value: AutoDiscoveryOptionsInterface.enabled,
label: Messages.form.autoDiscoveryOptions.enabled,
},
{
value: AutoDiscoveryOptionsInterface.disabled,
label: Messages.form.autoDiscoveryOptions.disabled,
},
{
value: AutoDiscoveryOptionsInterface.custom,
label: Messages.form.autoDiscoveryOptions.custom,
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ export const Messages = {
default: 'Default',
custom: 'Custom',
},
autoDiscoveryOptions: {
enabled: 'Enabled',
disabled: 'Disabled',
custom: 'Custom',
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { Messages } from '../FormParts.messages';
import { getStyles } from '../FormParts.styles';
import { AdditionalOptionsFormPartProps, PostgreSQLAdditionalOptionsProps } from '../FormParts.types';

import { tablestatOptions } from './AdditionalOptions.constants';
import { TablestatOptionsInterface } from './AdditionalOptions.types';
import { autoDiscoveryOptions, tablestatOptions } from './AdditionalOptions.constants';
import { AutoDiscoveryOptionsInterface, TablestatOptionsInterface } from './AdditionalOptions.types';
import { MongodbTLSCertificate } from './MongodbTLSCertificate';
import { MysqlTLSCertificate } from './MysqlTLSCertificate';
import { PostgreTLSCertificate } from './PostgreTLSCertificate';
Expand All @@ -41,16 +41,55 @@ export const AdditionalOptionsFormPart: FC<AdditionalOptionsFormPartProps> = ({
);
};

export const PostgreSQLAdditionalOptions: FC<PostgreSQLAdditionalOptionsProps> = ({ isRDS, isAzure }) => (
<>
<h4>{Messages.form.labels.trackingOptions}</h4>
<RadioButtonGroupField
name="tracking"
data-testid="tracking-options-radio-button-group"
options={isRDS || isAzure ? rdsTrackingOptions : trackingOptions}
/>
</>
);
export const PostgreSQLAdditionalOptions: FC<PostgreSQLAdditionalOptionsProps> = ({ form, isRDS, isAzure }) => {
const selectedOption = form.getState()?.values?.autoDiscoveryOptions;
const [selectedValue, setSelectedValue] = useState<string>(selectedOption || AutoDiscoveryOptionsInterface.enabled);
const styles = useStyles2(getStyles);
const validators = [platformCoreValidators.containsNumber, ...platformCoreValidators.int32];

const getAutoDiscoveryLimitValue = (type: AutoDiscoveryOptionsInterface) =>
type === AutoDiscoveryOptionsInterface.enabled ? 0 : type === AutoDiscoveryOptionsInterface.disabled ? -1 : 10;

useEffect(() => {
setSelectedValue(selectedOption);
form.change('autoDiscoveryLimit', getAutoDiscoveryLimitValue(selectedOption));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedOption]);

return (
<>
<h4>{Messages.form.labels.trackingOptions}</h4>
<RadioButtonGroupField
name="tracking"
data-testid="tracking-options-radio-button-group"
options={isRDS || isAzure ? rdsTrackingOptions : trackingOptions}
className={styles.radioField}
fullWidth
/>
<h4>{Messages.form.labels.postgresqlDetails.autoDiscovery}</h4>
<div className={styles.group}>
<RadioButtonGroupField
name="autoDiscoveryOptions"
data-testid="auto-discovery-options-radio-button-group"
defaultValue={selectedValue}
options={autoDiscoveryOptions}
className={styles.radioField}
label={Messages.form.labels.postgresqlDetails.autoDiscoveryLimitOptions}
fullWidth
/>
<NumberInputField
key="autoDiscoveryLimit"
name="autoDiscoveryLimit"
defaultValue={0}
disabled={selectedValue !== AutoDiscoveryOptionsInterface.custom}
validators={validators}
label={Messages.form.labels.postgresqlDetails.autoDiscoveryLimit}
tooltipText={Messages.form.tooltips.postgresqlDetails.autoDiscoveryLimit}
/>
</div>
</>
);
};

const getTablestatValues = (type: TablestatOptionsInterface) => {
switch (type) {
Expand All @@ -69,7 +108,8 @@ const MySQLOptions = ({ form }: { form: FormApi }) => {
useEffect(() => {
setSelectedValue(selectedOption);
form.change('tablestats_group_table_limit', getTablestatValues(selectedOption));
}, [selectedOption, form]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedOption]);

return (
<>
Expand Down Expand Up @@ -115,6 +155,7 @@ export const getAdditionalOptions = (
/>
</>
<PostgreSQLAdditionalOptions
form={form}
isRDS={remoteInstanceCredentials.isRDS}
isAzure={remoteInstanceCredentials.isAzure}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ export enum TablestatOptionsInterface {
default = 'default',
custom = 'custom',
}

export enum AutoDiscoveryOptionsInterface {
enabled = 'enabled',
disabled = 'disabled',
custom = 'custom',
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export const Messages = {
postgresqlDetails: {
database: 'Database',
maxQueryLength: 'Max query length',
autoDiscovery: 'Auto-discovery',
autoDiscoveryLimit: 'Auto-discovery limit',
autoDiscoveryLimitOptions: 'State',
},
mysqlDetails: {
maxQueryLength: 'Max query length',
Expand Down Expand Up @@ -87,6 +90,7 @@ export const Messages = {
postgresqlDetails: {
database: 'Database (default: postgres)',
maxQueryLength: 'Max query length',
autoDiscoveryLimit: 'Auto-discovery limit',
},
mysqlDetails: {
maxQueryLength: 'Max query length',
Expand Down Expand Up @@ -126,6 +130,7 @@ export const Messages = {
postgresqlDetails: {
database: 'Database name',
maxQueryLength: 'Full Example (Fingerprint) storage is not allowed by default to have the best performance',
autoDiscoveryLimit: 'Turn off auto-discovery when the total count of databases exceeds the limit.',
},
mysqlDetails: {
maxQueryLength: 'Full Example (Fingerprint) storage is not allowed by default to have the best performance',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe('getAdditionalOptions ::', () => {
const fields = container.querySelectorAll('input');
const trakingFields = screen.getAllByTestId('tracking-radio-button');
expect(trakingFields.length).toBe(trackingOptions.length);
expect(fields.length).toBe(7);
expect(fields.length).toBe(12);
});
it('should render correct for RDS PostgreSQL', async () => {
const type = Databases.postgresql;
Expand All @@ -198,6 +198,6 @@ describe('getAdditionalOptions ::', () => {
const fields = container.querySelectorAll('input');
const trakingFields = screen.getAllByTestId('tracking-radio-button');
expect(trakingFields.length).toBe(rdsTrackingOptions.length);
expect(fields.length).toBe(8);
expect(fields.length).toBe(13);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface AdditionalOptionsFormPartProps {
export interface PostgreSQLAdditionalOptionsProps {
isRDS?: boolean;
isAzure?: boolean;
form: FormApi;
}

export enum Schema {
Expand Down
5 changes: 5 additions & 0 deletions public/app/percona/shared/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ export const DATABASE_ICONS: Record<Databases, string> = {
[Databases.mariadb]: 'percona-database-mysql',
[Databases.haproxy]: 'percona-database-haproxy',
};

export const INT_32 = {
min: -2147483648,
max: 2147483647,
};
1 change: 1 addition & 0 deletions public/app/percona/shared/helpers/validatorsForm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export { maxLength } from './maxLength';
export { required } from './required';
export { requiredTrue } from './requiredTrue';
export { minTags } from './minTags';
export { int32 } from './int32';
export * from './validator.types';
export * as validators from '.';
5 changes: 5 additions & 0 deletions public/app/percona/shared/helpers/validatorsForm/int32.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { INT_32 } from '../../core';

import { lessThan, greaterThan } from '.';

export const int32 = [greaterThan(INT_32.min - 1), lessThan(INT_32.max + 1)];

0 comments on commit 5e2a721

Please sign in to comment.