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-13166: Ability to monitor DBs from a different node #766

Merged
merged 35 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a3ef553
Nodes for MySQLConnection
doracretu3pillar Jul 24, 2024
a0353ac
Added Nodes Agents component
doracretu3pillar Jul 29, 2024
c39224b
Added pmm_agent_id parameter instead of agent/node
doracretu3pillar Jul 29, 2024
98f238a
Added NodesAgents to all the services
doracretu3pillar Aug 5, 2024
218ccdd
Fixes after reviews
doracretu3pillar Aug 16, 2024
2db183c
Testing NodesAgents in progress
doracretu3pillar Aug 21, 2024
c549be1
Added NodesAgents test
doracretu3pillar Aug 22, 2024
af05984
Fix from PR
doracretu3pillar Aug 29, 2024
cd89d7b
Fixes after PR
doracretu3pillar Sep 6, 2024
cc639cd
Prettier fix
DoraCretu594118 Sep 10, 2024
dfb3498
Merge branch 'v3' into PMM-13166_nodes_monitor_db
doracretu3pillar Sep 10, 2024
395a1a7
Fixed ts issues
DoraCretu594118 Sep 10, 2024
f2a327f
Merge branch 'PMM-13166_nodes_monitor_db' of https://github.com/perco…
DoraCretu594118 Sep 10, 2024
088e376
Added the types to mappedNodes, nodesOptions, changed the agent name …
doracretu3pillar Sep 19, 2024
17f0547
Updated tests - partial
doracretu3pillar Sep 19, 2024
ade9992
Merge branch 'v3' into PMM-13166_nodes_monitor_db
doracretu3pillar Sep 20, 2024
fee3eed
Partially tests
doracretu3pillar Sep 20, 2024
44c2d5d
Fixed tests
doracretu3pillar Sep 20, 2024
d64b7e8
Added node_type to node mocks and fixed eslint for NodesAgents
doracretu3pillar Sep 20, 2024
d8318ae
Fixed other tests related to Add Service
doracretu3pillar Sep 20, 2024
b95747b
More tests fixed
doracretu3pillar Sep 20, 2024
78507cb
Fixed prettier
doracretu3pillar Sep 20, 2024
ced9f39
Added spy on console.error
doracretu3pillar Sep 21, 2024
c478147
Added test for console error
doracretu3pillar Sep 21, 2024
40fbcbb
Added console error check to every test
doracretu3pillar Sep 21, 2024
864dfe4
Fixes after PR
doracretu3pillar Sep 23, 2024
68548b7
Replaced the formAPI with taken values from the form, and added new m…
doracretu3pillar Sep 23, 2024
59e041f
SelectedAgent can be undefined
doracretu3pillar Sep 23, 2024
09b6adb
Clear mock before each test
doracretu3pillar Sep 23, 2024
6c07180
Added wait for to last test
doracretu3pillar Sep 23, 2024
24f3a77
If address is localhost then send node_id instead of add_node, and se…
doracretu3pillar Sep 30, 2024
2618cbf
Fixes after PR
doracretu3pillar Sep 30, 2024
09097c3
Fixed prettier
doracretu3pillar Sep 30, 2024
4bd8d20
Merge branch 'v3' into PMM-13166_nodes_monitor_db
doracretu3pillar Sep 30, 2024
4476cbc
Merge branch 'v3' into PMM-13166_nodes_monitor_db
doracretu3pillar Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ describe('AddRemoteInstanceService:: ', () => {
replication_set: 'test',
cluster: 'test',
custom_labels: 'test:test',
pmm_agent_id: {
value: 'pmm-server',
},
};

const payload = {
Expand Down Expand Up @@ -93,7 +96,7 @@ describe('AddRemoteInstanceService:: ', () => {
qan_postgresql_pgstatements_agent: true,
metrics_mode: 1,
};

expect(toPayload(data)).toStrictEqual(payload);
const expected = toPayload(data);
expect(expected).toStrictEqual(payload);
doracretu3pillar marked this conversation as resolved.
Show resolved Hide resolved
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,11 @@ export const toPayload = (values: any, discoverName?: string, type?: InstanceAva
}
}

data.pmm_agent_id = values.pmm_agent_id.value;

data.metrics_mode = 1;
delete data.tracking;
delete data.node;

return data;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { Provider } from 'react-redux';

import { Databases } from 'app/percona/shared/core';
import { configureStore } from 'app/store/configureStore';

import { InstanceTypesExtra } from '../../panel.types';

Expand All @@ -20,7 +22,11 @@ jest.mock('app/percona/shared/helpers/logger', () => {
describe('Add remote instance:: ', () => {
it('should render correct for mysql and postgres and highlight empty mandatory fields on submit', async () => {
const type = Databases.mysql;
render(<AddRemoteInstance onSubmit={jest.fn()} instance={{ type, credentials: {} }} selectInstance={jest.fn()} />);
render(
<Provider store={configureStore()}>
<AddRemoteInstance onSubmit={jest.fn()} instance={{ type, credentials: {} }} selectInstance={jest.fn()} />
</Provider>
);

expect(screen.getByTestId('address-text-input').classList.contains('invalid')).toBe(false);
expect(screen.getByTestId('username-text-input').classList.contains('invalid')).toBe(false);
Expand All @@ -35,7 +41,11 @@ describe('Add remote instance:: ', () => {

it('should render for external service and highlight empty mandatory fields on submit', async () => {
const type = InstanceTypesExtra.external;
render(<AddRemoteInstance onSubmit={jest.fn()} instance={{ type, credentials: {} }} selectInstance={jest.fn()} />);
render(
<Provider store={configureStore()}>
<AddRemoteInstance onSubmit={jest.fn()} instance={{ type, credentials: {} }} selectInstance={jest.fn()} />
</Provider>
);

expect(screen.getByTestId('address-text-input').classList.contains('invalid')).toBe(false);
expect(screen.getByTestId('metrics_path-text-input').classList.contains('invalid')).toBe(false);
Expand All @@ -55,7 +65,11 @@ describe('Add remote instance:: ', () => {
it('should render correct for HAProxy and highlight empty mandatory fields on submit', async () => {
const type = Databases.haproxy;

render(<AddRemoteInstance onSubmit={jest.fn()} instance={{ type, credentials: {} }} selectInstance={jest.fn()} />);
render(
<Provider store={configureStore()}>
<AddRemoteInstance onSubmit={jest.fn()} instance={{ type, credentials: {} }} selectInstance={jest.fn()} />
</Provider>
);

expect(screen.getByTestId('address-text-input').classList.contains('invalid')).toBe(false);
expect(screen.getByTestId('username-text-input').classList.contains('invalid')).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Get instance data:: ', () => {
port: '5432',
metricsParameters: 'manually',
schema: 'https',
pmm_agent_id: '',
},
};

Expand Down Expand Up @@ -77,6 +78,7 @@ describe('Get instance data:: ', () => {
port: '27017',
metricsParameters: 'manually',
schema: 'https',
pmm_agent_id: '',
},
};

Expand All @@ -100,6 +102,7 @@ describe('Get instance data:: ', () => {
port: '3306',
metricsParameters: 'manually',
schema: 'https',
pmm_agent_id: '',
},
};

Expand All @@ -123,6 +126,7 @@ describe('Get instance data:: ', () => {
port: '6032',
metricsParameters: 'manually',
schema: 'https',
pmm_agent_id: '',
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export const getInstanceData = (instanceType: InstanceAvailableType, credentials
remoteInstanceCredentials: {
metricsParameters: MetricsParameters.manually,
schema: Schema.HTTPS,
pmm_agent_id: '',
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { render, fireEvent, screen } from '@testing-library/react';
import React from 'react';
import { Form } from 'react-final-form';
import { Provider } from 'react-redux';

import { configureStore } from 'app/store/configureStore';

import { ExternalServiceConnectionDetails } from './ExternalServiceConnectionDetails';

describe('Add remote instance:: ', () => {
it('should render correct for mysql and postgres and highlight empty mandatory fields on submit', async () => {
render(
<Form
onSubmit={jest.fn()}
mutators={{
setValue: ([field, value], state, { changeValue }) => {
changeValue(state, field, () => value);
},
}}
render={({ form }) => <ExternalServiceConnectionDetails form={form} />}
/>
<Provider store={configureStore()}>
<Form
onSubmit={jest.fn()}
mutators={{
setValue: ([field, value], state, { changeValue }) => {
changeValue(state, field, () => value);
},
}}
render={({ form }) => <ExternalServiceConnectionDetails form={form} />}
/>
</Provider>
);

const metricsParametrsRadioState = screen.getByTestId('metricsParameters-radio-state');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { FC, useCallback, useEffect, useMemo } from 'react';

import { useStyles2 } from '@grafana/ui';
import { NodesAgents } from 'app/percona/add-instance/components/AddRemoteInstance/FormParts/NodesAgents/NodesAgents';
import { PasswordInputField } from 'app/percona/shared/components/Form/PasswordInput';
import { RadioButtonGroupField } from 'app/percona/shared/components/Form/RadioButtonGroup';
import { TextInputField } from 'app/percona/shared/components/Form/TextInput';
Expand Down Expand Up @@ -96,6 +97,7 @@ export const ExternalServiceConnectionDetails: FC<FormPartProps> = ({ form }) =>
/>
<div />
</div>
<NodesAgents form={form} />
<div className={styles.group}>
<TextInputField
name="address"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export const Messages = {
username: 'Username',
password: 'Password',
},
nodesAgents: {
nodes: 'Nodes',
agents: 'Agents',
},
mainDetails: {
address: 'Hostname',
serviceName: 'Service name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export const getStyles = ({ breakpoints, spacing, colors }: GrafanaTheme2) => ({
width: 100%;
margin-right: 5px;
`,
selectFieldWrapper: css`
width: 100%;
`,
selectField: css`
height: 38px;
`,
group: css`
display: flex;
flex-direction: row;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { render, screen } from '@testing-library/react';
import { FormApi, FormState } from 'final-form';
import React from 'react';
import { Form } from 'react-final-form';
import { Provider } from 'react-redux';

import { Databases } from 'app/percona/shared/core';
import { configureStore } from 'app/store/configureStore';

import { AdditionalOptionsFormPart, getAdditionalOptions } from './AdditionalOptions/AdditionalOptions';
import { ExternalServiceConnectionDetails } from './ExternalServiceConnectionDetails/ExternalServiceConnectionDetails';
Expand All @@ -20,14 +22,16 @@ const form: Partial<FormApi> = {
describe('MainDetailsFormPart ::', () => {
it('should disable fields with sat isRDS flag', async () => {
const { container } = render(
<Form
onSubmit={jest.fn()}
render={({ form }) => <MainDetailsFormPart form={form} remoteInstanceCredentials={{ isRDS: true }} />}
/>
<Provider store={configureStore()}>
<Form
onSubmit={jest.fn()}
render={({ form }) => <MainDetailsFormPart form={form} remoteInstanceCredentials={{ isRDS: true }} />}
/>
</Provider>
);

const fields = container.querySelectorAll('input');
expect(fields.length).toBe(5);
expect(fields.length).toBe(8);

expect(screen.getByTestId('address-text-input')).toBeDisabled();
expect(screen.getByTestId('serviceName-text-input')).not.toBeDisabled();
Expand All @@ -38,14 +42,16 @@ describe('MainDetailsFormPart ::', () => {

it('should disable fields with not sat isRDS flag', async () => {
const { container } = render(
<Form
onSubmit={jest.fn()}
render={({ form }) => <MainDetailsFormPart form={form} remoteInstanceCredentials={{ isRDS: false }} />}
/>
<Provider store={configureStore()}>
<Form
onSubmit={jest.fn()}
render={({ form }) => <MainDetailsFormPart form={form} remoteInstanceCredentials={{ isRDS: false }} />}
/>
</Provider>
);

const fields = container.querySelectorAll('input');
expect(fields.length).toBe(5);
expect(fields.length).toBe(8);

expect(screen.getByTestId('address-text-input')).not.toBeDisabled();
expect(screen.getByTestId('serviceName-text-input')).not.toBeDisabled();
Expand All @@ -58,10 +64,12 @@ describe('MainDetailsFormPart ::', () => {
describe('ExternalServiceConnectionDetails ::', () => {
it('should render', async () => {
const { container } = render(
<Form
onSubmit={jest.fn()}
render={() => <ExternalServiceConnectionDetails form={form as unknown as FormApi} />}
/>
<Provider store={configureStore()}>
<Form
onSubmit={jest.fn()}
render={() => <ExternalServiceConnectionDetails form={form as unknown as FormApi} />}
/>
</Provider>
);

const fields = container.querySelectorAll('input');
Expand Down Expand Up @@ -89,17 +97,19 @@ describe('AdditionalOptionsFormPart ::', () => {
};

render(
<Form
onSubmit={jest.fn()}
render={() => (
<AdditionalOptionsFormPart
instanceType={type}
remoteInstanceCredentials={remoteInstanceCredentials}
loading={false}
form={form as unknown as FormApi}
/>
)}
/>
<Provider store={configureStore()}>
<Form
onSubmit={jest.fn()}
render={() => (
<AdditionalOptionsFormPart
instanceType={type}
remoteInstanceCredentials={remoteInstanceCredentials}
loading={false}
form={form as unknown as FormApi}
/>
)}
/>
</Provider>
);

expect(screen.getByTestId('skip_connection_check-checkbox-input')).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { Form } from 'react-final-form';
import { Provider } from 'react-redux';

import { configureStore } from 'app/store/configureStore';

import { HAProxyConnectionDetails } from './HAProxyConnectionDetails';

describe('HAProxy connection details:: ', () => {
it('should trim username and password values right', () => {
render(<Form onSubmit={jest.fn()} render={() => <HAProxyConnectionDetails remoteInstanceCredentials={{}} />} />);
render(
<Provider store={configureStore()}>
<Form onSubmit={jest.fn()} render={() => <HAProxyConnectionDetails remoteInstanceCredentials={{}} />} />
</Provider>
);

const userNameTextInput = screen.getByTestId('username-text-input');
fireEvent.change(userNameTextInput, { target: { value: ' test ' } });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { FC, useCallback, useMemo } from 'react';

import { useStyles2 } from '@grafana/ui';
import { NodesAgents } from 'app/percona/add-instance/components/AddRemoteInstance/FormParts/NodesAgents/NodesAgents';
import { PasswordInputField } from 'app/percona/shared/components/Form/PasswordInput';
import { TextInputField } from 'app/percona/shared/components/Form/TextInput';
import Validators from 'app/percona/shared/helpers/validators';
Expand All @@ -10,7 +11,7 @@ import { Messages } from '../FormParts.messages';
import { getStyles } from '../FormParts.styles';
import { MainDetailsFormPartProps } from '../FormParts.types';

export const HAProxyConnectionDetails: FC<MainDetailsFormPartProps> = ({ remoteInstanceCredentials }) => {
export const HAProxyConnectionDetails: FC<MainDetailsFormPartProps> = ({ form, remoteInstanceCredentials }) => {
const styles = useStyles2(getStyles);

const portValidators = useMemo(() => [validators.required, Validators.validatePort], []);
Expand All @@ -29,6 +30,7 @@ export const HAProxyConnectionDetails: FC<MainDetailsFormPartProps> = ({ remoteI
/>
<div />
</div>
<NodesAgents form={form} />
<div className={styles.group}>
<TextInputField
name="address"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { FC, useMemo } from 'react';

import { useStyles2 } from '@grafana/ui';
import { NodesAgents } from 'app/percona/add-instance/components/AddRemoteInstance/FormParts/NodesAgents/NodesAgents';
import { PasswordInputField } from 'app/percona/shared/components/Form/PasswordInput';
import { TextInputField } from 'app/percona/shared/components/Form/TextInput';
import Validators from 'app/percona/shared/helpers/validators';
Expand Down Expand Up @@ -30,6 +31,7 @@ export const MainDetailsFormPart: FC<MainDetailsFormPartProps> = ({ form, remote
/>
<div />
</div>
<NodesAgents form={form} />
<div className={styles.group}>
<TextInputField
name="address"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { render, screen, fireEvent } from '@testing-library/react';
import React from 'react';
import { Form } from 'react-final-form';
import { Provider } from 'react-redux';

import { configureStore } from 'app/store/configureStore';

import { MongoDBConnectionDetails } from './MongoDBConnectionDetails';

describe('MongoDB connection details:: ', () => {
it('should have max query length attribute', () => {
render(<Form onSubmit={jest.fn()} render={() => <MongoDBConnectionDetails remoteInstanceCredentials={{}} />} />);
render(
<Provider store={configureStore()}>
<Form onSubmit={jest.fn()} render={() => <MongoDBConnectionDetails remoteInstanceCredentials={{}} />} />
</Provider>
);

const textInput = screen.getByTestId('maxQueryLength-text-input');
fireEvent.change(textInput, { target: { value: '1000' } });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { FC, useMemo } from 'react';

import { useStyles2 } from '@grafana/ui';
import { NodesAgents } from 'app/percona/add-instance/components/AddRemoteInstance/FormParts/NodesAgents/NodesAgents';
import { PasswordInputField } from 'app/percona/shared/components/Form/PasswordInput';
import { TextInputField } from 'app/percona/shared/components/Form/TextInput';
import Validators from 'app/percona/shared/helpers/validators';
Expand Down Expand Up @@ -31,6 +32,7 @@ export const MongoDBConnectionDetails: FC<MainDetailsFormPartProps> = ({ form, r
/>
<div />
</div>
<NodesAgents form={form} />
<div className={styles.group}>
<TextInputField
name="address"
Expand Down
Loading
Loading