Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

EVG-19947: Support EC2 Fleet on provider settings page #2050

Merged
merged 7 commits into from
Sep 27, 2023

Conversation

minnakt
Copy link
Contributor

@minnakt minnakt commented Sep 19, 2023

EVG-19947

Description

This PR adds support for EC2 Fleet.

Initially, I was going to make the regions static as indicated by the designs. This would mean showing an item for each of the AWS regions by default, even if there are no settings that correspond to that region.

But then I found out that the backend validation doesn't allow incomplete entries in the provider settings list — that is, if there's an item corresponding to "us-west-1", then all of its required fields must be filled out. This means that I would have to filter out the "empty" regions before sending the output to GQL, but it's not easy to determine what makes a region empty.

I changed the design so that you add a new item whenever you want to specify settings for a new region. This works better with the backend validation since it requires the region settings to be properly filled out when you save the page. Design-wise I think the change is fine and might better at reducing clutter on the page.

Screenshots

Screenshot 2023-09-19 at 4 24 14 PM

Testing

  • Jest and Cypress tests

@cypress
Copy link

cypress bot commented Sep 19, 2023

Passing run #12912 ↗︎

0 587 7 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Clean up
Project: Spruce Commit: d3b7f250dc
Status: Passed Duration: 17:49 💡
Started: Sep 27, 2023 1:24 AM Ended: Sep 27, 2023 1:42 AM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

@minnakt minnakt marked this pull request as ready for review September 19, 2023 21:13
@minnakt minnakt requested a review from a team September 19, 2023 21:13
Comment on lines +224 to +227
size: {
type: "number" as "number",
title: "Size",
},
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 size is required if virtualName is empty. You could maybe use a bidirectional dependency

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 think the bidirectional dependencies don't work with the ! condition (?) so I gave this a try using anyOf with required but it didn't work... I also tried using the validate() function prop but I don't have access to rawErrors on the array template until v5 🙃

Sadly I think I may just have to leave it as it is, but I checked and made sure the backend does a validation error if both fields aren't defined


const useCapacityOptimization = {
type: "boolean" as "boolean",
title:
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Could probably make this more scannable by making the title "Capacity optimaztion" (maybe bolded?) and including the rest as a description

Comment on lines +213 to +216
userData: {
"ui:widget": "textarea",
"ui:elementWrapperCSS": textAreaCSS,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] If you want, you could probably situate the "Merge with existing user data" checkbox on the top-right of the texarea with some CSS like I did here

region: {
"ui:data-cy": "region-select",
"ui:allowDeselect": false,
"ui:enumDisabled": fleetRegions,
Copy link
Contributor

Choose a reason for hiding this comment

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

This works great 👌

GET_AWS_REGIONS
);
const { awsRegions } = awsData || {};
const fleetRegions = formData?.ec2FleetProviderSettings?.map((p) => p.region);
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] It could be useful to name this something like configuredRegions to indicate it's based on the distro data, not just the available options

Comment on lines 245 to 251
subnetId: {
"ui:placeholder": "e.g. subnet-xxxx",
},
subnetPrefix: {
"ui:description":
"Will look for subnets like <prefix>.subnet_1a, <prefix>.subnet_1b, etc.",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] You could indent these fields if you want to indicate they're associated with the checkmark above


// Change field values.
cy.selectLGOption("Region", "us-west-1");
cy.getInputByLabel("SSH Key Name").clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cy.getInputByLabel("SSH Key Name").clear();
cy.getInputByLabel("SSH Key Name").as("keyNameInput").clear();

// Change field values.
cy.selectLGOption("Region", "us-west-1");
cy.getInputByLabel("SSH Key Name").clear();
cy.getInputByLabel("SSH Key Name").type("my ssh key");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cy.getInputByLabel("SSH Key Name").type("my ssh key");
cy.get("@keyNameInput").type("my ssh key");

Comment on lines 133 to 134
cy.getInputByLabel("SSH Key Name").clear();
cy.getInputByLabel("SSH Key Name").type("mci");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
cy.getInputByLabel("SSH Key Name").clear();
cy.getInputByLabel("SSH Key Name").type("mci");
cy.get("@keyNameInput").clear();
cy.get("@keyNameInput").type("mci");

cy.dataCy("delete-item-button").click();
});
save();
cy.validateToast("success");
Copy link
Contributor

Choose a reason for hiding this comment

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

It'll be great to validate the toast copy in the second parameter

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 think I want to leave this one as-is since I would have to update multiple other test files for consistency (also I'm not sure that checking the copy is too important, it says the same thing every time)

Copy link
Contributor

@SupaJoon SupaJoon Sep 22, 2023

Choose a reason for hiding this comment

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

Sorry I didn't explain my reasoning fully. A benefit of being specific is to help with maintaining and debugging the test suite. If an issue occurs where the toast isn't dispatched, including the toast message allows to easily search the codebase for where the toast should have been dispatched. Even though the toast says the same thing every time for this test suite, we dispatch over 60 different success messages in Spruce. I hear you out about updating multiple files and the repetition in checking copy. I think ideally validateToast or it's usage should encapsulate the toast copy so we don't need to pass the parameter explicitly for every toast validation statement. It's okay to leave this as is for now but eventually I'll like to clean this up across our Cypress tests in a separate ticket: https://jira.mongodb.org/browse/EVG-20920

cy.dataCy("capacity-optimization").should("not.exist");

cy.selectLGOption("Fleet Instance Type", "Spot");
cy.dataCy("use-capacity-optimization").should("exist");
Copy link
Contributor

Choose a reason for hiding this comment

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

If the element is visible, it's more robust to assert should("be.visible") since it must exist to visible and also because the test is about showing and hiding.

// Correct section is displayed.
cy.dataCy("ec2-fleet-provider-settings").should("exist");
cy.dataCy("ec2-fleet-provider-settings")
.children()
Copy link
Contributor

Choose a reason for hiding this comment

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

This test will be more robust if it doesn't count the children HTML element and instead uses contains to assert existence. A package or code change could introduce a wrapper component that could always make this statement true and being explicit about what is contained will make the test more expressive so it's possible to understand what's contained under [data-cy="ec2-fleet-provider-settings" ] by reading the test code.

@minnakt minnakt merged commit 87b9d23 into evergreen-ci:main Sep 27, 2023
2 checks passed
@minnakt minnakt deleted the EVG-19947 branch September 27, 2023 01:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants