Skip to content

Commit

Permalink
[Logs] Deprecate configuration settings (#201625)
Browse files Browse the repository at this point in the history
## 📓 Summary

Closes #200898 

These changes deprecate some unused configurations and update the
implementation where required in preparation for the Kibana v9 upgrade.

<img width="3004" alt="Screenshot 2024-11-25 at 12 54 14"
src="https://github.com/user-attachments/assets/cfa56d25-a270-4ec5-a97a-e72e7a7478a4">

---------

Co-authored-by: Marco Antonio Ghiani <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
3 people authored Dec 5, 2024
1 parent 542aa52 commit 2994b00
Show file tree
Hide file tree
Showing 19 changed files with 208 additions and 166 deletions.
113 changes: 113 additions & 0 deletions x-pack/plugins/observability_solution/infra/server/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* 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 { i18n } from '@kbn/i18n';

import { offeringBasedSchema, schema } from '@kbn/config-schema';
import { PluginConfigDescriptor } from '@kbn/core-plugins-server';
import { ConfigDeprecation } from '@kbn/config';
import { InfraConfig } from './types';
import { publicConfigKeys } from '../common/plugin_config_types';

export type { InfraConfig };

export const config: PluginConfigDescriptor<InfraConfig> = {
schema: schema.object({
enabled: schema.boolean({ defaultValue: true }),
alerting: schema.object({
inventory_threshold: schema.object({
group_by_page_size: schema.number({ defaultValue: 5_000 }),
}),
metric_threshold: schema.object({
group_by_page_size: schema.number({ defaultValue: 10_000 }),
}),
}),
inventory: schema.object({
compositeSize: schema.number({ defaultValue: 2000 }),
}),
sources: schema.maybe(
schema.object({
default: schema.maybe(
schema.object({
fields: schema.maybe(
schema.object({
message: schema.maybe(schema.arrayOf(schema.string())),
})
),
})
),
})
),
featureFlags: schema.object({
customThresholdAlertsEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: false }),
serverless: schema.boolean({ defaultValue: false }),
}),
logsUIEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: false }),
}),
metricsExplorerEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: false }),
}),
osqueryEnabled: schema.boolean({ defaultValue: true }),
inventoryThresholdAlertRuleEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: true }),
}),
metricThresholdAlertRuleEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: false }),
}),
logThresholdAlertRuleEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: false }),
}),
alertsAndRulesDropdownEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: true }),
}),
/**
* Depends on optional "profilingDataAccess" and "profiling"
* plugins. Enable both with `xpack.profiling.enabled: true` before
* enabling this feature flag.
*/
profilingEnabled: schema.boolean({ defaultValue: false }),
ruleFormV2Enabled: schema.boolean({ defaultValue: false }),
}),
}),
deprecations: () => [sourceFieldsMessageDeprecation],
exposeToBrowser: publicConfigKeys,
};

const sourceFieldsMessageDeprecation: ConfigDeprecation = (settings, fromPath, addDeprecation) => {
const sourceFieldsMessageSetting = settings?.xpack?.infra?.sources?.default?.fields?.message;

if (sourceFieldsMessageSetting) {
addDeprecation({
configPath: `${fromPath}.sources.default.fields.message`,
title: i18n.translate('xpack.infra.deprecations.sourcesDefaultFieldsMessage.title', {
defaultMessage: 'The "xpack.infra.sources.default.fields.message" setting is deprecated.',
ignoreTag: true,
}),
message: i18n.translate('xpack.infra.deprecations.sourcesDefaultFieldsMessage.message', {
defaultMessage:
'Features using this configurations are set to be removed in v9 and this is no longer used.',
}),
level: 'warning',
documentationUrl: `https://www.elastic.co/guide/en/kibana/current/logs-ui-settings-kb.html#general-logs-ui-settings-kb`,
correctiveActions: {
manualSteps: [
i18n.translate('xpack.infra.deprecations.sourcesDefaultFieldsMessage.manualSteps1', {
defaultMessage: 'Remove "xpack.infra.sources.default.fields.message" from kibana.yml.',
ignoreTag: true,
}),
],
},
});
}
};
4 changes: 1 addition & 3 deletions x-pack/plugins/observability_solution/infra/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
*/

import { PluginInitializerContext } from '@kbn/core/server';
import { config, InfraConfig } from './plugin';

export { config, type InfraConfig } from './config';
export type { InfraPluginSetup, InfraPluginStart, InfraRequestHandlerContext } from './types';
export type { InfraConfig };
export { config };

