-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Uptime] Synthetics monitor saved object (#119318)
- Loading branch information
Showing
17 changed files
with
177 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
x-pack/plugins/uptime/server/lib/saved_objects/saved_objects.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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 { | ||
SavedObjectsErrorHelpers, | ||
SavedObjectsServiceSetup, | ||
} from '../../../../../../src/core/server'; | ||
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../common/constants'; | ||
import { DynamicSettings } from '../../../common/runtime_types'; | ||
import { UMSavedObjectsQueryFn } from '../adapters'; | ||
import { UptimeConfig } from '../../config'; | ||
import { settingsObjectId, umDynamicSettings } from './uptime_settings'; | ||
import { syntheticsMonitor } from './synthetics_monitor'; | ||
|
||
export interface UMSavedObjectsAdapter { | ||
config: UptimeConfig; | ||
getUptimeDynamicSettings: UMSavedObjectsQueryFn<DynamicSettings>; | ||
setUptimeDynamicSettings: UMSavedObjectsQueryFn<void, DynamicSettings>; | ||
} | ||
|
||
export const registerUptimeSavedObjects = (savedObjectsService: SavedObjectsServiceSetup) => { | ||
savedObjectsService.registerType(umDynamicSettings); | ||
savedObjectsService.registerType(syntheticsMonitor); | ||
}; | ||
|
||
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; | ||
} | ||
}, | ||
setUptimeDynamicSettings: async (client, settings): Promise<void> => { | ||
await client.create(umDynamicSettings.name, settings, { | ||
id: settingsObjectId, | ||
overwrite: true, | ||
}); | ||
}, | ||
}; |
47 changes: 47 additions & 0 deletions
47
x-pack/plugins/uptime/server/lib/saved_objects/synthetics_monitor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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 { SavedObjectsType } from 'kibana/server'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const syntheticsMonitorType = 'synthetics-monitor'; | ||
|
||
export const syntheticsMonitor: SavedObjectsType = { | ||
name: syntheticsMonitorType, | ||
hidden: false, | ||
namespaceType: 'single', | ||
mappings: { | ||
dynamic: false, | ||
properties: { | ||
name: { | ||
type: 'keyword', | ||
}, | ||
id: { | ||
type: 'keyword', | ||
}, | ||
type: { | ||
type: 'keyword', | ||
}, | ||
urls: { | ||
type: 'keyword', | ||
}, | ||
tags: { | ||
type: 'keyword', | ||
}, | ||
}, | ||
}, | ||
management: { | ||
importableAndExportable: true, | ||
icon: 'uptimeApp', | ||
getTitle: (savedObject) => | ||
savedObject.attributes.name + | ||
' - ' + | ||
i18n.translate('xpack.uptime.syntheticsMonitors', { | ||
defaultMessage: 'Uptime - Monitor', | ||
}), | ||
}, | ||
}; |
46 changes: 46 additions & 0 deletions
46
x-pack/plugins/uptime/server/lib/saved_objects/uptime_settings.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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 { SavedObjectsType } from 'kibana/server'; | ||
import { i18n } from '@kbn/i18n'; | ||
export const settingsObjectType = 'uptime-dynamic-settings'; | ||
export const settingsObjectId = 'uptime-dynamic-settings-singleton'; | ||
|
||
export const umDynamicSettings: SavedObjectsType = { | ||
name: settingsObjectType, | ||
hidden: false, | ||
namespaceType: 'single', | ||
mappings: { | ||
dynamic: false, | ||
properties: { | ||
/* Leaving these commented to make it clear that these fields exist, even though we don't want them indexed. | ||
When adding new fields please add them here. If they need to be searchable put them in the uncommented | ||
part of properties. | ||
heartbeatIndices: { | ||
type: 'keyword', | ||
}, | ||
certAgeThreshold: { | ||
type: 'long', | ||
}, | ||
certExpirationThreshold: { | ||
type: 'long', | ||
}, | ||
defaultConnectors: { | ||
type: 'keyword', | ||
}, | ||
*/ | ||
}, | ||
}, | ||
management: { | ||
importableAndExportable: true, | ||
icon: 'uptimeApp', | ||
getTitle: () => | ||
i18n.translate('xpack.uptime.uptimeSettings.index', { | ||
defaultMessage: 'Uptime Settings - Index', | ||
}), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters