Skip to content
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
39ba6a6
feat(infra): add logs.app_target config
Mar 31, 2023
f61e185
refactor(infra): stricter parameter validation
Mar 31, 2023
0e19e58
refactor(infra): update tests
Mar 31, 2023
1596b6b
refactor(infra): update functional tests
Mar 31, 2023
b4b21e3
chore(infra): include discover plugin to access locator
Apr 3, 2023
e5e0a70
feat(infra): add logs app service
Apr 3, 2023
e7d61b8
feat(infra): consume logs app service
Apr 3, 2023
539c7d9
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Apr 3, 2023
e4995f7
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani Apr 4, 2023
b2346f6
feat(infra): minor change
Apr 4, 2023
f91d543
refactor(infra): lift navigation higher in the tree
Apr 12, 2023
643f798
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Apr 12, 2023
7dcef58
refactor(infra): create discover app
Apr 12, 2023
8a0b2c3
Merge branch '153890-redirect-logs-ui-to-discover-serverless' of gith…
Apr 12, 2023
4c08f60
refactor(infra): fix merge conflict
Apr 12, 2023
e280f64
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani Apr 12, 2023
313c330
refactor(infra): stricter app mount
Apr 12, 2023
712783a
refactor(infra): stop machine service on unmount
Apr 12, 2023
6d4d032
refactor(infra): remove unused type
Apr 12, 2023
694b6be
refactor(infra): minor change
Apr 12, 2023
0e5b194
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani Apr 12, 2023
071da03
refactor(infra): remove doc for xpack.infra.logs.app_target config
Apr 13, 2023
19ab5a2
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani Apr 13, 2023
5d41247
Merge branch '153890-redirect-logs-ui-to-discover-serverless' of gith…
Apr 13, 2023
5f2d288
refactor(infra): use toSpec method to create locator config
Apr 13, 2023
9b363ee
refactor(infra): split logs and discover apps registrations
Apr 13, 2023
fef8be3
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Apr 13, 2023
7748e7e
refactor(infra): change requests
Apr 13, 2023
f2c2d84
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani Apr 13, 2023
9ff6c2d
refactor(infra): replace url on logs redirect
Apr 17, 2023
f2db6f2
refactor(infra): apply name to ad-hoc data view
Apr 17, 2023
0835ce5
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani Apr 17, 2023
04e9316
refactor(infra): restore log view from url
Apr 19, 2023
8ae8fb5
fix(fleet): mismatching config name
Apr 19, 2023
31a3018
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani Apr 19, 2023
36e7b92
Merge branch 'main' into 153890-redirect-logs-ui-to-discover-serverless
tonyghiani Apr 19, 2023
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
1 change: 1 addition & 0 deletions config/serverless.oblt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xpack.infra.logs.app_target: discover
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.graph.savePolicy (alternatives)',
'xpack.ilm.ui.enabled (boolean)',
'xpack.index_management.ui.enabled (boolean)',
'xpack.infra.logs.app_target (alternatives)',
'xpack.infra.sources.default.fields.message (array)',
'xpack.license_management.ui.enabled (boolean)',
'xpack.maps.preserveDrawingBuffer (boolean)',
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/infra/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const LOGS_FEATURE_ID = 'logs';
export type InfraFeatureId = typeof METRICS_FEATURE_ID | typeof LOGS_FEATURE_ID;

