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

Add Sharding Support to PSMDB Demand Backup Test #918

Open
wants to merge 50 commits into
base: main
Choose a base branch
from

Conversation

edithturn
Copy link
Contributor

Demand backup test for PSMDB to include sharding:

  • Set up a sharded cluster with 2 shards and 3 nodes each.
  • Add a test collection and enable sharding on it.
  • Add an unsharded test collection (expected to land on the second shard).
  • Perform backup, drop data, restore, and verify data integrity.
  • Clean up by deleting backups, restores, and the cluster.

The reference script for this implementation was: demand-backup.e2e.ts

@edithturn edithturn requested a review from a team as a code owner December 10, 2024 10:48
ui/apps/everest/.e2e/utils/db-cmd-line.ts Outdated Show resolved Hide resolved
ui/apps/everest/.e2e/utils/db-cmd-line.ts Outdated Show resolved Hide resolved
ui/apps/everest/.e2e/utils/db-cmd-line.ts Outdated Show resolved Hide resolved
ui/apps/everest/.e2e/utils/db-cmd-line.ts Outdated Show resolved Hide resolved
ui/apps/everest/.e2e/utils/db-cmd-line.ts Outdated Show resolved Hide resolved
ui/apps/everest/.e2e/utils/db-cmd-line.ts Outdated Show resolved Hide resolved
ui/apps/everest/.e2e/utils/db-cmd-line.ts Show resolved Hide resolved
);
};

export const validateMongoDBSharding = async (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add parameter to this function for collection so you can just call it twice in the test with different collection parameter so that you don't duplicate the code for t1 and t2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a new parameter for the collection

export const validateMongoDBSharding = async (
  cluster: string,
  namespace: string,
  collectionName: string
) => {
  const collectionString = await queryPSMDB(
    cluster,
    namespace,
    'config',
    `db.collections.find({ _id: \\"test.${collectionName}\\" });`
  );

);

// Shard t1
await queryPSMDB(cluster, namespace, 'test', 'db.t1.createIndex({ a: 1 });');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move createIndex to prepareMongoDBTestDB function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, now createIndex is inside prepareMongoDBTestDB

);

// Shard t2
await queryPSMDB(cluster, namespace, 'test', 'db.t2.createIndex({ b: 1 });');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move createIndex to prepareMongoDBTestDB function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

cluster,
namespace,
'test',
'db.t2.insertMany([{ b: 1 }, { b: 2 }, { b: 3 }]);'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please call the keys the same as in t1, so { a: 1 }, { a: 2 }, { a: 3 }. It will simplify things because we will have 1 function for configureMongoSharding which will just take parameter for collection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering the keys of booth collections the same:

t1 Collection String: 
  
    _id: 'test.t1',
    key: { a: 1 },

t2 Collection String:

    _id: 'test.t2',
    key: { a: 1 },

);
};

export const configureMongoDBSharding = async (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add parameter for collection name to this function and call it twice so that there is no code duplication for t1 and t2.
enableSharding can be called in the test directly or it can be left here because I don't think it will have any effect if the sharding is already enabled on the collection.

Copy link
Contributor Author

@edithturn edithturn Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created shardCollection inside configureMongoDBSharding, and calling it to times for t1 and t2

const shardCollection = async (
    collectionName: string,
    key: object,
    splitKey: object
  ) => {
    await queryPSMDB(
      cluster,
      namespace,
      'admin',
      `sh.shardCollection(\\"test.${collectionName}\\", ${JSON.stringify(key)});`
    );

queryTestDB,
} from '@e2e/utils/db-cmd-line';

export let isShardingEnabled = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems strange exporting this from the test and importing it into helper functions. Let's create a function psmdbShardingEnabled in db-cmd-line.ts and then use it inside the same file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted for this:

// Enable replicaSet option if sharding is enabled
  const isShardingEnabled = true;
  const replicaSetOption = isShardingEnabled ? '' : '&replicaSet=rs0';

Since the function queryPSMDB will be call when we test sharding, so I am assuming it will be activate it, let me know your toughs, Tomislav.

const isChecked = await shardingCheckbox?.isChecked();
if (!isChecked) {
if (shardingCheckbox) {
isShardingEnabled = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we create a new function in db-cmd-line.ts we don't need this here. Also we want to check if sharding is actually enabled in the backend (api call) and not did we just click on something in UI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I removed!

// await moveForward(page);
});

// Step to set number of shards
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment since test description below has the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Comment on lines 243 to 245
//if (db != 'psmdb') {
// expect(addedCluster?.spec.proxy.replicas).toBe(size);
//}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

);
expect(addedCluster?.spec.engine.storage.size.toString()).toBe('1Gi');
expect(addedCluster?.spec.proxy.expose.type).toBe('internal');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add something like:

expect(addedCluster?.spec.sharding.enabled).toBe(true)
expect(addedCluster?.spec.sharding.shards).toBe(2)
expect(addedCluster?.spec.sharding.configServer.replicas).toBe(3)
expect(addedCluster?.spec.proxy.replicas).toBe(3)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

expect(storageClasses.length).toBeGreaterThan(0);

await page.goto('/databases');
await page.getByTestId('add-db-cluster-button').waitFor();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this part should be moved to utils to avoid duplication 🤔 we call the cluster creation button in a lot of places

tplavcic and others added 10 commits January 8, 2025 10:02
* First Version Readme 1.4.0 Everest

* First Version Readme 1.4.0 Everest

* First Version Readme 1.4.0 Everest

* Fixing tittle

* Fixing Typos and aligns

* Fixing Typos

* Fixing Typos

* Hel Section finish

* Hel Section finish

* CLI Section finish

* Update Readme for HELM

* Udd link for our helm chardts

* Update README.md

Removing Notes
…e` flags (percona#991)

* EVEREST-1794 Extend help description for `everestctl namespaces remove` flags

* Revert go.sum

* Fix formatting

* Update commands/namespaces/remove.go

Co-authored-by: Mayank Shah <[email protected]>

* EVEREST-1794 Fix go mods after merge

---------

Co-authored-by: Mayank Shah <[email protected]>
* chore: test upgrades RBAC

* chore: test cluster creation RBAC

* chore: test cluster creation RBAC

* chore: update playwright

* chore: refactor mock request

* chore: test DB actions

* feat: add code commands to add namespaces

* fix: bad routing on cluster details

* chore: test overview actions

* chore: use kubectl to change permissions on tests

* chore: apply kubectl for all permissions on tests

* chore: test invisible actions

* chore: remove unused var

* chore: test backups

* chore: test storages RBAC

* chore: test schedules

* chore: further schedules RBAC tests

* chore: test restores RBAC

* chore: further test restores RBAC

* chore: refactor e2e RBAC utils

* chore: rename setRBACPermissions fn

* chore: simplify RBAC changes logic

* chore: test new tests flow for RBAC

* chore: improve RBAC test flow

* fix: bash error

* chore: remove unused var

* chore: remove unused import

---------

Co-authored-by: Mayank Shah <[email protected]>
@edithturn edithturn requested a review from a team as a code owner January 15, 2025 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants