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-12608 Add auto discovery limit for PG #695

Merged
merged 12 commits into from
Nov 16, 2023
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,14 @@ export const tablestatOptions = [
label: Messages.form.tablestatOptions.custom,
},
];

export const autoDiscoveryOptions = [
{
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,9 @@ export const Messages = {
default: 'Default',
custom: 'Custom',
},
autoDiscoveryOptions: {
disabled: 'Disabled',
custom: 'Custom',
},
},
};
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { FormApi } from 'final-form';
import React, { FC, useEffect, useState } from 'react';
import React, { FC, useEffect, useMemo, useState } from 'react';

import { useStyles2 } from '@grafana/ui';
import { InstanceAvailableType, RemoteInstanceCredentials } from 'app/percona/add-instance/panel.types';
import { CheckboxField } from 'app/percona/shared/components/Elements/Checkbox';
import { NumberInputField } from 'app/percona/shared/components/Form/NumberInput';
import { RadioButtonGroupField } from 'app/percona/shared/components/Form/RadioButtonGroup';
import { Databases } from 'app/percona/shared/core';
import validators from 'app/percona/shared/helpers/validators';
import { validators as platformCoreValidators } from 'app/percona/shared/helpers/validatorsForm';

import { rdsTrackingOptions, trackingOptions } from '../FormParts.constants';
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 +42,58 @@ 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 && form.getState().values.autoDiscoveryOptions;
doracretu3pillar marked this conversation as resolved.
Show resolved Hide resolved
const [selectedValue, setSelectedValue] = useState<string>(selectedOption || AutoDiscoveryOptionsInterface.disabled);
const autoDiscoveryValidators = useMemo(() => [validators.min(0)], []);
const styles = useStyles2(getStyles);

const getAutoDiscoveryLimitValue = (type: AutoDiscoveryOptionsInterface) => {
switch (type) {
doracretu3pillar marked this conversation as resolved.
Show resolved Hide resolved
case AutoDiscoveryOptionsInterface.disabled:
return 0;
default:
return 1000;
}
};

useEffect(() => {
setSelectedValue(selectedOption);
form.change('autoDiscoveryLimit', getAutoDiscoveryLimitValue(selectedOption));
}, [selectedOption, form]);

return (
<>
<h4>{Messages.form.labels.trackingOptions}</h4>
<RadioButtonGroupField
name="tracking"
data-testid="tracking-options-radio-button-group"
options={isRDS || isAzure ? rdsTrackingOptions : trackingOptions}
/>
<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={autoDiscoveryValidators}
label={Messages.form.labels.postgresqlDetails.autoDiscoveryLimit}
tooltipText={Messages.form.tooltips.postgresqlDetails.autoDiscoveryLimit}
/>
</div>
</>
);
};

const getTablestatValues = (type: TablestatOptionsInterface) => {
switch (type) {
Expand Down Expand Up @@ -115,6 +158,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,8 @@ export enum TablestatOptionsInterface {
default = 'default',
custom = 'custom',
}

export enum AutoDiscoveryOptionsInterface {
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: 'TODO',
matejkubinec marked this conversation as resolved.
Show resolved Hide resolved
},
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(11);
});
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(12);
});
});
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
Loading