Skip to content

Commit

Permalink
Health summary with clusters and databases (#878)
Browse files Browse the repository at this point in the history
* WIP on HealthSummaryDTO

* Add test to the health summary service

Co-Authored-By: Eugen Maksymenko <eugen.maksymenko@suse.com>

* Formatting code

* Fix typespec in health summary service

* Health Summary DTO has database and cluster id as Ecto.UUID

* Refactored field extraction in Health Summary Service/DTO

Co-authored-by: Eugen Maksymenko <eugen.maksymenko@suse.com>
  • Loading branch information
CDimonaco and EMaksy authored Oct 7, 2022
1 parent 3e6bb49 commit b67b5b4
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 72 deletions.
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} =
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,
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

0 comments on commit b67b5b4

Please sign in to comment.