export async function plugin(context: PluginInitializerContext) {
const { InfraServerPlugin } = await import('./plugin');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { UI_SETTINGS } from '@kbn/data-plugin/server';
import { TimeseriesVisData } from '@kbn/vis-type-timeseries-plugin/server';
import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common';
import { TSVBMetricModel } from '@kbn/metrics-data-access-plugin/common';
import { InfraConfig } from '../../../plugin';
import type { InfraPluginRequestHandlerContext } from '../../../types';
import type { InfraConfig, InfraPluginRequestHandlerContext } from '../../../types';
import {
CallWithRequestParams,
InfraDatabaseGetIndicesAliasResponse,
Expand Down
80 changes: 1 addition & 79 deletions x-pack/plugins/observability_solution/infra/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
*/

import { Server } from '@hapi/hapi';
import { schema, offeringBasedSchema } from '@kbn/config-schema';
import {
CoreStart,
Plugin,
PluginConfigDescriptor,
PluginInitializerContext,
} from '@kbn/core/server';
import { CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/server';
import { handleEsError } from '@kbn/es-ui-shared-plugin/server';
import { i18n } from '@kbn/i18n';
import { Logger } from '@kbn/logging';
Expand All @@ -26,7 +20,6 @@ import {
import { type AlertsLocatorParams, alertsLocatorID } from '@kbn/observability-plugin/common';
import { mapValues } from 'lodash';
import { LOGS_FEATURE_ID, METRICS_FEATURE_ID } from '../common/constants';
import { publicConfigKeys } from '../common/plugin_config_types';
import { LOGS_FEATURE, METRICS_FEATURE } from './features';
import { registerRoutes } from './infra_server';
import { InfraServerPluginSetupDeps, InfraServerPluginStartDeps } from './lib/adapters/framework';
Expand Down Expand Up @@ -61,77 +54,6 @@ import { UsageCollector } from './usage/usage_collector';
import { mapSourceToLogView } from './utils/map_source_to_log_view';
import { uiSettings } from '../common/ui_settings';

export const config: PluginConfigDescriptor<InfraConfig> = {
schema: schema.object({
enabled: schema.boolean({ defaultValue: true }),
alerting: schema.object({
inventory_threshold: schema.object({
group_by_page_size: schema.number({ defaultValue: 5_000 }),
}),
metric_threshold: schema.object({
group_by_page_size: schema.number({ defaultValue: 10_000 }),
}),
}),
inventory: schema.object({
compositeSize: schema.number({ defaultValue: 2000 }),
}),
sources: schema.maybe(
schema.object({
default: schema.maybe(
schema.object({
fields: schema.maybe(
schema.object({
message: schema.maybe(schema.arrayOf(schema.string())),
})
),
})
),
})
),
featureFlags: schema.object({
customThresholdAlertsEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: false }),
serverless: schema.boolean({ defaultValue: false }),
}),
logsUIEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: false }),
}),
metricsExplorerEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: false }),
}),
osqueryEnabled: schema.boolean({ defaultValue: true }),
inventoryThresholdAlertRuleEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: true }),
}),
metricThresholdAlertRuleEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: false }),
}),
logThresholdAlertRuleEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: false }),
}),
alertsAndRulesDropdownEnabled: offeringBasedSchema({
traditional: schema.boolean({ defaultValue: true }),
serverless: schema.boolean({ defaultValue: true }),
}),
/**
* Depends on optional "profilingDataAccess" and "profiling"
* plugins. Enable both with `xpack.profiling.enabled: true` before
* enabling this feature flag.
*/
profilingEnabled: schema.boolean({ defaultValue: false }),
ruleFormV2Enabled: schema.boolean({ defaultValue: false }),
}),
}),
exposeToBrowser: publicConfigKeys,
};

export type { InfraConfig };

