[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).
This commit is contained in:
Gerard Soldevila 2023-11-14 09:51:31 +01:00 committed by GitHub
parent cedaa3feec
commit 33ba4913e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 5 deletions

View file

@ -17,7 +17,7 @@ export default function ({ getService }: FtrProviderContext) {
describe('Core Context Providers', () => {
let event: Event<Record<string, unknown>>;
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, {

View file

@ -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', () => {

View file

@ -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

View file

@ -55,6 +55,7 @@ export interface MonitoringStats {
}
export enum HealthStatus {
Uninitialized = 'uninitialized',
OK = 'OK',
Warning = 'warn',
Error = 'error',

View file

@ -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);