export const TIMESTAMP_FIELD = '@timestamp';
export const MESSAGE_FIELD = 'message';
export const TIEBREAKER_FIELD = '_doc';
export const HOST_FIELD = 'host.name';
export const CONTAINER_FIELD = 'container.id';
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/infra/common/plugin_config_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export interface InfraConfig {
inventory: {
compositeSize: number;
};
logs: {
app_target: 'logs-ui' | 'discover';
};
sources?: {
default?: {
fields?: {
Expand All @@ -28,6 +31,7 @@ export interface InfraConfig {

export const publicConfigKeys = {
sources: true,
logs: true,
} as const;

export type InfraPublicConfigKey = keyof {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/infra/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"charts",
"data",
"dataViews",
"discover",
"embeddable",
"features",
"lens",
Expand Down
76 changes: 76 additions & 0 deletions x-pack/plugins/infra/public/apps/discover_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { interpret } from 'xstate';
import type { DiscoverStart } from '@kbn/discover-plugin/public';
import type { InfraClientStartDeps, InfraClientStartExports } from '../types';
import type { LogViewColumnConfiguration, ResolvedLogView } from '../../common/log_views';
import { createLogViewStateMachine, DEFAULT_LOG_VIEW } from '../observability_logs/log_view_state';
import { MESSAGE_FIELD, TIMESTAMP_FIELD } from '../../common/constants';

export const renderApp = (plugins: InfraClientStartDeps, pluginStart: InfraClientStartExports) => {
const { discover } = plugins;
const { logViews } = pluginStart;

const machine = createLogViewStateMachine({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to use the log view reference from the url instead of a hard-coded default here? Or am I missing some other mechanism using which it is initialized correctly?

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.

I didn't think of it and you are right, it was always using the default log view, even with a different one specified in the URL. I created the initializeFromUrl function and passed it to the state machine, now it does correctly recover the URL param if exists.

initialContext: { logViewReference: DEFAULT_LOG_VIEW },
logViews: logViews.client,
});

const service = interpret(machine)
.onTransition((state) => {
if (
state.matches('checkingStatus') ||
state.matches('resolvedPersistedLogView') ||
state.matches('resolvedInlineLogView')
) {
return redirectToDiscover(discover, state.context.resolvedLogView);
} else if (
state.matches('loadingFailed') ||
state.matches('resolutionFailed') ||
state.matches('checkingStatusFailed')
) {
return redirectToDiscover(discover);
}
})
.start();

return () => {
// Stop machine interpreter after navigation
service.stop();
};
};

const redirectToDiscover = (discover: DiscoverStart, resolvedLogView?: ResolvedLogView) => {
if (!resolvedLogView) {
return discover.locator?.navigate({});
}

const columns = parseColumns(resolvedLogView.columns);
const dataViewSpec = resolvedLogView.dataViewReference.toSpec();

return discover.locator?.navigate({
columns,
dataViewId: dataViewSpec.id,
dataViewSpec,
});
};

/**
* Helpers
*/

const parseColumns = (columns: ResolvedLogView['columns']) => {
return columns.map(getColumnValue).filter(Boolean) as string[];
};

const getColumnValue = (column: LogViewColumnConfiguration) => {
if ('messageColumn' in column) return MESSAGE_FIELD;
if ('timestampColumn' in column) return TIMESTAMP_FIELD;
if ('fieldColumn' in column) return column.fieldColumn.field;

return null;
};
112 changes: 66 additions & 46 deletions x-pack/plugins/infra/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import {
AppMountParameters,
AppNavLinkStatus,
AppUpdater,
CoreStart,
DEFAULT_APP_CATEGORIES,
Expand Down Expand Up @@ -136,54 +137,73 @@ export class Plugin implements InfraClientPluginClass {
new LogStreamEmbeddableFactoryDefinition(core.getStartServices)
);

core.application.register({
id: 'logs',
title: i18n.translate('xpack.infra.logs.pluginTitle', {
defaultMessage: 'Logs',
}),
euiIconType: 'logoObservability',
order: 8100,
appRoute: '/app/logs',
// !! Need to be kept in sync with the routes in x-pack/plugins/infra/public/pages/logs/page_content.tsx
deepLinks: [
{
id: 'stream',
title: i18n.translate('xpack.infra.logs.index.streamTabTitle', {
defaultMessage: 'Stream',
}),
path: '/stream',
},
{
id: 'anomalies',
title: i18n.translate('xpack.infra.logs.index.anomaliesTabTitle', {
defaultMessage: 'Anomalies',
}),
path: '/anomalies',
},
{
id: 'log-categories',
title: i18n.translate('xpack.infra.logs.index.logCategoriesBetaBadgeTitle', {
defaultMessage: 'Categories',
}),
path: '/log-categories',
},
{
id: 'settings',
title: i18n.translate('xpack.infra.logs.index.settingsTabTitle', {
defaultMessage: 'Settings',
}),
path: '/settings',
if (this.config.logs.app_target === 'discover') {
core.application.register({
id: 'logs-to-discover',
title: '',
navLinkStatus: AppNavLinkStatus.hidden,
appRoute: '/app/logs',
mount: async () => {
// mount callback should not use setup dependencies, get start dependencies instead
const [_coreStart, plugins, pluginStart] = await core.getStartServices();

const { renderApp } = await import('./apps/discover_app');

return renderApp(plugins, pluginStart);
},
],
category: DEFAULT_APP_CATEGORIES.observability,
mount: async (params: AppMountParameters) => {
// mount callback should not use setup dependencies, get start dependencies instead
const [coreStart, pluginsStart, pluginStart] = await core.getStartServices();
const { renderApp } = await import('./apps/logs_app');
});
}

return renderApp(coreStart, pluginsStart, pluginStart, params);
},
});
if (this.config.logs.app_target === 'logs-ui') {
core.application.register({
id: 'logs',
title: i18n.translate('xpack.infra.logs.pluginTitle', {
defaultMessage: 'Logs',
}),
euiIconType: 'logoObservability',
order: 8100,
appRoute: '/app/logs',
// !! Need to be kept in sync with the routes in x-pack/plugins/infra/public/pages/logs/page_content.tsx
deepLinks: [
{
id: 'stream',
title: i18n.translate('xpack.infra.logs.index.streamTabTitle', {
defaultMessage: 'Stream',
}),
path: '/stream',
},
{
id: 'anomalies',
title: i18n.translate('xpack.infra.logs.index.anomaliesTabTitle', {
defaultMessage: 'Anomalies',
}),
path: '/anomalies',
},
{
id: 'log-categories',
title: i18n.translate('xpack.infra.logs.index.logCategoriesBetaBadgeTitle', {
defaultMessage: 'Categories',
}),
path: '/log-categories',
},
{
id: 'settings',
title: i18n.translate('xpack.infra.logs.index.settingsTabTitle', {
defaultMessage: 'Settings',
}),
path: '/settings',
},
],
category: DEFAULT_APP_CATEGORIES.observability,
mount: async (params: AppMountParameters) => {
// mount callback should not use setup dependencies, get start dependencies instead
const [coreStart, plugins, pluginStart] = await core.getStartServices();

const { renderApp } = await import('./apps/logs_app');
return renderApp(coreStart, plugins, pluginStart, params);
},
});
}

// !! Need to be kept in sync with the routes in x-pack/plugins/infra/public/pages/metrics/index.tsx
const infraDeepLinks = [
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/infra/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
import { type TypedLensByValueInput, LensPublicStart } from '@kbn/lens-plugin/public';
import type { ChartsPluginStart } from '@kbn/charts-plugin/public';
import { CasesUiStart } from '@kbn/cases-plugin/public';
import { DiscoverStart } from '@kbn/discover-plugin/public';
import type { UnwrapPromise } from '../common/utility_types';
import type {
SourceProviderProps,
Expand Down Expand Up @@ -74,6 +75,7 @@ export interface InfraClientStartDeps {
charts: ChartsPluginStart;
data: DataPublicPluginStart;
dataViews: DataViewsPublicPluginStart;
discover: DiscoverStart;
embeddable?: EmbeddableStart;
lens: LensPublicStart;
ml: MlPluginStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ const createMockStaticConfiguration = (sources: any) => ({
inventory: {
compositeSize: 2000,
},
logs: {
app_target: 'logs-ui',
},
sources,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import { Evaluation } from './lib/evaluate_rule';
import type { LogMeta, Logger } from '@kbn/logging';
import { DEFAULT_FLAPPING_SETTINGS } from '@kbn/alerting-plugin/common';
import { InfraConfig } from '../../../../common/plugin_config_types';

jest.mock('./lib/evaluate_rule', () => ({ evaluateRule: jest.fn() }));

Expand Down Expand Up @@ -1818,7 +1819,7 @@ describe('The metric threshold alert type', () => {
});
});

const createMockStaticConfiguration = (sources: any) => ({
const createMockStaticConfiguration = (sources: any): InfraConfig => ({
alerting: {
inventory_threshold: {
group_by_page_size: 100,
Expand All @@ -1830,6 +1831,9 @@ const createMockStaticConfiguration = (sources: any) => ({
inventory: {
compositeSize: 2000,
},
logs: {
app_target: 'logs-ui',
},
sources,
});

Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/infra/server/lib/sources/sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { SavedObject } from '@kbn/core/server';
import { InfraConfig } from '../../types';
import { infraSourceConfigurationSavedObjectName } from './saved_object_type';
import { InfraSources } from './sources';

Expand Down Expand Up @@ -108,7 +109,7 @@ describe('the InfraSources lib', () => {
});
});

const createMockStaticConfiguration = (sources: any) => ({
const createMockStaticConfiguration = (sources: any): InfraConfig => ({
alerting: {
inventory_threshold: {
group_by_page_size: 10000,
Expand All @@ -117,10 +118,12 @@ const createMockStaticConfiguration = (sources: any) => ({
group_by_page_size: 10000,
},
},
enabled: true,
inventory: {
compositeSize: 2000,
},
logs: {
app_target: 'logs-ui',
},
sources,
});

Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/infra/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ import { UsageCollector } from './usage/usage_collector';

export const config: PluginConfigDescriptor<InfraConfig> = {
schema: schema.object({
logs: schema.object({
app_target: schema.oneOf([schema.literal('logs-ui'), schema.literal('discover')], {
defaultValue: 'logs-ui',
}),
}),
alerting: schema.object({
inventory_threshold: schema.object({
group_by_page_size: schema.number({ defaultValue: 5_000 }),
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/infra/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@kbn/shared-ux-prompt-not-found",
"@kbn/shared-ux-router",
"@kbn/shared-ux-link-redirect-app",
"@kbn/discover-plugin",
"@kbn/observability-alert-details",
"@kbn/ui-theme"
],
Expand Down