diff --git a/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker b/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker index 42cf433046e3f..a9a54bf6794b2 100755 --- a/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker +++ b/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker @@ -375,6 +375,7 @@ kibana_vars=( xpack.task_manager.poll_interval xpack.task_manager.request_capacity xpack.task_manager.version_conflict_threshold + xpack.uptime.index ) longopts='' diff --git a/x-pack/plugins/uptime/server/config.ts b/x-pack/plugins/uptime/server/config.ts new file mode 100644 index 0000000000000..1f08d52a25694 --- /dev/null +++ b/x-pack/plugins/uptime/server/config.ts @@ -0,0 +1,19 @@ +/* + * 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 { PluginConfigDescriptor } from 'kibana/server'; +import { schema, TypeOf } from '@kbn/config-schema'; + +export const config: PluginConfigDescriptor = { + schema: schema.maybe( + schema.object({ + index: schema.string(), + }) + ), +}; + +export type UptimeConfig = TypeOf; diff --git a/x-pack/plugins/uptime/server/index.ts b/x-pack/plugins/uptime/server/index.ts index 4894c73c625c1..a48ae37d077f9 100644 --- a/x-pack/plugins/uptime/server/index.ts +++ b/x-pack/plugins/uptime/server/index.ts @@ -10,3 +10,5 @@ import { Plugin } from './plugin'; export const plugin = (initializerContext: PluginInitializerContext) => new Plugin(initializerContext); + +export { config } from './config'; diff --git a/x-pack/plugins/uptime/server/lib/saved_objects.ts b/x-pack/plugins/uptime/server/lib/saved_objects.ts index 3e9888df55aa0..cf5b86564a714 100644 --- a/x-pack/plugins/uptime/server/lib/saved_objects.ts +++ b/x-pack/plugins/uptime/server/lib/saved_objects.ts @@ -10,8 +10,10 @@ import { DYNAMIC_SETTINGS_DEFAULTS } from '../../common/constants'; import { DynamicSettings } from '../../common/runtime_types'; import { SavedObjectsType, SavedObjectsErrorHelpers } from '../../../../../src/core/server'; import { UMSavedObjectsQueryFn } from './adapters'; +import { UptimeConfig } from '../config'; export interface UMSavedObjectsAdapter { + config: UptimeConfig; getUptimeDynamicSettings: UMSavedObjectsQueryFn; setUptimeDynamicSettings: UMSavedObjectsQueryFn; } @@ -55,12 +57,17 @@ export const umDynamicSettings: SavedObjectsType = { }; export const savedObjectsAdapter: UMSavedObjectsAdapter = { + config: null, getUptimeDynamicSettings: async (client): Promise => { try { const obj = await client.get(umDynamicSettings.name, settingsObjectId); return obj?.attributes ?? DYNAMIC_SETTINGS_DEFAULTS; } catch (getErr) { + const config = savedObjectsAdapter.config; if (SavedObjectsErrorHelpers.isNotFoundError(getErr)) { + if (config?.index) { + return { ...DYNAMIC_SETTINGS_DEFAULTS, heartbeatIndices: config.index }; + } return DYNAMIC_SETTINGS_DEFAULTS; } throw getErr; diff --git a/x-pack/plugins/uptime/server/plugin.ts b/x-pack/plugins/uptime/server/plugin.ts index 736cbed51084c..efb613dfda826 100644 --- a/x-pack/plugins/uptime/server/plugin.ts +++ b/x-pack/plugins/uptime/server/plugin.ts @@ -16,9 +16,10 @@ import { import { uptimeRuleFieldMap } from '../common/rules/uptime_rule_field_map'; import { initServerWithKibana } from './kibana.index'; import { KibanaTelemetryAdapter, UptimeCorePlugins } from './lib/adapters'; -import { umDynamicSettings } from './lib/saved_objects'; +import { savedObjectsAdapter, umDynamicSettings } from './lib/saved_objects'; import { mappingFromFieldMap } from '../../rule_registry/common/mapping_from_field_map'; import { Dataset } from '../../rule_registry/server'; +import { UptimeConfig } from './config'; export type UptimeRuleRegistry = ReturnType['ruleRegistry']; @@ -32,6 +33,10 @@ export class Plugin implements PluginType { } public setup(core: CoreSetup, plugins: UptimeCorePlugins) { + const config = this.initContext.config.get(); + + savedObjectsAdapter.config = config; + this.logger = this.initContext.logger.get(); const { ruleDataService } = plugins.ruleRegistry;