From 33ba4913e53905b099458e3567c77a73ecbff18a Mon Sep 17 00:00:00 2001 From: Gerard Soldevila Date: Tue, 14 Nov 2023 09:51:31 +0100 Subject: [PATCH] [`taskManager` plugin status] Do not emit empty status to status Observables (#171012) ## Summary Improvement over https://github.com/elastic/kibana/pull/169447, see [related comment](https://github.com/elastic/kibana/pull/171012). --- .../from_the_server/core_context_providers.ts | 2 +- .../task_manager/server/lib/calculate_health_status.test.ts | 2 +- .../task_manager/server/lib/calculate_health_status.ts | 2 +- .../server/monitoring/monitoring_stats_stream.ts | 1 + x-pack/plugins/task_manager/server/routes/health.ts | 5 +++-- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/test/analytics/tests/instrumented_events/from_the_server/core_context_providers.ts b/test/analytics/tests/instrumented_events/from_the_server/core_context_providers.ts index cf781bed5ad0e..1d6b187c207f1 100644 --- a/test/analytics/tests/instrumented_events/from_the_server/core_context_providers.ts +++ b/test/analytics/tests/instrumented_events/from_the_server/core_context_providers.ts @@ -17,7 +17,7 @@ export default function ({ getService }: FtrProviderContext) { describe('Core Context Providers', () => { let event: Event>; before(async () => { - let i = 2; + let i = 1; do { // Wait until we get a GREEN "status_changed" event. At that point all the context providers should be set up. const events = await ebtServerHelper.getEvents(i, { diff --git a/x-pack/plugins/task_manager/server/lib/calculate_health_status.test.ts b/x-pack/plugins/task_manager/server/lib/calculate_health_status.test.ts index 16caafb982886..6c9a9efeb558e 100644 --- a/x-pack/plugins/task_manager/server/lib/calculate_health_status.test.ts +++ b/x-pack/plugins/task_manager/server/lib/calculate_health_status.test.ts @@ -267,7 +267,7 @@ describe('calculateHealthStatus', () => { true, logger ) - ).toEqual({ status: HealthStatus.Warning, reason: `no health stats available` }); + ).toEqual({ status: HealthStatus.Uninitialized, reason: `no health stats available` }); }); test('should return error status if any stat has status error', () => { diff --git a/x-pack/plugins/task_manager/server/lib/calculate_health_status.ts b/x-pack/plugins/task_manager/server/lib/calculate_health_status.ts index 7826b701551d9..15a206625efa8 100644 --- a/x-pack/plugins/task_manager/server/lib/calculate_health_status.ts +++ b/x-pack/plugins/task_manager/server/lib/calculate_health_status.ts @@ -21,7 +21,7 @@ export function calculateHealthStatus( // if stats are empty, return a warning if (isEmpty(summarizedStats.stats)) { - return { status: HealthStatus.Warning, reason: `no health stats available` }; + return { status: HealthStatus.Uninitialized, reason: `no health stats available` }; } // if "hot" health stats are any more stale than monitored_stats_required_freshness diff --git a/x-pack/plugins/task_manager/server/monitoring/monitoring_stats_stream.ts b/x-pack/plugins/task_manager/server/monitoring/monitoring_stats_stream.ts index 62505a34d7f89..a05eca7079ca4 100644 --- a/x-pack/plugins/task_manager/server/monitoring/monitoring_stats_stream.ts +++ b/x-pack/plugins/task_manager/server/monitoring/monitoring_stats_stream.ts @@ -55,6 +55,7 @@ export interface MonitoringStats { } export enum HealthStatus { + Uninitialized = 'uninitialized', OK = 'OK', Warning = 'warn', Error = 'error', diff --git a/x-pack/plugins/task_manager/server/routes/health.ts b/x-pack/plugins/task_manager/server/routes/health.ts index 7a348147b0b76..f6c6dfb88aad4 100644 --- a/x-pack/plugins/task_manager/server/routes/health.ts +++ b/x-pack/plugins/task_manager/server/routes/health.ts @@ -14,7 +14,7 @@ import { } from '@kbn/core/server'; import { IClusterClient, DocLinksServiceSetup } from '@kbn/core/server'; import { Observable, Subject } from 'rxjs'; -import { tap, map } from 'rxjs/operators'; +import { tap, map, filter } from 'rxjs/operators'; import { throttleTime } from 'rxjs/operators'; import { UsageCounter } from '@kbn/usage-collection-plugin/server'; import { Logger, ServiceStatus, ServiceStatusLevels } from '@kbn/core/server'; @@ -114,7 +114,8 @@ export function healthRoute(params: HealthRouteParams): { }), // Only calculate the summarized stats (calculates all running averages and evaluates state) // when needed by throttling down to the requiredHotStatsFreshness - map((stats) => withServiceStatus(getHealthStatus(stats))) + map((stats) => withServiceStatus(getHealthStatus(stats))), + filter(([monitoredHealth]) => monitoredHealth.status !== HealthStatus.Uninitialized) ) .subscribe(([monitoredHealth, serviceStatus]) => { serviceStatus$.next(serviceStatus);