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

Fix ENSA version calculation #2222

Merged
merged 6 commits into from
Jan 30, 2024
Merged

Fix ENSA version calculation #2222

merged 6 commits into from
Jan 30, 2024

Conversation

jamie-suse
Copy link
Contributor

@jamie-suse jamie-suse commented Jan 25, 2024

Description

This PR is a correction to the aggregated ENSA version calculation made in #2177

The way the relevant SAP systems and resulting ENSA version are determined is by:

  1. Record all hosts that have the cluster's ID in a list
  2. From there, get all application instances that are hosts from the hosts list and have an SID managed from the cluster (found in the additional_sids field for the cluster)
  3. With the list of relevant application instances, their corresponding SAP system IDs can be found, and recorded as a list of distinct SAP system IDs.
  4. Lastly, with the relevant SAP systems found, their individual ENSA versions can be recorded, and the aggregated ENSA version can be calculated as previously.

How was this tested?

Updated unit tests to validate the new logic

@jamie-suse jamie-suse added the elixir Pull requests that update Elixir code label Jan 25, 2024
@jamie-suse jamie-suse marked this pull request as ready for review January 26, 2024 11:31
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.

Hey @jamie-suse
I think there is room for improvement in the code, beyond the logic now looks correct.

Anyway, out of that, and not asking to do changes about this, just food for thoughts.
I think that personally, I would design the code differently. I would have a function named getSapSystemsByCluster(cluster_id) or similar, which returns you all the sap systems belonging to this cluster, returning the sap system read model, and from there, you can get the needed field, in this case the ensa version.
The current code looks so tailored to the current need that those functions are not really usable anywhere else.

@arbulu89 arbulu89 added the bug Something isn't working label Jan 29, 2024
@nelsonkopliku
Copy link
Member

nelsonkopliku commented Jan 29, 2024

I would design the code differently. I would have a function named getSapSystemsByCluster(cluster_id) or similar...

@arbulu89 this is a good point which might result in the opportunity of being able to expose the information about which ensa versions are there in this ascs ers cluster directly from the backend, so we do not have the same logic applied in the frontend.

I would track this as debt though, because this logic might be applied at read time by composing query results or it might be projected either in cluster read model or a dedicated read model if we leverage events.

@jamie-suse
Copy link
Contributor Author

Okay I will make a ticket for tracking the refactor 👍

@jamie-suse jamie-suse requested a review from arbulu89 January 29, 2024 13:59
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.

Now the logic looks good 🙂

@@ -225,4 +230,23 @@ defmodule Trento.Clusters do
end

defp maybe_request_checks_execution(error), do: error

@spec get_ensa_version([String.t()]) :: EnsaVersion.t()
defp get_ensa_version(sap_system_ids) do
Copy link
Contributor

Choose a reason for hiding this comment

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

The name is a bit misleading for me, but I don't have any better suggestion, so...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I know we don't really have terminology for this. The best I can think of is get_aggregated_ensa_version(), what do you think?

[%Trento.Clusters.ValueObjects.AscsErsClusterSapSystem{sid: sid}] = sap_systems
test "should start a checks execution on demand for ascs_ers clusters with ENSA 1 version" do
%SapSystemReadModel{id: sap_system_id_1, sid: sid_1} =
insert(:sap_system, ensa_version: Trento.SapSystems.Enums.EnsaVersion.ensa1())
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use the aliased short version here EnsaVersion.ensa1() (and in many more places)

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 because these tests use both Trento.SapSystems.Enums.EnsaVersion and Trento.Clusters.Enums.EnsaVersion. I'm fine with renaming the cluster's ENSA version something else like ClusterEnsaVersion or AggregatedEnsaVersion, what do you think?

@jamie-suse jamie-suse requested a review from arbulu89 January 29, 2024 15:47
@jamie-suse jamie-suse merged commit 647c73f into main Jan 30, 2024
23 checks passed
@jamie-suse jamie-suse deleted the ensa-version-fix branch January 30, 2024 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working elixir Pull requests that update Elixir code
Development

Successfully merging this pull request may close these issues.

3 participants