Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Sep 15, 2020
1 parent 4e30218 commit 64576c2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 35 deletions.
54 changes: 30 additions & 24 deletions src/core/server/status/legacy_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

import { pick } from 'lodash';
import { i18n } from '@kbn/i18n';
import { deepFreeze } from '@kbn/std';

import { ServiceStatusLevels, ServiceStatus, CoreStatus } from './types';
import { deepFreeze } from '../../utils';
import { PluginName } from '../plugins';

interface Deps {
Expand All @@ -31,26 +32,41 @@ interface Deps {
}

export interface LegacyStatusInfo {
overall: {
state: LegacyStatusState;
title: string;
nickname: string;
uiColor: LegacyStatusUiColor;
/** ISO-8601 date string w/o timezone */
since: string;
icon?: string;
};
overall: LegacyStatusOverall;
statuses: StatusComponentHttp[];
}

interface LegacyStatusOverall {
state: LegacyStatusState;
title: string;
nickname: string;
uiColor: LegacyStatusUiColor;
/** ISO-8601 date string w/o timezone */
since: string;
icon?: string;
}

type LegacyStatusState = 'green' | 'yellow' | 'red';
type LegacyStatusIcon = 'danger' | 'warning' | 'success';
type LegacyStatusUiColor = 'secondary' | 'warning' | 'danger';

interface LegacyStateAttr {
id: LegacyStatusState;
state: LegacyStatusState;
title: string;
icon: LegacyStatusIcon;
uiColor: LegacyStatusUiColor;
nickname: string;
}

export const calculateLegacyStatus = ({
core,
overall,
plugins,
versionWithoutSnapshot,
}: Deps): LegacyStatusInfo => {
const since = new Date().toISOString();
const overallLegacy: LegacyStatusInfo['overall'] = {
const overallLegacy: LegacyStatusOverall = {
since,
...pick(STATUS_LEVEL_LEGACY_ATTRS[overall.level.toString()], [
'state',
Expand Down Expand Up @@ -92,21 +108,11 @@ const serviceStatusToHttpComponent = (
id: serviceName,
message: status.summary,
since,
...pick(STATUS_LEVEL_LEGACY_ATTRS[status.level.toString()], ['state', 'icon', 'uiColor']), // TODO: only pick needed fields
...serviceStatusAttrs(status),
});

type LegacyStatusState = 'green' | 'yellow' | 'red';
type LegacyStatusIcon = 'danger' | 'warning' | 'success';
type LegacyStatusUiColor = 'secondary' | 'warning' | 'danger';

interface LegacyStateAttr {
id: LegacyStatusState;
state: LegacyStatusState;
title: string;
icon: LegacyStatusIcon;
uiColor: LegacyStatusUiColor;
nickname: string;
}
const serviceStatusAttrs = (status: ServiceStatus) =>
pick(STATUS_LEVEL_LEGACY_ATTRS[status.level.toString()], ['state', 'icon', 'uiColor']);

const STATUS_LEVEL_LEGACY_ATTRS = deepFreeze<Record<string, LegacyStateAttr>>({
[ServiceStatusLevels.critical.toString()]: {
Expand Down
18 changes: 7 additions & 11 deletions src/core/server/status/routes/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ interface StatusHttpBody {
}

export const registerStatusRoute = ({ router, config, metrics, status }: Deps) => {
// Since this observable is not subscribed to elsewhere, we need to subscribe
// here to eagerly load the plugins status when Kibana starts up.
const plugins$ = new ReplaySubject<Record<PluginName, ServiceStatus>>();
status.plugins$.subscribe(plugins$);
// Since the status.plugins$ observable is not subscribed to elsewhere, we need to subscribe it here to eagerly load
// the plugins status when Kibana starts up so this endpoint responds quickly on first boot.
const combinedStatus$ = new ReplaySubject<
[ServiceStatus<unknown>, CoreStatus, Record<string, ServiceStatus<unknown>>]
>();
combineLatest([status.overall$, status.core$, status.plugins$]).subscribe(combinedStatus$);

router.get(
{
Expand All @@ -125,13 +127,7 @@ export const registerStatusRoute = ({ router, config, metrics, status }: Deps) =
async (context, req, res) => {
const { version, buildSha, buildNum } = config.packageInfo;
const versionWithoutSnapshot = version.replace(SNAPSHOT_POSTFIX, '');
const [overall, core, plugins] = await combineLatest([
status.overall$,
status.core$,
plugins$,
])
.pipe(first())
.toPromise();
const [overall, core, plugins] = await combinedStatus$.pipe(first()).toPromise();

let statusInfo: StatusInfo | LegacyStatusInfo;
if (req.query?.v8format) {
Expand Down

0 comments on commit 64576c2

Please sign in to comment.