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

Send and receive explicit restoration events #1673

Merged
merged 19 commits into from
Aug 1, 2023
Merged

Conversation

jamie-suse
Copy link
Contributor

@jamie-suse jamie-suse commented Jul 26, 2023

Description

Previously, when a restoration occurred on the backend, *_registered events were being sent. Now we need to explicitly send events indicating that a restoration (*_restored event) has occurred.

sap_system_restored and database_restored events also send database_instances (and additionally application_instances, in the case of sap_system_restored) data, which is required to update the UI.

Fixes TRNT-2355

How was this tested?

Updated projector tests to ensure they send the new events.

Added tests for new Sagas and new SAP systems reducer functions.

@jamie-suse jamie-suse added the elixir Pull requests that update Elixir code label Jul 26, 2023
@jamie-suse jamie-suse marked this pull request as draft July 26, 2023 14:07
@jamie-suse jamie-suse force-pushed the restoration-bug-projectors branch 2 times, most recently from fb8e403 to c50ee6b Compare July 27, 2023 14:06
@jamie-suse jamie-suse changed the title Send cluster_restored & sap_system_restored websocket events Send and receive explicit restoration events Jul 27, 2023
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.

You still need to preload the database_instances in the database restoration and maybe change the view

@@ -341,11 +341,11 @@ defmodule Trento.SapSystemProjector do
sap_system =
SapSystemReadModel
|> Repo.get!(sap_system_id)
|> Repo.preload([:tags])
|> Repo.preload([:tags, :database_instances, :application_instances])
Copy link
Contributor

Choose a reason for hiding this comment

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

Something I noticed here as that we could even do this:

@impl true
  def after_update(
        %SapSystemRestored{},
        _,
        %{sap_system: %SapSystemReadModel{} = sap_system}
      ) do
    enriched_sap_system =
      Repo.preload(sap_system, [
        :application_instances,
        :database_instances,
        :tags
      ])

    ....

I mean, we don't need to query, as the read model already comes in the 3rd parameter of the after_update.
Not a big deal though.

@@ -306,7 +306,7 @@ defmodule Trento.DatabaseProjector do