export interface KbnServer extends Server {
usage: any;
}
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/observability_solution/infra/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
"@kbn/entities-schema",
"@kbn/zod",
"@kbn/observability-utils-server",
"@kbn/core-plugins-server",
"@kbn/config",
"@kbn/observability-utils-common"
],
"exclude": ["target/**/*"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export const configSchema = schema.object({

export const config: PluginConfigDescriptor<LogsSharedConfig> = {
schema: configSchema,
deprecations: ({ unused }) => [unused('savedObjects.logView.enabled', { level: 'warning' })],
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export interface LogsSharedBackendLibs extends LogsSharedDomainLibs {
getStartServices: LogsSharedPluginStartServicesAccessor;
getUsageCollector: () => UsageCollector;
logger: Logger;
isServerless: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class LogsSharedPlugin
private logViews: LogViewsService;
private usageCollector: UsageCollector;

constructor(context: PluginInitializerContext<LogsSharedConfig>) {
constructor(private readonly context: PluginInitializerContext<LogsSharedConfig>) {
this.config = context.config.get();
this.logger = context.logger.get();
this.usageCollector = {};
Expand All @@ -51,11 +51,13 @@ export class LogsSharedPlugin
}

public setup(core: LogsSharedPluginCoreSetup, plugins: LogsSharedServerPluginSetupDeps) {
const isServerless = this.context.env.packageInfo.buildFlavor === 'serverless';

const framework = new KibanaFramework(core, plugins);

const logViews = this.logViews.setup();

if (this.config.savedObjects.logView.enabled) {
if (!isServerless) {
// Conditionally register log view saved objects
core.savedObjects.registerType(logViewSavedObjectType);
} else {
Expand All @@ -78,6 +80,7 @@ export class LogsSharedPlugin
getStartServices: () => core.getStartServices(),
getUsageCollector: () => this.usageCollector,
logger: this.logger,
isServerless,
};

// Register server side APIs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const initGetLogViewRoute = ({
config,
framework,
getStartServices,
isServerless,
}: LogsSharedBackendLibs) => {
framework
.registerVersionedRoute({
Expand Down Expand Up @@ -41,7 +42,7 @@ export const initGetLogViewRoute = ({
* - if the log view saved object is correctly registered, perform a lookup for retrieving it
* - else, skip the saved object lookup and immediately get the internal log view if exists.
*/
const logView = config.savedObjects.logView.enabled
const logView = !isServerless
? await logViewsClient.getLogView(logViewId)
: await logViewsClient.getInternalLogView(logViewId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const initLogViewRoutes = (libs: LogsSharedBackendLibs) => {
initGetLogViewRoute(libs);

// Register the log view update endpoint only when the Saved object is correctly registered
if (libs.config.savedObjects.logView.enabled) {
if (!libs.isServerless) {
initPutLogViewRoute(libs);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ import type {
export class ObservabilityLogsExplorerPlugin
implements Plugin<ObservabilityLogsExplorerPluginSetup, ObservabilityLogsExplorerPluginStart>
{
private config: ObservabilityLogsExplorerConfig;
private locators?: ObservabilityLogsExplorerLocators;
private appStateUpdater = new BehaviorSubject<AppUpdater>(() => ({}));

constructor(context: PluginInitializerContext<ObservabilityLogsExplorerConfig>) {
this.config = context.config.get();
}
constructor(context: PluginInitializerContext<ObservabilityLogsExplorerConfig>) {}

public setup(
core: CoreSetup<ObservabilityLogsExplorerStartDeps, ObservabilityLogsExplorerPluginStart>,
Expand All @@ -56,9 +53,7 @@ export class ObservabilityLogsExplorerPlugin
title: logsExplorerAppTitle,
category: DEFAULT_APP_CATEGORIES.observability,
euiIconType: 'logoLogging',
visibleIn: this.config.navigation.showAppLink
? ['globalSearch', 'sideNav']
: ['globalSearch'],
visibleIn: ['globalSearch'],
keywords: ['logs', 'log', 'explorer', 'logs explorer'],
updater$: this.appStateUpdater,
mount: async (appMountParams: ObservabilityLogsExplorerAppMountParameters) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const configSchema = schema.object({

export const config: PluginConfigDescriptor<ObservabilityLogsExplorerConfig> = {
schema: configSchema,
deprecations: ({ renameFromRoot }) => [
deprecations: ({ renameFromRoot, unused }) => [
renameFromRoot(
'xpack.discoverLogExplorer.featureFlags.deepLinkVisible',
'xpack.observabilityLogsExplorer.navigation.showAppLink',
Expand All @@ -41,6 +41,7 @@ export const config: PluginConfigDescriptor<ObservabilityLogsExplorerConfig> = {
'xpack.observabilityLogsExplorer.enabled',
{ level: 'warning' }
),
unused('navigation.showAppLink', { level: 'warning' }),
],
exposeToBrowser: {
navigation: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ interface Props {

export function ObservabilityOnboardingHeaderActionMenu({ setHeaderActionMenu, theme$ }: Props) {
const {
services: { config },
services: { context },
} = useKibana<ObservabilityOnboardingAppServices>();
const location = useLocation();
const normalizedPathname = location.pathname.replace(/\/$/, '');

const isRootPage = normalizedPathname === '';
const isServerless = config.serverless.enabled;

if (!isServerless && !isRootPage) {
if (!context.isServerless && !isRootPage) {
return (
<HeaderMenuPortal setHeaderActionMenu={setHeaderActionMenu} theme$={theme$}>
<EuiButton
Expand Down
Loading

0 comments on commit 2994b00

Please sign in to comment.