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 dashboard #462

Merged
merged 1 commit into from
Apr 28, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions assets/js/state/sagas/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { get, post, put as PUT } from 'axios';
import { put, all, call, takeEvery, select } from 'redux-saga/effects';
import {
put,
all,
call,
takeEvery,
takeLatest,
select,
} from 'redux-saga/effects';
import { urlEncode, keysToCamel } from '@lib/serialization';

import {
Expand Down Expand Up @@ -511,11 +518,15 @@ function* watchCatalogUpdate() {
}

function* refreshHealthSummaryOnComnponentsHealthChange() {
yield takeEvery('HEARTBEAT_FAILED', loadSapSystemsHealthSummary);
yield takeEvery('HEARTBEAT_SUCCEDED', loadSapSystemsHealthSummary);
yield takeEvery('DATABASE_HEALTH_CHANGED', loadSapSystemsHealthSummary);
yield takeEvery('SAP_SYSTEM_HEALTH_CHANGED', loadSapSystemsHealthSummary);
yield takeEvery('CLUSTER_HEALTH_CHANGED', loadSapSystemsHealthSummary);
yield takeLatest('HOST_REGISTERED', loadSapSystemsHealthSummary);
yield takeLatest('CLUSTER_REGISTERED', loadSapSystemsHealthSummary);
yield takeLatest('DATABASE_REGISTERED', loadSapSystemsHealthSummary);
yield takeLatest('SAP_SYSTEM_REGISTERED', loadSapSystemsHealthSummary);
yield takeLatest('HEARTBEAT_FAILED', loadSapSystemsHealthSummary);
yield takeLatest('HEARTBEAT_SUCCEDED', loadSapSystemsHealthSummary);
yield takeLatest('DATABASE_HEALTH_CHANGED', loadSapSystemsHealthSummary);
yield takeLatest('SAP_SYSTEM_HEALTH_CHANGED', loadSapSystemsHealthSummary);
yield takeLatest('CLUSTER_HEALTH_CHANGED', loadSapSystemsHealthSummary);
}

function* loadClusterConnectionSettings({ payload: { cluster } }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Trento.SapSystems.HealthSummaryService do

import Ecto.Query

@type instancesList :: [DatabaseInstanceReadModel.t() | ApplicationInstanceReadModel.t()]
@type instance_list :: [DatabaseInstanceReadModel.t() | ApplicationInstanceReadModel.t()]

@spec get_health_summary :: [HealthSummaryDto.t()]
def get_health_summary do
Expand Down Expand Up @@ -58,7 +58,7 @@ defmodule Trento.SapSystems.HealthSummaryService do
|> HealthService.compute_aggregated_health()
end

@spec compute_clusters_health(instancesList) ::
@spec compute_clusters_health(instance_list) ::
Health.t()
defp compute_clusters_health(instances) do
instances
Expand All @@ -69,9 +69,10 @@ defmodule Trento.SapSystems.HealthSummaryService do
|> HealthService.compute_aggregated_health()
end

@spec clusters_from_instance(instancesList) :: [ClusterReadModel.t()]
@spec clusters_from_instance(instance_list) :: [ClusterReadModel.t()]
defp clusters_from_instance(instances) do
instances
|> Enum.filter(fn %{host: host} -> host end)
|> Enum.map(fn %{host: %{cluster_id: cluster_id}} -> cluster_id end)
|> Enum.uniq()
|> Enum.map(fn cluster_id -> Repo.get!(ClusterReadModel, cluster_id) end)
Expand All @@ -82,7 +83,7 @@ defmodule Trento.SapSystems.HealthSummaryService do
Enum.map(clusters, fn %ClusterReadModel{health: health} -> health end)
end

@spec reject_unclustered_instances(instancesList) :: instancesList
@spec reject_unclustered_instances(instance_list) :: instance_list
defp reject_unclustered_instances(instances) do
Enum.reject(instances, fn
%{host: %{cluster_id: nil}} -> true
Expand All @@ -98,10 +99,12 @@ defmodule Trento.SapSystems.HealthSummaryService do
end)
end

@spec compute_hosts_health(instancesList) :: Health.t()
@spec compute_hosts_health(instance_list) :: Health.t()
defp compute_hosts_health(instances) do
instances
|> Enum.filter(fn %{host: host} -> host end)
|> Enum.map(fn %{host: %{heartbeat: heartbeat}} -> heartbeat end)
|> Enum.filter(& &1)
|> HealthService.compute_aggregated_health()
end
end