TrentoWeb.Endpoint.broadcast(
@databases_topic,
"database_registered",
"database_restored",
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you need to preload the database_instances

@jamie-suse jamie-suse marked this pull request as ready for review July 27, 2023 16:42
@jamie-suse jamie-suse force-pushed the restoration-bug-projectors branch from 160f81b to 0d5d2e2 Compare July 31, 2023 12:17
@jamie-suse jamie-suse added the javascript Pull requests that update Javascript code label Jul 31, 2023
@@ -36,7 +36,7 @@ context('Databases Overview', () => {
cy.contains('div', hdqDatabase.instances[1].name).should('exist');
});

it('should show the ACTIVE pill in the right host', () => {
it.skip('should show the ACTIVE pill in the right host', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this test is for bug TRNT-2357.
This skip needs to be removed is the PR fixing that bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

mamma mia...
How we have ended like this now? 😭

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.

Many comments...
The PR is pretty huge, so I don't know if I missed something..

@@ -102,6 +102,7 @@ export const clustersListSlice = createSlice({
});

export const CLUSTER_DEREGISTERED = 'CLUSTER_DEREGISTERED';
export const CLUSTER_RESTORED = 'CLUSTER_RESTORED';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why a new line after this?

@@ -30,6 +30,12 @@ export const databasesListSlice = createSlice({
appendDatabaseInstance: (state, action) => {
state.databaseInstances = [...state.databaseInstances, action.payload];
},
upsertDatabaseInstances: (state, action) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really like this now.
I think that the filterByInstances should be changed to be upsertInstances and include the concat there.
In fact, I think we should remove the upsertDatabaseInstance and only leave upsertDatabaseInstances, because the we have the risk for appending already existing instances with the previous function (I would even leave appendDatabaseInstances as it is easier to understand)
So I would replace the plural usage everywhere

yield put(appendCluster(payload));
yield put(
notify({
text: `Cluster, ${payload.name}, has been restored.`,
Copy link
Contributor

Choose a reason for hiding this comment

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

@abravosuse Do we want to use this notifications with the restoration wording, or should we still use registered?

Copy link
Contributor

@rtorrero rtorrero Aug 1, 2023

Choose a reason for hiding this comment

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

I'd remove the ,s

yield debounce(
debounceDuration,
HOST_DEREGISTERED,
loadSapSystemsHealthSummary
);
yield debounce(debounceDuration, HOST_RESTORED, loadSapSystemsHealthSummary);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this formatted?
Anyway, the order of things looks unsorted.
Could we maybe have all deregistered first and all restored afterwards?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the formatter keeps one-line-ing it 🤦‍♂️.

Moved all the restored events below the deregistered events 👍.

I notice there is not a listener here for DATABASE_DEREGISTERED, should this be added in?

const action = upsertDatabaseInstances(newInstances);

const expectedState = {
databaseInstances: initialState.databaseInstances
Copy link
Contributor

Choose a reason for hiding this comment

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

Really complex...
Cannot we have a fixed expected thing so everyone can understand in a first glance what's going on?

|> Repo.preload([
:tags,
:database_instances,
database_instances: [host: :tags],
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this host and tags preloaded instances?
Why do we even need to have them twice?

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 just included them otherwise the JSON serialiser was complaining.

Why do we even need to have them twice?

One is the :tags for the DatabaseReadModel, the other is :tags for HostReadModel.

I can see how to remove the HostReadModel tags if it's not desired.

Copy link
Contributor

Choose a reason for hiding this comment

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

So we need to fix the view them, not add database_instances twice loading hosts that we don't need, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you don't want to include the hosts data from database_instances?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason why we need it?
We don't use it in the frontend as far as I know

@@ -36,7 +36,7 @@ context('Databases Overview', () => {
cy.contains('div', hdqDatabase.instances[1].name).should('exist');
});

it('should show the ACTIVE pill in the right host', () => {
it.skip('should show the ACTIVE pill in the right host', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

mamma mia...
How we have ended like this now? 😭

@@ -40,7 +40,6 @@ defmodule TrentoWeb.V1.SapSystemView do
database
|> Map.from_struct()
|> Map.delete(:__meta__)
|> Map.delete(:database_instances)
Copy link
Contributor

@arbulu89 arbulu89 Aug 1, 2023

Choose a reason for hiding this comment

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

By the way, here we might want to use add_system_replication_status_to_secondary_instance so we put the pills properly.
We need to see how it behaves

@jamie-suse jamie-suse force-pushed the restoration-bug-projectors branch from 475fe2f to 37b6681 Compare August 1, 2023 12:40
@jamie-suse jamie-suse requested a review from arbulu89 August 1, 2023 12:48
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.

Looks good!
Just a couple of last comments, but you don't need a new review.
I hope you tested how it works manually as well 😉

@@ -70,6 +71,17 @@ export function* databaseDeregistered({ payload }) {
);
}

export function* databaseRestored({ payload }) {
yield put(appendDatabase(payload));
yield put(upsertDatabaseInstances(payload.database_instances));
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we need yield put(upsertDatabaseInstancesToSapSystem([payload])); here?

@@ -302,11 +302,11 @@ defmodule Trento.DatabaseProjector do
database =
DatabaseReadModel
|> Repo.get!(sap_system_id)
|> Repo.preload([:tags])
|> Repo.preload([:tags, :database_instances, [database_instances: :host]])
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove this [database_instances: :host]?

Copy link
Contributor

@rtorrero rtorrero left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @jamie-suse

@arbulu89 arbulu89 merged commit be3813c into main Aug 1, 2023
@arbulu89 arbulu89 deleted the restoration-bug-projectors branch August 1, 2023 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
elixir Pull requests that update Elixir code javascript Pull requests that update Javascript code
Development

Successfully merging this pull request may close these issues.

3 participants