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

Health summary with clusters and databases #878

Merged
merged 6 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ defmodule Trento.Application.UseCases.SapSystems.HealthSummaryDto do
field :sapsystem_health, Ecto.Enum, values: Health.values()
field :database_health, Ecto.Enum, values: Health.values()
field :clusters_health, Ecto.Enum, values: Health.values()
field :cluster_id, Ecto.UUID
field :database_id, Ecto.UUID
field :hosts_health, Ecto.Enum, values: [:passing, :critical, :unknown]
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ defmodule Trento.SapSystems.HealthSummaryService do
sapsystem_health: health,
database_health: compute_database_health(database_instances),
clusters_health: compute_clusters_health(all_instances),
hosts_health: compute_hosts_health(all_instances)
hosts_health: compute_hosts_health(all_instances),
cluster_id: extract_cluster_id(database_instances),
database_id: extract_database_id(database_instances)
})
end

Expand All @@ -70,6 +72,18 @@ defmodule Trento.SapSystems.HealthSummaryService do
|> HealthService.compute_aggregated_health()
end

@spec extract_database_id([DatabaseInstanceReadModel.t()]) :: String.t()
defp extract_database_id([]), do: nil

defp extract_database_id([%DatabaseInstanceReadModel{sap_system_id: sap_system_id} | _]),
do: sap_system_id

@spec extract_cluster_id([DatabaseInstanceReadModel.t()]) :: String.t()
defp extract_cluster_id([]), do: nil

defp extract_cluster_id([%DatabaseInstanceReadModel{host: %{cluster_id: cluster_id}} | _]),
do: cluster_id

@spec clusters_from_instance(instance_list) :: [ClusterReadModel.t()]
defp clusters_from_instance(instances) do
instances
Expand Down
57 changes: 0 additions & 57 deletions test/support/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -433,61 +433,4 @@ defmodule Trento.Factory do
msg: Faker.StarWars.planet()
}
end

def sap_system_with_cluster_and_hosts do
%ClusterReadModel{id: cluster_id} =
insert(:cluster, type: ClusterType.hana_scale_up(), health: Health.passing())

%ClusterReadModel{id: another_cluster_id} =
insert(:cluster, type: ClusterType.hana_scale_up(), health: Health.warning())

%HostReadModel{id: host_1_id} = insert(:host, cluster_id: cluster_id, heartbeat: :unknown)

%HostReadModel{id: host_2_id} =
insert(:host, cluster_id: another_cluster_id, heartbeat: :passing)

database_sid = "HDD"

%SapSystemReadModel{
id: sap_system_id,
sid: sid
} = insert(:sap_system, health: Health.passing())

insert(
:database_instance_without_host,
sap_system_id: sap_system_id,
sid: database_sid,
host_id: host_1_id,
health: Health.warning()
)

insert(
:database_instance_without_host,
sap_system_id: sap_system_id,
sid: database_sid,
host_id: host_2_id,
health: Health.critical()
)

insert(
:application_instance_without_host,
sap_system_id: sap_system_id,
sid: sid,
host_id: host_1_id,
health: Health.passing()
)

insert(
:application_instance_without_host,
sap_system_id: sap_system_id,
sid: sid,
host_id: host_2_id,
health: Health.warning()
)

%{
sap_system_id: sap_system_id,
sid: sid
}
end
end
40 changes: 33 additions & 7 deletions test/trento/application/usecases/health_summary_service_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ defmodule Trento.HealthSummaryServiceTest do

alias Trento.Application.UseCases.SapSystems.HealthSummaryDto
alias Trento.SapSystems.HealthSummaryService
require Trento.Domain.Enums.Health, as: Health
require Trento.Domain.Enums.ClusterType, as: ClusterType

alias Trento.{
HostReadModel,
Expand Down Expand Up @@ -47,19 +49,43 @@ defmodule Trento.HealthSummaryServiceTest do
end

test "should determine health summary for a SAP System" do
%{
sap_system_id: sap_system_id,
%Trento.ClusterReadModel{id: cluster_id} =
insert(:cluster, type: ClusterType.hana_scale_up(), health: Health.passing())

%Trento.HostReadModel{id: host_1_id} =
Copy link
Contributor

Choose a reason for hiding this comment

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

We could rename host_1_id to host_id

insert(:host, cluster_id: cluster_id, heartbeat: :unknown)

%Trento.SapSystemReadModel{
id: sap_system_id,
sid: sid
} = sap_system_with_cluster_and_hosts()
} = insert(:sap_system, health: Health.critical())

insert(
:database_instance_without_host,
sap_system_id: sap_system_id,
sid: "HDD",
host_id: host_1_id,
health: Health.warning()
)

insert(
:application_instance_without_host,
sap_system_id: sap_system_id,
sid: sid,
host_id: host_1_id,
health: Health.critical()
)

assert [
%HealthSummaryDto{
id: ^sap_system_id,
sid: ^sid,
sapsystem_health: :passing,
database_health: :critical,
clusters_health: :warning,
hosts_health: :unknown
sapsystem_health: :critical,
database_health: :warning,
clusters_health: :passing,
hosts_health: :unknown,
database_id: ^sap_system_id,
Copy link
Contributor

Choose a reason for hiding this comment

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

now I bit confused it this is the database id or the sap system id hehe
Because if it is the same, we are sending it twice, in the id and in the database_id.

Now i'm thinking both of them might have the same id, the difference in the frontend is that we get one with /sap_systems/id and the other with /databases/id.
Could you double check this?

Copy link
Member 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 understood, they are not the same 👀

Copy link
Member Author

Choose a reason for hiding this comment

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

They can but can also be different

cluster_id: ^cluster_id
}
] = HealthSummaryService.get_health_summary()
end
Expand Down
40 changes: 33 additions & 7 deletions test/trento_web/controllers/health_overview_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,36 @@ defmodule TrentoWeb.HealthOverviewControllerTest do
use TrentoWeb.ConnCase, async: true

import Trento.Factory
require Trento.Domain.Enums.Health, as: Health
require Trento.Domain.Enums.ClusterType, as: ClusterType

test "should return the expected overview", %{conn: conn} do
%{
sap_system_id: sap_system_id,
%Trento.ClusterReadModel{id: cluster_id} =
insert(:cluster, type: ClusterType.hana_scale_up(), health: Health.passing())

%Trento.HostReadModel{id: host_1_id} =
insert(:host, cluster_id: cluster_id, heartbeat: :unknown)

%Trento.SapSystemReadModel{
id: sap_system_id,
sid: sid
} = sap_system_with_cluster_and_hosts()
} = insert(:sap_system, health: Health.critical())

insert(
:database_instance_without_host,
sap_system_id: sap_system_id,
sid: "HDD",
host_id: host_1_id,
health: Health.warning()
)

insert(
:application_instance_without_host,
sap_system_id: sap_system_id,
sid: sid,
host_id: host_1_id,
health: Health.critical()
)

conn = get(conn, Routes.health_overview_path(conn, :overview))

Expand All @@ -17,10 +41,12 @@ defmodule TrentoWeb.HealthOverviewControllerTest do
%{
"id" => "#{sap_system_id}",
"sid" => "#{sid}",
"sapsystem_health" => "passing",
"database_health" => "critical",
"clusters_health" => "warning",
"hosts_health" => "unknown"
"sapsystem_health" => "critical",
"database_health" => "warning",
"clusters_health" => "passing",
"hosts_health" => "unknown",
"database_id" => "#{sap_system_id}",
"cluster_id" => "#{cluster_id}"
}
] == json_response(conn, 200)
end
Expand Down