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

Identify clustered sap instances #3397

Merged
merged 8 commits into from
Mar 25, 2025
Merged

Conversation

arbulu89
Copy link
Contributor

@arbulu89 arbulu89 commented Mar 20, 2025

Description

Identify clustered SAP instances as right now, all SAP application and database instances running in a cluster host are identified as clustered instances, which is not always the case.

With this, we can be precise in the ApplicationInstanceMoved event, and only do it when the instance is clustered.

All the new logic is almost implemented in the policies code. Everything else is just side-effect work.

Now that we have a more detailed SAP instances data, I have removed the sid and additional_sids entries from all the code, except the frontend.

In the next PR I want to deprecate the sid and additional_sids elements from the API (keep them for backward compatibility) and send the new SAP instances to the frontend. This way, we can display properly if the instance is clustered as well.

How was this tested?

UT, regression test, manual testing...

@arbulu89 arbulu89 added the env Create an ephimeral environment for the pr branch label Mar 20, 2025
@@ -669,7 +715,7 @@ defmodule Trento.Discovery.Policies.ClusterPolicy do
}) do
Enum.concat(
primitives,
Enum.flat_map(clones, &Map.get(&1, :primitives, [])) ++
Enum.flat_map(clones, &(&1 |> Map.get(:primitive, []) |> List.wrap())) ++
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 a small bug we had. We didn't notice as we were not using cloned resources coming from this function

@arbulu89 arbulu89 added the regression Add this label to force the PR to run upcasting regression tests label Mar 20, 2025
cluster
|> Map.put(:sid, SapInstance.get_hana_instance_sid(sap_instances))
|> Map.put(:additional_sids, SapInstance.get_sap_instance_sids(sap_instances))
|> Map.delete(:sap_instances)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the sap_instances by now.
I will work on the frontend part in a next implementation and see how to give the information to the frontend

@arbulu89 arbulu89 force-pushed the identify-clustered-sap-instances branch from af24c5e to 30ff192 Compare March 24, 2025 08:39
@arbulu89 arbulu89 force-pushed the identify-clustered-sap-instances branch from 30ff192 to dba7f30 Compare March 24, 2025 14:06
@arbulu89 arbulu89 marked this pull request as ready for review March 24, 2025 14:56
Copy link
Contributor

@abravosuse abravosuse left a comment

Choose a reason for hiding this comment

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

Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

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

hey @arbulu89 the code looks good. These kind of changes require possibly a lot of changes indeed 😄 and I trust the testing that has been made.

Question about the modified events: why are we changing legacy events as well? And did not changes to events require upcasting? 🤔

@arbulu89
Copy link
Contributor Author

arbulu89 commented Mar 25, 2025

Question about the modified events: why are we changing legacy events as well? And did not changes to events require upcasting?

Indeed. Changing legacy events was not needed. I thought that the params would be superseded, but they are not, we simply redirect to the new module. Good catch.

About the upcasting, as the embeds_many defaults to an empty list, everything works without it. It is true that we lose some partial data though. I will implement the upcasting just for completeness, but the result would be the same due eventual consistency.

@arbulu89
Copy link
Contributor Author

arbulu89 commented Mar 25, 2025

Hey @nelsonkopliku ,
About the upcasting again. I have done some coding and adding "advanced" upcasting code looks unnecessary again. At the end, we just simply update some partial incomplete data in the aggregate, that we don't even use there (it is there only for projection purposes). And this data will be overriden 100% cases when the next payload arrives. So it is not used for anything.

I think that I will avoid adding not needed extra complexity/code and simply bump the version of the event, at least to be informative (because if there is not any upcasting function, it doesn't really do anything).
What do you think?

PD: I'm going to even remove the version bump. This forces me to have the upcast function implemented, and it doesn't make much sense as it wouldn't do any change at all in the coming parameters, returning the same object

@nelsonkopliku
Copy link
Member

Sounds reasonable @arbulu89, thanks for looking into it.

@arbulu89 arbulu89 requested a review from nelsonkopliku March 25, 2025 13:55
Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

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

LGTM

@arbulu89 arbulu89 force-pushed the identify-clustered-sap-instances branch from 1828cf5 to 3b131a4 Compare March 25, 2025 14:03
Copy link
Contributor

@gagandeepb gagandeepb left a comment

Choose a reason for hiding this comment

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

Just one comment/side-note.

Comment on lines +173 to +176
case Repo.one(query) do
nil -> []
sap_instances -> sap_instances
end
Copy link
Contributor

Choose a reason for hiding this comment

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

This will raise an exception if there's more than one result, IIRC.

Copy link
Contributor Author

@arbulu89 arbulu89 Mar 25, 2025

Choose a reason for hiding this comment

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

This is the host_id, UUID and primary key in the database. It is impossible by database definition as the host can only have one cluster.
But thank you for pointing it out, you never know until you double-check hehe

@arbulu89 arbulu89 merged commit bef97ba into main Mar 25, 2025
39 checks passed
@arbulu89 arbulu89 deleted the identify-clustered-sap-instances branch March 25, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
env Create an ephimeral environment for the pr branch regression Add this label to force the PR to run upcasting regression tests
Development

Successfully merging this pull request may close these issues.

None yet

4 participants