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-13232 Fix SSL postgres for v3 #827

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions tests/pages/adminPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const pathToPmmQaRepo = process.env.PATH_TO_PMM_QA || '/srv/pmm-qa';

module.exports = {
url: 'graph/d/pmm-home/home-dashboard?orgId=1',
pathToFramework: `${pathToPmmQaRepo}/pmm-tests/pmm-framework.sh`,
pathToPMMTests: `${pathToPmmQaRepo}/pmm-tests/`,
pathToFramework: `${pathToPmmQaRepo}/pmm_qa/pmm-framework.py`,
pathToPMMTests: `${pathToPmmQaRepo}/pmm_qa/pmm-tests/`,
sideMenu: {
integratedAlerting: 'li > a[href="/graph/integrated-alerting"]',
alertingBellIcon: locate('$navbar-section').at(2).find('li a[aria-label="Alerting"]'),
Expand Down
18 changes: 12 additions & 6 deletions tests/pages/remoteInstancesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ module.exports = {
subscriptionID: '$azure_subscription_id-text-input',
tableStatsGroupTableLimit: '$tablestats_group_table_limit-number-input',
tenantID: '$azure_tenant_id-text-input',
tlscaInput: '$tls_ca-textarea-input',
tlsCertificateInput: '$tls_cert-textarea-input',
tlsCertificateKeyInput: '$tls_key-textarea-input',
tlscaInput: locate('$tls_ca-textarea-input'),
tlsCertificateInput: locate('$tls_cert-textarea-input'),
tlsCertificateKeyInput: locate('$tls_key-textarea-input'),
tlsCertificateFilePasswordInput: '$tls_certificate_file_password-password-input',
tlsCertificateKey: '$tls_certificate_key-textarea-input',
usePerformanceSchema2: '$qan_mysql_perfschema-field-container',
Expand Down Expand Up @@ -265,9 +265,15 @@ module.exports = {
I.dontSeeElement(this.fields.tlsCertificateInput);
I.click(this.fields.useTLS);
I.waitForElement(this.fields.tlscaInput, 30);
await this.fillFileContent(this.fields.tlscaInput, details.tlsCAFile);
await this.fillFileContent(this.fields.tlsCertificateInput, details.tlsCertFile);
await this.fillFileContent(this.fields.tlsCertificateKeyInput, details.tlsKeyFile);
I.usePlaywrightTo('Fill TLS ca field', async ({ page }) => {
await page.fill(this.fields.tlscaInput.toXPath(), details.tlsCA);
});
I.usePlaywrightTo('Fill TLS certificate field', async ({ page }) => {
await page.fill(this.fields.tlsCertificateInput.toXPath(), details.tlsCert);
});
I.usePlaywrightTo('Fill TLS certificate key field', async ({ page }) => {
await page.fill(this.fields.tlsCertificateKeyInput.toXPath(), details.tlsKey);
});
if (details.serviceType === 'postgres_ssl') I.click(this.fields.usePgStatStatements);

if (details.serviceType === 'mysql_ssl') I.click(this.fields.skipTLSL);
Expand Down
68 changes: 27 additions & 41 deletions tests/verifyTLSPostgresRemoteInstance_test.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,20 @@
const assert = require('assert');

const { adminPage } = inject();
const pmmFrameworkLoader = `bash ${adminPage.pathToFramework}`;
const pathToPMMFramework = adminPage.pathToPMMTests;
const noSslCheckServiceName = 'pg_no_ssl_check';

Feature('Monitoring SSL/TLS PGSQL instances');

const instances = new DataTable(['serviceName', 'version', 'container', 'serviceType', 'metric', 'maxQueryLength']);

instances.add(['pgsql_14_ssl_service', '14', 'pgsql_14', 'postgres_ssl', 'pg_stat_database_xact_rollback', '7']);
// skipping this due to bug in setup due to repo and packages
// instances.add(['pgsql_12_ssl_service', '12', 'pgsql_12', 'postgres_ssl', 'pg_stat_database_xact_rollback']);
// instances.add(['pgsql_11_ssl_service', '11', 'pgsql_11', 'postgres_ssl', 'pg_stat_database_xact_rollback']);
// instances.add(['pgsql_13_ssl_service', '13', 'pgsql_13', 'postgres_ssl', 'pg_stat_database_xact_rollback']);

BeforeSuite(async ({ I, codeceptjsConfig }) => {
// await I.verifyCommand(`${pmmFrameworkLoader} --pdpgsql-version=11 --setup-postgres-ssl --pmm2`);
// await I.verifyCommand(`${pmmFrameworkLoader} --pdpgsql-version=12 --setup-postgres-ssl --pmm2`);
// await I.verifyCommand(`${pmmFrameworkLoader} --pdpgsql-version=13 --setup-postgres-ssl --pmm2`);
await I.verifyCommand(`${pmmFrameworkLoader} --pdpgsql-version=14 --setup-postgres-ssl --pmm2`);
});

AfterSuite(async ({ I }) => {
// await I.verifyCommand('docker stop pgsql_11 || docker rm pgsql_11');
// await I.verifyCommand('docker stop pgsql_12 || docker rm pgsql_12');
// await I.verifyCommand('docker stop pgsql_13 || docker rm pgsql_13');
await I.verifyCommand('docker stop pgsql_14 || docker rm pgsql_14');
});

Before(async ({ I, settingsAPI }) => {
await I.Authorize();
});

const instances = new DataTable(['serviceName', 'version', 'container', 'serviceType', 'metric', 'maxQueryLength']);

instances.add(['pgsql_16_ssl_service', '16', 'pdpgsql_pgsm_ssl_16', 'postgres_ssl', 'pg_stat_database_xact_rollback', '7']);
// instances.add(['pgsql_14_ssl_service', '14', 'pdpgsql_pgsm_ssl_14', 'postgres_ssl', 'pg_stat_database_xact_rollback', '7']);
// instances.add(['pgsql_14_ssl_service', '13', 'pdpgsql_pgsm_ssl_13', 'postgres_ssl', 'pg_stat_database_xact_rollback', '7']);
// instances.add(['pgsql_12_ssl_service', '12', 'pdpgsql_pgsm_ssl_12', 'postgres_ssl', 'pg_stat_database_xact_rollback', '7']);

Data(instances).Scenario(
'PMM-T948 PMM-T947 Verify Adding SSL services remotely @ssl @ssl-postgres @ssl-remote @not-ui-pipeline',
async ({
Expand All @@ -55,9 +37,9 @@ Data(instances).Scenario(
password: 'pmm',
cluster: 'pgsql_remote_cluster',
environment: 'pgsql_remote_cluster',
tlsCAFile: `${pathToPMMFramework}tls-ssl-setup/postgres/${version}/ca.crt`,
tlsKeyFile: `${pathToPMMFramework}tls-ssl-setup/postgres/${version}/client.pem`,
tlsCertFile: `${pathToPMMFramework}tls-ssl-setup/postgres/${version}/client.crt`,
tlsCA: await I.verifyCommand(`docker exec ${container} cat certificates/ca.crt`),
tlsKey: await I.verifyCommand(`docker exec ${container} cat certificates/client.pem`),
tlsCert: await I.verifyCommand(`docker exec ${container} cat certificates/client.crt`),
};
}

Expand All @@ -71,7 +53,7 @@ Data(instances).Scenario(
serviceType: 'POSTGRESQL_SERVICE',
service: 'postgresql',
},
serviceName,
remoteServiceName,
);

// Check Remote Instance also added and have running status
Expand Down Expand Up @@ -103,7 +85,7 @@ Data(instances).Scenario(
I, remoteInstancesPage, pmmInventoryPage, current, grafanaAPI,
}) => {
const {
serviceName, metric,
serviceName, metric, container,
} = current;
let response;
let result;
Expand All @@ -113,7 +95,10 @@ Data(instances).Scenario(
I.wait(10);

// verify metric for client container node instance
response = await grafanaAPI.checkMetricExist(metric, { type: 'service_name', value: serviceName });
const localServiceName = await I.verifyCommand(`docker exec ${container} pmm-admin list | grep "PostgreSQL" | grep "ssl_service" | awk -F " " '{print $2}'`);

response = await grafanaAPI.checkMetricExist(metric, { type: 'service_name', value: localServiceName });

result = JSON.stringify(response.data.data.result);

assert.ok(response.data.data.result.length !== 0, `Metrics ${metric} from ${serviceName} should be available but got empty ${result}`);
Expand Down Expand Up @@ -184,7 +169,6 @@ Data(instances).Scenario(
adminPage.performPageDown(5);
await dashboardPage.expandEachDashboardRow();
adminPage.performPageUp(5);
await dashboardPage.verifyThereAreNoGraphsWithNA();
await dashboardPage.verifyThereAreNoGraphsWithoutData(1);
}
},
Expand All @@ -196,17 +180,19 @@ Data(instances).Scenario(
I, current, adminPage, queryAnalyticsPage,
}) => {
const {
serviceName,
serviceName, container,
} = current;

const serviceList = [serviceName, `remote_${serviceName}`, noSslCheckServiceName];
const localServiceName = await I.verifyCommand(`docker exec ${container} pmm-admin list | grep "PostgreSQL" | grep "ssl_service" | awk -F " " '{print $2}'`);

const serviceList = [localServiceName, `remote_${serviceName}`, noSslCheckServiceName];

for (const service of serviceList) {
I.amOnPage(I.buildUrlWithParams(queryAnalyticsPage.url, { from: 'now-5m' }));
queryAnalyticsPage.waitForLoaded();
await adminPage.applyTimeRange('Last 5 minutes');
queryAnalyticsPage.waitForLoaded();
await queryAnalyticsPage.filters.selectFilter(service);
await queryAnalyticsPage.filters.selectFilterInGroup(service, 'Service Name');
queryAnalyticsPage.waitForLoaded();
const count = await queryAnalyticsPage.data.getCountOfItems();

Expand Down Expand Up @@ -237,9 +223,9 @@ Data(instances).Scenario(
password: 'pmm',
cluster: 'pgsql_remote_cluster',
environment: 'pgsql_remote_cluster',
tlsCAFile: `${pathToPMMFramework}tls-ssl-setup/postgres/${version}/ca.crt`,
tlsKeyFile: `${pathToPMMFramework}tls-ssl-setup/postgres/${version}/client.pem`,
tlsCertFile: `${pathToPMMFramework}tls-ssl-setup/postgres/${version}/client.crt`,
tlsCA: await I.verifyCommand(`docker exec ${container} cat certificates/ca.crt`),
tlsKey: await I.verifyCommand(`docker exec ${container} cat certificates/client.pem`),
tlsCert: await I.verifyCommand(`docker exec ${container} cat certificates/client.crt`),
};
}

Expand All @@ -261,7 +247,7 @@ Data(instances).Scenario(
serviceType: 'POSTGRESQL_SERVICE',
service: 'postgresql',
},
serviceName,
remoteServiceName,
);

const { service_id } = await inventoryAPI.apiGetNodeInfoByServiceName('POSTGRESQL_SERVICE', remoteServiceName);
Expand All @@ -277,9 +263,9 @@ Data(instances).Scenario(
// Check max visible query length is less than max_query_length option
I.amOnPage(I.buildUrlWithParams(queryAnalyticsPage.url, { from: 'now-5m' }));
queryAnalyticsPage.waitForLoaded();
await queryAnalyticsPage.filters.selectFilter(remoteServiceName);
await queryAnalyticsPage.filters.selectFilterInGroup(remoteServiceName, 'Service Name');
I.waitForElement(queryAnalyticsPage.data.elements.queryRows, 30);
const queryFromRow = await queryAnalyticsPage.data.elements.queryRowValue(1);
const queryFromRow = await I.grabTextFrom(await queryAnalyticsPage.data.elements.queryRowValue(1));

if (maxQueryLength !== '' && maxQueryLength !== '-1') {
assert.ok(queryFromRow.length <= maxQueryLength, `Query length exceeds max length boundary equals ${queryFromRow.length} is more than ${maxQueryLength}`);
Expand Down
Loading