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

Everest-864 | reset backups and monitoring on namespace change #1100

Merged
merged 17 commits into from
Feb 20, 2025
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
8 changes: 7 additions & 1 deletion ui/apps/everest/.e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ export default defineConfig({
},
testDir: 'pr',
testIgnore: ['pr/rbac/**/*'],
dependencies: ['setup', 'rbac', 'rbac-teardown'],
dependencies: [
'setup',
...(process.env.IGNORE_RBAC_TESTS &&
process.env.IGNORE_RBAC_TESTS !== 'false'
? []
: ['rbac', 'rbac-teardown']),
],
},
{
name: 'release',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,42 @@ test.describe('DB Cluster creation', () => {
await fillScheduleModalForm(page, undefined, undefined, false, '1');
await expect(page.getByTestId('same-schedule-warning')).toBeVisible();
});

test('Reset schedules, PITR and monitoring when changing namespace', async ({
page,
}) => {
expect(storageClasses.length).toBeGreaterThan(0);
await selectDbEngine(page, 'psmdb');
await expect(page.getByText(storageClasses[0])).toBeVisible();
await moveForward(page);
await moveForward(page);
await addFirstScheduleInDBWizard(page);
await page
.getByTestId('switch-input-pitr-enabled-label')
.getByRole('checkbox')
.check();
await moveForward(page);
await moveForward(page);
await page
.getByTestId('switch-input-monitoring-label')
.getByRole('checkbox')
.check();

const monitoringPreviewContent = page
.getByTestId('section-monitoring')
.getByTestId('preview-content');

expect(await monitoringPreviewContent.textContent()).toBe('Enabled');
await expect(page.getByText('PITR Enabled')).toBeVisible();
await expect(page.getByText('Backups disabled')).not.toBeVisible();

await goToStep(page, 'basic-information');
await page.getByTestId('text-input-k8s-namespace').click();

const namespacesOptions = page.getByRole('option');
await namespacesOptions.nth(1).click();
expect(await monitoringPreviewContent.textContent()).toBe('Disabled');
await expect(page.getByText('Backups disabled')).toBeVisible();
await expect(page.getByText('PITR disabled')).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -209,48 +209,48 @@ test.describe('Sharding (psmdb)', () => {
await selectDbEngine(page, 'psmdb');

await page.getByTestId('switch-input-sharding').click();
expect(page.getByTestId('switch-input-sharding')).toBeEnabled();
await expect(page.getByTestId('switch-input-sharding')).toBeEnabled();

await moveForward(page);

expect(page.getByTestId(`toggle-button-routers-3`)).toHaveAttribute(
await expect(page.getByTestId(`toggle-button-routers-3`)).toHaveAttribute(
'aria-pressed',
'true'
);
expect(page.getByTestId('shard-config-servers-3')).toHaveAttribute(
await expect(page.getByTestId('shard-config-servers-3')).toHaveAttribute(
'aria-pressed',
'true'
);

await page.getByTestId('toggle-button-nodes-1').click();
expect(page.getByTestId('shard-config-servers-1')).toHaveAttribute(
await expect(page.getByTestId('shard-config-servers-1')).toHaveAttribute(
'aria-pressed',
'true'
);
await page.getByTestId('toggle-button-nodes-5').click();
expect(page.getByTestId('shard-config-servers-5')).toHaveAttribute(
await expect(page.getByTestId('shard-config-servers-5')).toHaveAttribute(
'aria-pressed',
'true'
);
await page.getByTestId('toggle-button-nodes-custom').click();
await page.getByTestId('text-input-custom-nr-of-nodes').fill('7');
expect(page.getByTestId('shard-config-servers-7')).toHaveAttribute(
await expect(page.getByTestId('shard-config-servers-7')).toHaveAttribute(
'aria-pressed',
'true'
);
await page.getByTestId('text-input-custom-nr-of-nodes').fill('9');
expect(page.getByTestId('shard-config-servers-7')).toHaveAttribute(
await expect(page.getByTestId('shard-config-servers-7')).toHaveAttribute(
'aria-pressed',
'true'
);

await page.getByTestId('shard-config-servers-3').click();
await page.getByTestId('toggle-button-nodes-1').click();
expect(page.getByTestId('shard-config-servers-1')).toHaveAttribute(
await expect(page.getByTestId('shard-config-servers-1')).toHaveAttribute(
'aria-pressed',
'false'
);
expect(page.getByTestId('shard-config-servers-3')).toHaveAttribute(
await expect(page.getByTestId('shard-config-servers-3')).toHaveAttribute(
'aria-pressed',
'true'
);
Expand All @@ -263,19 +263,19 @@ test.describe('Sharding (psmdb)', () => {
await selectDbEngine(page, 'psmdb');

await page.getByTestId('switch-input-sharding').click();
expect(page.getByTestId('switch-input-sharding')).toBeEnabled();
await expect(page.getByTestId('switch-input-sharding')).toBeEnabled();

await moveForward(page);
await moveBack(page);

expect(page.getByTestId('switch-input-sharding')).toBeEnabled();
await expect(page.getByTestId('switch-input-sharding')).toBeEnabled();

await moveForward(page);
await moveForward(page);

await page.getByTestId('edit-section-1').click();

await page.getByTestId('switch-input-sharding').waitFor();
expect(page.getByTestId('switch-input-sharding')).toBeEnabled();
await expect(page.getByTestId('switch-input-sharding')).toBeEnabled();
});
});
19 changes: 13 additions & 6 deletions ui/apps/everest/.e2e/pr/db-cluster/db-wizard/db-wizard-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,22 @@ export const addFirstScheduleInDBWizard = async (page: Page) => {
page.getByTestId('editable-item').getByText('Monthly on day 10 at 1:05 AM')
).toBeVisible();

const namespace = (
await page
.getByTestId('section-basic-information')
.getByText('Namespace: ', { exact: false })
.innerText()
).split('Namespace: ')[1];
const matchingBucketNamespace = bucketNamespacesMap.find((b) =>
b[1].includes(namespace)
)[0];

if (await checkDbTypeisVisibleInPreview(page, DbType.Mongo)) {
expect(
await page.getByText(bucketNamespacesMap[0][0]).allInnerTexts()
await page.getByText(matchingBucketNamespace).allInnerTexts()
).toHaveLength(2);
} else {
await expect(page.getByText(bucketNamespacesMap[0][0])).toBeVisible();
await expect(page.getByText(matchingBucketNamespace)).toBeVisible();
}
};

Expand Down Expand Up @@ -153,10 +163,7 @@ export const fillScheduleModalForm = async (
await storageLocationField.click();

const storageOptions = page.getByRole('option');
const testStorage = storageOptions.filter({
hasText: bucketNamespacesMap[0][0],
});
await testStorage.click();
await storageOptions.first().click();
}

const retentionCopiesField = page.getByTestId('text-input-retention-copies');
Expand Down
38 changes: 10 additions & 28 deletions ui/apps/everest/.e2e/pr/multinamespaces/monitoring.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,16 @@ test.describe('Namespaces: Monitoring availability', () => {
await moveForward(page);
// Monitoring Step
await moveForward(page);
const monitoringCheckbox = await page
.getByTestId('switch-input-monitoring-label')
.getByRole('checkbox');
expect(await monitoringCheckbox.isChecked()).toBeFalsy();
await monitoringCheckbox.check();

// check monitoring is not available
await expect(page.getByTestId('monitoring-warning')).toBeVisible();
expect(await page.getByLabel('Enable monitoring').isChecked()).toBeFalsy();
await page.getByRole('button', { name: 'Add monitoring endpoint' }).click();

// filling in monitoring modal form
await page.getByTestId('text-input-name').fill(pxcMonitoringEndpoint);
const namespaces = page.getByTestId('text-input-namespace');
await namespaces.click();
await page
.getByRole('option', { name: EVEREST_CI_NAMESPACES.PXC_ONLY })
.click();
await page.getByTestId('text-input-url').fill(MONITORING_URL);
await page.getByTestId('text-input-user').fill(MONITORING_USER);
await page.getByTestId('text-input-password').fill(MONITORING_PASSWORD);

await expect(page.getByTestId('form-dialog-add')).toBeEnabled();
await page.getByTestId('form-dialog-add').click();

await expect(page.getByTestId('monitoring-warning')).not.toBeVisible();
await expect(page.getByTestId('switch-input-monitoring')).toBeEnabled();

await deleteMonitoringInstance(
request,
EVEREST_CI_NAMESPACES.PXC_ONLY,
pxcMonitoringEndpoint,
token
);
await page.getByTestId('text-input-monitoring-instance').click();
const namespaces = page.getByRole('option');
// This might eventually fail if someday we change the namespaces env variable logic
// But now, we know we add one endpoint per namespace
expect(await namespaces.count()).toBe(1);
});
});
4 changes: 3 additions & 1 deletion ui/apps/everest/.e2e/pr/settings/monitoring-list.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ test.describe.serial('Monitoring List', () => {
const namespaces = page.getByTestId('text-input-namespace');
await namespaces.click();
await expect(
page.getByText(EVEREST_CI_NAMESPACES.EVEREST_UI)
page
.getByRole('option')
.filter({ hasText: EVEREST_CI_NAMESPACES.EVEREST_UI })
).toBeVisible();
await page.getByRole('option').last().click();
await page.getByTestId('text-input-url').fill(MONITORING_URL);
Expand Down
41 changes: 41 additions & 0 deletions ui/apps/everest/.e2e/setup/global.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const {
EVEREST_LOCATION_SECRET_KEY,
EVEREST_LOCATION_REGION,
EVEREST_LOCATION_URL,
MONITORING_URL,
MONITORING_USER,
MONITORING_PASSWORD,
} = process.env;

const doBackupCall = async (fn: () => Promise<APIResponse>, retries = 3) => {
Expand All @@ -39,6 +42,10 @@ const doBackupCall = async (fn: () => Promise<APIResponse>, retries = 3) => {
return Promise.resolve();
}

if (response.status() === 409) {
return Promise.resolve();
}

if (statusText && statusText.message) {
if (statusText.message.includes('Could not read')) {
if (retries > 0) {
Expand Down Expand Up @@ -117,6 +124,40 @@ setup('Backup storages', async ({ request }) => {
await Promise.all(promises);
});

setup('Monitoring endpoints', async ({ request }) => {
const token = await getTokenFromLocalStorage();
const bucketNamespacesMap = getBucketNamespacesMap();
const allNamespaces = Array.from(
new Set(bucketNamespacesMap.map(([, namespaces]) => namespaces).flat())
);
const promises: Promise<any>[] = [];

// For the sake of simplicity, we will create a monitoring endpoint for all namespaces in the buckets we defined
for (const [idx, namespace] of allNamespaces.entries()) {
promises.push(
doBackupCall(() =>
request.post(`/v1/namespaces/${namespace}/monitoring-instances`, {
data: {
name: `e2e-endpoint-${idx}`,
type: 'pmm',
url: MONITORING_URL,
allowedNamespaces: [],
verifyTLS: false,
pmm: {
user: MONITORING_USER,
password: MONITORING_PASSWORD,
},
},
headers: {
Authorization: `Bearer ${token}`,
},
})
)
);
}
await Promise.all(promises);
});

setup('Close modal permanently', async ({ page }) => {
await page.goto('/');
await expect(page.getByTestId('lets-go-button')).toBeVisible();
Expand Down
18 changes: 18 additions & 0 deletions ui/apps/everest/.e2e/teardown/global.teardown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import { test as setup, expect } from '@playwright/test';
import { getTokenFromLocalStorage } from '../utils/localStorage';
import { getBucketNamespacesMap } from '../constants';
import { deleteMonitoringInstance } from '@e2e/utils/monitoring-instance';

setup.describe.serial('Teardown', () => {
setup('Delete backup storage', async ({ request }) => {
Expand Down Expand Up @@ -49,6 +50,23 @@ setup.describe.serial('Teardown', () => {
await Promise.all(promises);
});

setup('Delete monitoring instances', async ({ request }) => {
const token = await getTokenFromLocalStorage();
const bucketNamespacesMap = getBucketNamespacesMap();
const allNamespaces = Array.from(
new Set(bucketNamespacesMap.map(([, namespaces]) => namespaces).flat())
);

for (const [idx, namespace] of allNamespaces.entries()) {
await deleteMonitoringInstance(
request,
namespace,
`e2e-endpoint-${idx}`,
token
);
}
});

// setup('Delete monitoring instances', async ({ request }) => {
// await deleteMonitoringInstance(request, testMonitoringName);
// await deleteMonitoringInstance(request, testMonitoringName2);
Expand Down
22 changes: 13 additions & 9 deletions ui/apps/everest/.e2e/utils/monitoring-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,30 @@ export const testMonitoringName2 = 'ui-test-monitoring-1';
export const createMonitoringInstance = async (
request: APIRequestContext,
name: string,
namespaces: string[],
namespace: string,
token: string
) => {
const data = {
type: 'pmm',
name,
allowedNamespaces: namespaces,
type: 'pmm',
url: MONITORING_URL,
allowedNamespaces: [],
verifyTLS: false,
pmm: {
user: MONITORING_USER,
password: MONITORING_PASSWORD,
},
};

const response = await request.post('/v1/monitoring-instances', {
data,
headers: {
Authorization: `Bearer ${token}`,
},
});
const response = await request.post(
`/v1/namespaces/${namespace}/monitoring-instances`,
{
data,
headers: {
Authorization: `Bearer ${token}`,
},
}
);

expect(response.ok()).toBeTruthy();
};
Expand Down
1 change: 1 addition & 0 deletions ui/apps/everest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"test:watch": "vitest",
"pre-e2e": "rm -rf tests-out test-results && tsc --incremental --noImplicitAny false -p .e2e/tsconfig.json && tsc-alias -p .e2e/tsconfig.json",
"e2e": "node ./setup-e2e-rbac-user.js && pnpm pre-e2e && cd .e2e && playwright test --project=pr",
"e2e:ignore-rbac": "pnpm pre-e2e && cd .e2e && IGNORE_RBAC_TESTS=true playwright test --project=pr",
"e2e:upgrade": "pnpm pre-e2e && cd .e2e && playwright test --project=upgrade",
"e2e:release": "pnpm pre-e2e && cd .e2e && playwright test --project=release",
"build": "tsc --incremental && vite build --emptyOutDir",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@ export const FirstStep = ({ loadingDefaultsForEdition }: StepProps) => {
DB_WIZARD_DEFAULTS.monitoringInstance
);
setValue(DbWizardFormFields.monitoring, DB_WIZARD_DEFAULTS.monitoring);
setValue(
DbWizardFormFields.monitoringInstance,
DB_WIZARD_DEFAULTS.monitoringInstance
);
setValue(DbWizardFormFields.schedules, []);
setValue(DbWizardFormFields.pitrEnabled, false);
};

const setDefaultsForDbType = useCallback((dbType: DbType) => {
Expand Down
Loading