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

Make frontend listen for events when instances' presence changes #1779

Merged
merged 3 commits into from
Sep 4, 2023

Conversation

jamie-suse
Copy link
Contributor

Description

This PR adds the ability for the frontend to listen for application_instance_absent_at_changed & database_instance_absent_at_changed websocket events when instances' presence changes.

With this change, the frontend's state will update when an instance becomes absent or present.

How was this tested?

Added tests in Redux reducers and Sagas to test this behaviour.

@jamie-suse jamie-suse added enhancement New feature or request javascript Pull requests that update Javascript code labels Aug 31, 2023
@@ -79,6 +81,19 @@ function* applicationInstanceHealthChanged({ payload }) {
yield put(updateApplicationInstanceHealth(payload));
}

export function* applicationInstanceAbsentAtChanged({ payload }) {
yield put(updateApplicationInstanceAbsentAt(payload));
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 may be a bit technical, but payload will include the field sid, that we don't strictly need to pass to updateApplicationInstanceAbsentAt(). Thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't really matter, it is fine this way

@@ -111,6 +113,19 @@ function* databaseInstanceSystemReplicationChanged({ payload }) {
yield put(updateSAPSystemDatabaseInstanceSystemReplication(payload));
}

export function* databaseInstanceAbsentAtChanged({ payload }) {
yield put(updateDatabaseInstanceAbsentAt(payload));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

const { sid, absent_at } = payload;
yield put(
notify({
text: `The application instance ${sid} is now ${
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thoughts on this message?

const { sid, absent_at } = payload;
yield put(
notify({
text: `The database instance ${sid} is now ${
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I would put:
The database instance ${instance_number} from ${sid} is absent
and
The database instance ${instance_number} from ${sid} is present again

@jamie-suse jamie-suse marked this pull request as ready for review September 4, 2023 06:05
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

We need to add new reducer function to update the database instances in the sap system reducer.
Besides that, some tiny details

assets/js/state/sagas/databases.js Show resolved Hide resolved
const { sid, absent_at } = payload;
yield put(
notify({
text: `The database instance ${sid} is now ${
Copy link
Contributor

Choose a reason for hiding this comment

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

I would put:
The database instance ${instance_number} from ${sid} is absent
and
The database instance ${instance_number} from ${sid} is present again

state.databaseInstances = updateInstance(
state.databaseInstances,
instance,
{ absent_at }
Copy link
Contributor

Choose a reason for hiding this comment

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

I would put {absent_at: instance.absent_at} to have the same style like the other reducer functions

Copy link
Member

Choose a reason for hiding this comment

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

done

@@ -41,6 +43,53 @@ describe('SAP Systems sagas', () => {
console.error.mockRestore();
});

it('should update the absent_at field when the database instance is marked absent', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this now in the top of the file?
I would put it at the end as it is at the end in the prod code as well

Copy link
Member

Choose a reason for hiding this comment

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

done

it('should update the absent_at field when the database instance is marked absent', async () => {
const { sap_system_id, instance_number, host_id, sid } =
databaseInstanceFactory.build();
const absent_at = Date.now();
Copy link
Contributor

Choose a reason for hiding this comment

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

I bit strange this absent_at not going in the factory itself, isn't it?

Copy link
Member

Choose a reason for hiding this comment

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

done

@@ -79,6 +81,19 @@ function* applicationInstanceHealthChanged({ payload }) {
yield put(updateApplicationInstanceHealth(payload));
}

export function* applicationInstanceAbsentAtChanged({ payload }) {
yield put(updateApplicationInstanceAbsentAt(payload));
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't really matter, it is fine this way

@CDimonaco CDimonaco requested a review from arbulu89 September 4, 2023 10:36
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

Thank you @CDimonaco
Green light.
Just added some few tiny cosmetic comments, but you don't need a new review in any case

@@ -149,6 +149,15 @@ export const sapSystemsListSlice = createSlice({
}
);
},
updateApplicationInstanceAbsentAt: (state, { payload: instance }) => {
const { absent_at } = instance;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we have this like the database reducer?

Copy link
Member

Choose a reason for hiding this comment

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

done

setApplicationInstanceDeregistering,
unsetApplicationInstanceDeregistering,
setDatabaseInstanceDeregisteringToSAPSystem,
unsetDatabaseInstanceDeregisteringToSAPSystem,
updateDatabaseInstanceAbsentToSAPSystem,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would put this together with the first one, in line 247, as they are related

Copy link
Member

Choose a reason for hiding this comment

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

done

@@ -183,6 +192,15 @@ export const sapSystemsListSlice = createSlice({
{ deregistering: false }
);
},
updateDatabaseInstanceAbsentToSAPSystem: (state, { payload: instance }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What about putting this right after the other? as they are related and to avoid scrolling

Copy link
Member

Choose a reason for hiding this comment

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

done

@CDimonaco CDimonaco force-pushed the listen-marked-absent branch from b5c68ec to c9c0d8a Compare September 4, 2023 10:54
@CDimonaco CDimonaco force-pushed the listen-marked-absent branch from c9c0d8a to e47b0ef Compare September 4, 2023 11:37
@CDimonaco CDimonaco merged commit b6e8188 into main Sep 4, 2023
@CDimonaco CDimonaco deleted the listen-marked-absent branch September 4, 2023 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request javascript Pull requests that update Javascript code
Development

Successfully merging this pull request may close these issues.

3 participants