Skip to content

Commit

Permalink
Better dashboard reactivness, fix certain cases where an empty host c…
Browse files Browse the repository at this point in the history
…ould cause a match error
  • Loading branch information
fabriziosestito committed Apr 28, 2022
1 parent 2b9ab74 commit 7911cf2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
16 changes: 10 additions & 6 deletions assets/js/state/sagas/index.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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 } }) {
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

0 comments on commit 7911cf2

Please sign in to comment.