Skip to content

Commit

Permalink
[Uptime] Uptime index config using kibana.yml (elastic#115775)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
shahzad31 and kibanamachine committed Oct 27, 2021
1 parent 696825f commit 92cafad
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ kibana_vars=(
xpack.task_manager.poll_interval
xpack.task_manager.request_capacity
xpack.task_manager.version_conflict_threshold
xpack.uptime.index
)

longopts=''
Expand Down
19 changes: 19 additions & 0 deletions x-pack/plugins/uptime/server/config.ts
Original file line number Diff line number Diff line change
@@ -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<typeof config.schema>;
2 changes: 2 additions & 0 deletions x-pack/plugins/uptime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ import { Plugin } from './plugin';

export const plugin = (initializerContext: PluginInitializerContext) =>
new Plugin(initializerContext);

export { config } from './config';
7 changes: 7 additions & 0 deletions x-pack/plugins/uptime/server/lib/saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DynamicSettings>;
setUptimeDynamicSettings: UMSavedObjectsQueryFn<void, DynamicSettings>;
}
Expand Down Expand Up @@ -55,12 +57,17 @@ export const umDynamicSettings: SavedObjectsType = {
};

export const savedObjectsAdapter: UMSavedObjectsAdapter = {
config: null,
getUptimeDynamicSettings: async (client): Promise<DynamicSettings> => {
try {
const obj = await client.get<DynamicSettings>(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;
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/uptime/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Plugin['setup']>['ruleRegistry'];

Expand All @@ -32,6 +33,10 @@ export class Plugin implements PluginType {
}

public setup(core: CoreSetup, plugins: UptimeCorePlugins) {
const config = this.initContext.config.get<UptimeConfig>();

savedObjectsAdapter.config = config;

this.logger = this.initContext.logger.get();
const { ruleDataService } = plugins.ruleRegistry;

Expand Down

0 comments on commit 92cafad

Please sign in to comment.