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

feat(global-writes): add unsharded state COMPASS-8276 #6289

Merged
merged 43 commits into from
Sep 27, 2024

Conversation

mabaasit
Copy link
Contributor

@mabaasit mabaasit commented Sep 26, 2024

This PR includes:

  1. Warning icon on Global Writes tab (along with a tooltip);
  2. Unsharded state which allows users to create a shard key for a collection;
  3. Initial sharding state, which is shown once server starts to create a shard key
Preview

Tab Warning
image

Unsharded State
image

Sharding State (more work in next ticket)
image

Description

Checklist

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@github-actions github-actions bot added the feat label Sep 26, 2024
Comment on lines 69 to 71
createShardkey: {
isLoading: boolean;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was not part of the tech doc, but while working on this, I realzied we need to disable the create-shard-button and added this. as an alternative, we can also await on the dispatch action on the react side and while its waiting we disable the button.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you clarify why is this not just part of sharding status? I'm maybe missing the purpose, but this seems like just part of the status transition for creation flow, so why are we moving this state into its own field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a state between UNSHARDED and SHARDING, time duration for which user clicks the create shard key and server acknowledges the change - keeps the button disabled, and for error shows the toast.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So this loading state is mutually exclusive with all the other states, is that correct? If yes, in that case we should just add it as another state in list of available state transitions for the component, using multiple states to declare mutually exclusive, state-machine-like, states of the application can lead to potentially weird cases and hard to reason about logic as it basically allows application to be in multiple states at once.

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 that's correct. It does make sense to add these to the state as well, its just that I think the list will grow a little and in such case, i find it a bit hard to maintain the transitions.

But I will try to do that. Thanks for the suggestion.

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 in 23c1361

});
return;
}
// TODO (COMPASS-8277): Now fetch the sharding key and possible process error.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here in the follow up tickets, we want to fetch the shard keys and also the agent process errors and based on that information, transition to other states. Currently this leaves user in a loading state, but i think that's fine with the current state of the project.

Comment on lines +185 to +193
openToast('global-writes-fetch-shard-info-error', {
title: `Failed to fetch sharding information: ${
(error as Error).message
}`,
dismissible: true,
timeout: 5000,
variant: 'important',
});
}
Copy link
Contributor Author

@mabaasit mabaasit Sep 26, 2024

Choose a reason for hiding this comment

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

we also want to have another state like ERROR or something, where user does not see loading and can see the error and possibly an action to refetch.

import type { AtlasService } from '@mongodb-js/atlas-service/provider';
import type { CreateShardKeyData } from '../store/reducer';

type ZoneMapping = unknown;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

leaving it unknow for now, will implement it when needed

@mabaasit mabaasit added the no release notes Fix or feature not for release notes label Sep 26, 2024
case ShardingStatuses.NOT_READY:
return (
<div className={centeredContent}>
<SpinLoaderWithLabel progressText="Loading ..." />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<SpinLoaderWithLabel progressText="Loading ..." />
<SpinLoaderWithLabel progressText="Loading " />

return (
<div className={containerStyles}>
<Banner variant={BannerVariant.Info}>
<strong>Sharding your collection ...</strong>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<strong>Sharding your collection ...</strong>
<strong>Sharding your collection </strong>

(or I guess you can … like the ' below – but just fyi, ' is just a literal ' that you don't really need to escape here anyway. And even more pedantically, you'd want to use ‘ ’ instead of ' 😄)

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 in 3b384fc

'AtlasFetchError',
'Error creating cluster shard key',
{
error: error as Error,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we can log literal Error objects?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed to log the message only

>;

enum GlobalWritesActionTypes {
SetIsManagedNamespace = 'global-writes/SetIsManagedNamespace',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Avoid setter actions. What is the actual event that happens in the app here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in a0eb2be.

this action is dispatched after we call the api to check if the namespace is managed or not, in fetchClusterShardingData action.

Comment on lines 38 to 53
function getStateViewBasedOnShardingStatus(shardingStatus: ShardingStatus) {
switch (shardingStatus) {
case ShardingStatuses.NOT_READY:
return (
<div className={centeredContent}>
<SpinLoaderWithLabel progressText="Loading …" />
</div>
);
case ShardingStatuses.UNSHARDED:
return <UnshardedState />;
case ShardingStatuses.SHARDING:
return <ShardingState />;
default:
return null;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: this is just a React component that is written like a plain function, I'd suggest we don't do that because you loose some React functionality that might come in handy like memoing the component or the ability to safely use hooks inside this 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.

fixed in 5f03a49

Comment on lines 69 to 71
createShardkey: {
isLoading: boolean;
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you clarify why is this not just part of sharding status? I'm maybe missing the purpose, but this seems like just part of the status transition for creation flow, so why are we moving this state into its own field?

@mabaasit mabaasit marked this pull request as ready for review September 26, 2024 13:21
@paula-stacho
Copy link
Contributor

paula-stacho commented Sep 27, 2024

Perhaps we could add some left padding, so that the LG hover visual isn't cut off:
Screenshot 2024-09-27 at 13 41 04
I'm thinking either 16px on the checkboxes (so that they are aligned with the text, skipping the toggle icon), or 4px on the form and description. What do you think?

@mabaasit
Copy link
Contributor Author

mabaasit commented Sep 27, 2024

Perhaps we could add some left padding, so that the LG hover visual isn't cut off: Screenshot 2024-09-27 at 13 41 04 I'm thinking either 16px on the checkboxes (so that they are aligned with the text, skipping the toggle icon), or 4px on the form and description. What do you think?

I added some spacing to avoid this in eca4068 (but only for the radio options and aligned checkbox accordingly)

Copy link
Contributor

@paula-stacho paula-stacho left a comment

Choose a reason for hiding this comment

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

Looks good!

@mabaasit mabaasit merged commit b9957ff into main Sep 27, 2024
27 checks passed
@mabaasit mabaasit deleted the COMPASS-8276-no-shard-key branch September 27, 2024 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat no release notes Fix or feature not for release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants