Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Feb 22, 2021
1 parent 70618f6 commit 4a61b64
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
28 changes: 19 additions & 9 deletions src/core/server/status/status_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
*/

import { Observable, combineLatest, Subscription } from 'rxjs';
import { map, distinctUntilChanged, shareReplay, take, debounceTime } from 'rxjs/operators';
import {
map,
distinctUntilChanged,
shareReplay,
take,
debounceTime,
pairwise,
startWith,
} from 'rxjs/operators';
import { isDeepStrictEqual } from 'util';

import { CoreService } from '../../types';
Expand Down Expand Up @@ -39,6 +47,7 @@ export class StatusService implements CoreService<InternalStatusServiceSetup> {
private readonly logger: Logger;
private readonly config$: Observable<StatusConfigType>;

private overall$?: Observable<ServiceStatus>;
private pluginsStatus?: PluginsStatusService;
private overallSubscription?: Subscription;

Expand All @@ -59,10 +68,7 @@ export class StatusService implements CoreService<InternalStatusServiceSetup> {
const core$ = this.setupCoreStatus({ elasticsearch, savedObjects });
this.pluginsStatus = new PluginsStatusService({ core$, pluginDependencies });

const overall$: Observable<ServiceStatus> = combineLatest([
core$,
this.pluginsStatus.getAll$(),
]).pipe(
this.overall$ = combineLatest([core$, this.pluginsStatus.getAll$()]).pipe(
// Prevent many emissions at once from dependency status resolution from making this too noisy
debounceTime(500),
map(([coreStatus, pluginsStatus]) => {
Expand All @@ -78,7 +84,7 @@ export class StatusService implements CoreService<InternalStatusServiceSetup> {
);

// Create an unused subscription to ensure all underlying lazy observables are started.
this.overallSubscription = overall$.subscribe();
this.overallSubscription = this.overall$.subscribe();

const router = http.createRouter('');
registerStatusRoute({
Expand All @@ -91,15 +97,15 @@ export class StatusService implements CoreService<InternalStatusServiceSetup> {
},
metrics,
status: {
overall$,
overall$: this.overall$,
plugins$: this.pluginsStatus.getAll$(),
core$,
},
});

return {
core$,
overall$,
overall$: this.overall$,
plugins: {
set: this.pluginsStatus.set.bind(this.pluginsStatus),
getDependenciesStatus$: this.pluginsStatus.getDependenciesStatus$.bind(this.pluginsStatus),
Expand All @@ -109,7 +115,11 @@ export class StatusService implements CoreService<InternalStatusServiceSetup> {
};
}

public start() {}
public start() {
this.overall$!.pipe(startWith(undefined), pairwise()).subscribe(([oldStatus, newStatus]) => {
this.logger.info(`Kibana overall status is now ${newStatus!.level.toString()}`);
});
}

public stop() {
if (this.overallSubscription) {
Expand Down
24 changes: 23 additions & 1 deletion x-pack/plugins/licensing/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { Observable, Subject, Subscription, timer } from 'rxjs';
import { take, startWith, map } from 'rxjs/operators';
import moment from 'moment';
import { createHash } from 'crypto';
import stringify from 'json-stable-stringify';
Expand All @@ -18,7 +19,8 @@ import {
Plugin,
PluginInitializerContext,
IClusterClient,
} from 'src/core/server';
ServiceStatusLevels,
} from '../../../../src/core/server';

import { ILicense, PublicLicense, PublicFeatures } from '../common/types';
import { LicensingPluginSetup, LicensingPluginStart } from './types';
Expand Down Expand Up @@ -107,6 +109,26 @@ export class LicensingPlugin implements Plugin<LicensingPluginSetup, LicensingPl
pollingFrequency.asMilliseconds()
);

core.status.set(
license$.pipe(
startWith(undefined),
take(2),
map((license) => {
if (license) {
return {
level: ServiceStatusLevels.available,
summary: 'License fetched',
};
} else {
return {
level: ServiceStatusLevels.degraded,
summary: 'license not fetched yet',
};
}
})
)
);

core.http.registerRouteHandlerContext(
'licensing',
createRouteHandlerContext(license$, core.getStartServices)
Expand Down

0 comments on commit 4a61b64

Please sign in to comment.