From 7911cf2a48db79ae4cbeccf32095fa779ee29831 Mon Sep 17 00:00:00 2001 From: Fabrizio Sestito Date: Thu, 28 Apr 2022 08:12:07 +0200 Subject: [PATCH] Better dashboard reactivness, fix certain cases where an empty host could cause a match error --- assets/js/state/sagas/index.js | 16 ++++++++++------ .../sap_systems/health_summary_service.ex | 13 ++++++++----- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/assets/js/state/sagas/index.js b/assets/js/state/sagas/index.js index 09ef30d33d..3c70076c06 100644 --- a/assets/js/state/sagas/index.js +++ b/assets/js/state/sagas/index.js @@ -1,5 +1,5 @@ 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 { @@ -511,11 +511,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 } }) { diff --git a/lib/trento/application/usecases/sap_systems/health_summary_service.ex b/lib/trento/application/usecases/sap_systems/health_summary_service.ex index 5e8d90c361..3b1bfe2d58 100644 --- a/lib/trento/application/usecases/sap_systems/health_summary_service.ex +++ b/lib/trento/application/usecases/sap_systems/health_summary_service.ex @@ -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 @@ -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 @@ -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) @@ -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 @@ -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