Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 39 additions & 11 deletions x-pack/plugins/infra/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
* 2.0.
*/

import {
AppMountParameters,
AppUpdater,
CoreStart,
DEFAULT_APP_CATEGORIES,
PluginInitializerContext,
} from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { AppMountParameters, PluginInitializerContext } from '@kbn/core/public';
import { from } from 'rxjs';
import { map } from 'rxjs/operators';
import { DEFAULT_APP_CATEGORIES } from '@kbn/core/public';
import { enableInfrastructureHostsView } from '@kbn/observability-plugin/public';
import { BehaviorSubject, combineLatest, from } from 'rxjs';
import { map } from 'rxjs/operators';
import { defaultLogViewsStaticConfig } from '../common/log_views';
import { InfraPublicConfig } from '../common/plugin_config_types';
import { createInventoryMetricRuleType } from './alerting/inventory';
Expand Down Expand Up @@ -38,6 +43,7 @@ import { getLogsHasDataFetcher, getLogsOverviewDataFetcher } from './utils/logs_
export class Plugin implements InfraClientPluginClass {
public config: InfraPublicConfig;
private logViews: LogViewsService;
private readonly appUpdater$ = new BehaviorSubject<AppUpdater>(() => ({}));

constructor(context: PluginInitializerContext<InfraPublicConfig>) {
this.config = context.config.get();
Expand Down Expand Up @@ -74,19 +80,27 @@ export class Plugin implements InfraClientPluginClass {
fetchData: createMetricsFetchData(core.getStartServices),
});

const startDep$AndHostViewFlag$ = combineLatest([
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea how to name this combination

from(core.getStartServices()),
core.uiSettings.get$<boolean>(enableInfrastructureHostsView),
]);

/** !! Need to be kept in sync with the deepLinks in x-pack/plugins/infra/public/plugin.ts */
const infraEntries = [
{ label: 'Inventory', app: 'metrics', path: '/inventory' },
{ label: 'Metrics Explorer', app: 'metrics', path: '/explorer' },
];
const hostInfraEntry = { label: 'Hosts', app: 'metrics', path: '/hosts' };
pluginsSetup.observability.navigation.registerSections(
from(core.getStartServices()).pipe(
startDep$AndHostViewFlag$.pipe(
map(
([
{
application: { capabilities },
},
[
{
application: { capabilities },
},
],
isInfrastructureHostsViewEnabled,
]) => [
...(capabilities.logs.show
? [
Expand All @@ -106,7 +120,7 @@ export class Plugin implements InfraClientPluginClass {
{
label: 'Infrastructure',
sortKey: 300,
entries: core.uiSettings.get(enableInfrastructureHostsView)
entries: isInfrastructureHostsViewEnabled
? [hostInfraEntry, ...infraEntries]
: infraEntries,
},
Expand Down Expand Up @@ -171,6 +185,7 @@ export class Plugin implements InfraClientPluginClass {
},
});

// !! Need to be kept in sync with the routes in x-pack/plugins/infra/public/pages/metrics/index.tsx
const infraDeepLinks = [
{
id: 'inventory',
Expand Down Expand Up @@ -210,8 +225,8 @@ export class Plugin implements InfraClientPluginClass {
order: 8200,
appRoute: '/app/metrics',
category: DEFAULT_APP_CATEGORIES.observability,
// !! Need to be kept in sync with the routes in x-pack/plugins/infra/public/pages/metrics/index.tsx
deepLinks: core.uiSettings.get(enableInfrastructureHostsView)
updater$: this.appUpdater$,
deepLinks: core.uiSettings.get<boolean>(enableInfrastructureHostsView)
? [hostInfraDeepLink, ...infraDeepLinks]
: infraDeepLinks,
mount: async (params: AppMountParameters) => {
Expand All @@ -223,6 +238,19 @@ export class Plugin implements InfraClientPluginClass {
},
});

startDep$AndHostViewFlag$.subscribe(
([_startServices, isInfrastructureHostsViewEnabled]: [
[CoreStart, InfraClientStartDeps, InfraClientStartExports],
boolean
]) => {
this.appUpdater$.next(() => ({
deepLinks: isInfrastructureHostsViewEnabled
? [hostInfraDeepLink, ...infraDeepLinks]
: infraDeepLinks,
}));
}
);

/* This exists purely to facilitate URL redirects from the old App ID ("infra"),
to our new App IDs ("metrics" and "logs"). With version 8.0.0 we can remove this. */
core.application.register({
Expand Down