From 43cce3178ede41449ad42a5362601d71ed4b6b86 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 24 Oct 2022 12:41:04 -0400 Subject: [PATCH 01/34] synthetics - add monitor id migration --- .../common/constants/monitor_defaults.ts | 2 - .../common/formatters/common/formatters.ts | 2 - .../fleet_package/common/normalizers.ts | 2 - .../legacy_uptime/lib/requests/get_monitor.ts | 4 +- .../migrations/monitors/8.6.0.test.ts | 193 ++++++++++++++++++ .../migrations/monitors/8.6.0.ts | 31 +++ .../migrations/monitors/index.ts | 12 ++ .../lib/saved_objects/saved_objects.ts | 6 +- .../lib/saved_objects/synthetics_monitor.ts | 152 +++++++------- .../routes/monitor_cruds/delete_monitor.ts | 7 +- .../routes/monitor_cruds/edit_monitor.ts | 7 +- .../synthetics_service/test_now_monitor.ts | 7 +- .../synthetics_service/formatters/common.ts | 2 - .../normalizers/browser_monitor.ts | 2 +- .../project_monitor_formatter.ts | 7 +- .../synthetics_service/synthetics_service.ts | 7 +- 16 files changed, 332 insertions(+), 111 deletions(-) create mode 100644 x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts create mode 100644 x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts create mode 100644 x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/index.ts diff --git a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts index 9f40d49d7086b4..9426e498879ab0 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts @@ -48,8 +48,6 @@ export const DEFAULT_COMMON_FIELDS: CommonFields = { [ConfigKey.MONITOR_SOURCE_TYPE]: SourceType.UI, [ConfigKey.JOURNEY_ID]: '', [ConfigKey.CONFIG_HASH]: '', - - // Deprecated, slated to be removed in a future version [ConfigKey.ID]: '', }; diff --git a/x-pack/plugins/synthetics/common/formatters/common/formatters.ts b/x-pack/plugins/synthetics/common/formatters/common/formatters.ts index ab7c3bc9cfa29c..619adfce73e74d 100644 --- a/x-pack/plugins/synthetics/common/formatters/common/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/common/formatters.ts @@ -33,8 +33,6 @@ export const commonFormatters: CommonFormatMap = { [ConfigKey.CUSTOM_HEARTBEAT_ID]: null, [ConfigKey.ORIGINAL_SPACE]: null, [ConfigKey.CONFIG_HASH]: null, - - // Deprecated, slated to be removed in a later release [ConfigKey.ID]: null, }; diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts index f4678b55698725..0f6b1f465a9a3a 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts @@ -97,7 +97,5 @@ export const commonNormalizers: CommonNormalizerMap = { [ConfigKey.CUSTOM_HEARTBEAT_ID]: getCommonNormalizer(ConfigKey.CUSTOM_HEARTBEAT_ID), [ConfigKey.ORIGINAL_SPACE]: getCommonNormalizer(ConfigKey.ORIGINAL_SPACE), [ConfigKey.CONFIG_HASH]: getCommonNormalizer(ConfigKey.CONFIG_HASH), - - // Deprecated, slated to be removed in a future release [ConfigKey.ID]: getCommonNormalizer(ConfigKey.ID), }; diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/requests/get_monitor.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/requests/get_monitor.ts index 9b92463f78641c..c085e5c7d7158e 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/requests/get_monitor.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/requests/get_monitor.ts @@ -12,7 +12,7 @@ import { EncryptedSyntheticsMonitor, SyntheticsMonitor, } from '../../../../common/runtime_types'; -import { syntheticsMonitor, syntheticsMonitorType } from '../saved_objects/synthetics_monitor'; +import { syntheticsMonitorType } from '../saved_objects/synthetics_monitor'; import { normalizeSecrets } from '../../../synthetics_service/utils/secrets'; export const getSyntheticsMonitor = async ({ @@ -32,7 +32,7 @@ export const getSyntheticsMonitor = async ({ const decryptedMonitor = await encryptedSavedObjectsClient.getDecryptedAsInternalUser( - syntheticsMonitor.name, + syntheticsMonitorType, monitorId, { namespace: encryptedMonitor.namespaces?.[0], diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts new file mode 100644 index 00000000000000..26fc393206fa13 --- /dev/null +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts @@ -0,0 +1,193 @@ +/* + * 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 { encryptedSavedObjectsMock } from '@kbn/encrypted-saved-objects-plugin/server/mocks'; +import { migration860 } from './8.6.0'; +import { migrationMocks } from '@kbn/core/server/mocks'; +import { ConfigKey } from '../../../../../../common/runtime_types'; + +const context = migrationMocks.createContext(); +const encryptedSavedObjectsSetup = encryptedSavedObjectsMock.createSetup(); + +const monitor850UI = { + id: 'ac38d021-515b-425c-9f92-e6212dadef9a', + type: 'synthetics-monitor', + namespaces: ['default'], + updated_at: '2022-10-24T14:17:01.875Z', + version: 'WzgzOCwyQr==', + attributes: { + type: 'http', + form_monitor_type: 'http', + enabled: true, + schedule: { number: '3', unit: 'm' }, + 'service.name': '', + config_id: '', + tags: [], + timeout: '16', + name: 'Dominique Clarke', + locations: [{ id: 'us_central', isServiceManaged: true }], + namespace: 'default', + origin: 'ui', + journey_id: '', + id: '', + __ui: { is_tls_enabled: false, is_zip_url_tls_enabled: false }, + urls: 'https://elastic.co', + max_redirects: '0', + 'url.port': null, + proxy_url: '', + 'response.include_body': 'on_error', + 'response.include_headers': true, + 'check.response.status': [], + 'check.request.method': 'GET', + 'ssl.certificate_authorities': '', + 'ssl.certificate': '', + 'ssl.verification_mode': 'full', + 'ssl.supported_protocols': ['TLSv1.1', 'TLSv1.2', 'TLSv1.3'], + revision: 1, + secrets: + '{"password":"","check.request.body":{"type":"text","value":""},"check.request.headers":{},"check.response.body.negative":[],"check.response.body.positive":[],"check.response.headers":{},"ssl.key":"","ssl.key_passphrase":"","username":""}', + }, + references: [], + coreMigrationVersion: '8.5.0', +}; + +const monitor850Project = { + id: '3ab5c90f-aa7f-4370-ada2-b559191398f0', + type: 'synthetics-monitor', + namespaces: ['default'], + updated_at: '2022-10-24T15:39:41.510Z', + version: 'WzE2OSwxXQ==', + attributes: { + type: 'browser', + form_monitor_type: 'multistep', + enabled: true, + schedule: { number: '3', unit: 'm' }, + 'service.name': '', + config_id: '', + tags: [], + timeout: null, + name: 'a', + locations: [ + { + id: 'us_central', + label: 'North America - US Central', + geo: { lat: 41.25, lon: -95.86 }, + url: 'https://us-central.synthetics.elastic.dev', + isServiceManaged: true, + status: 'beta', + isInvalid: false, + }, + ], + namespace: 'default', + origin: 'project', + journey_id: 'a', + id: '', + project_id: 'test2', + playwright_options: '{"ignoreHTTPSErrors":true,"headless":true}', + __ui: { + script_source: { is_generated_script: false, file_name: '' }, + is_zip_url_tls_enabled: false, + }, + 'url.port': null, + 'source.zip_url.url': '', + 'source.zip_url.folder': '', + 'source.zip_url.proxy_url': '', + playwright_text_assertion: '', + urls: '', + screenshots: 'on', + 'filter_journeys.match': 'a', + 'filter_journeys.tags': [], + ignore_https_errors: false, + 'throttling.is_enabled': true, + 'throttling.download_speed': '10', + 'throttling.upload_speed': '5', + 'throttling.latency': '10', + 'throttling.config': '10d/5u/10l', + 'ssl.certificate_authorities': '', + 'ssl.certificate': '', + 'ssl.verification_mode': 'full', + 'ssl.supported_protocols': ['TLSv1.1', 'TLSv1.2', 'TLSv1.3'], + original_space: 'default', + custom_heartbeat_id: 'a-test2-default', + revision: 1, + secrets: + '{"params":"{\\"url\\":\\"https://elastic.github.io/synthetics-demo/\\"}","source.inline.script":"","source.project.content":"UEsDBBQACAAIAAAAIQAAAAAAAAAAAAAAAAAXAAAAam91cm5leXMvb25lLmpvdXJuZXkudHNVkL1uwzAMhHc/BeFJAQyrLdAlQYouXbp3KjqwMhMrlUVVohMYgd+9in+AdCHED6c7kloDpkSy1R+JYtINd9bb356Mw/hDuqGzToOXlsSapIWSPOkT99HTkDR7qpemllTYLnAUuMLCKkhCoYKOvRWOMMIhcgflKzlM2e/OudwVZ4xgIqHQ+/wd9qA8drSB/QtcC1h96j6RuvUA0kYWcdYftzATgIYv3jE2W3h8qBbWh5k8r8DlGG+Gm2YiY67jZpfrMvuUXIG6QsBjfgSM2KWsWYeBaTlVOuy9aQFDcNagWPZllW86eAPqTgyAF7QyudVHFlazY91HN+Wu+bc67orPErNP+V1+1QeOb2hapXDy+3ejzLL+D1BLBwgqc7lrFgEAAMYBAABQSwECLQMUAAgACAAAACEAKnO5axYBAADGAQAAFwAAAAAAAAAAACAApIEAAAAAam91cm5leXMvb25lLmpvdXJuZXkudHNQSwUGAAAAAAEAAQBFAAAAWwEAAAAA","source.zip_url.username":"","source.zip_url.password":"","synthetics_args":[],"ssl.key":"","ssl.key_passphrase":""}', + }, + references: [], + coreMigrationVersion: '8.5.0', +}; + +describe('Case migrations v8.5.0 -> v8.6.0', () => { + beforeEach(() => { + jest.resetAllMocks(); + encryptedSavedObjectsSetup.createMigration.mockImplementation(({ migration }) => migration); + }); + + it('UI monitors - adds saved object id to the id field', () => { + expect(migration860(encryptedSavedObjectsSetup)(monitor850UI)).toEqual({ + ...monitor850UI, + attributes: { + ...monitor850UI.attributes, + [ConfigKey.ID]: monitor850UI.id, + }, + }); + }); + + it('project monitors - adds custom heartbeat id to id field', () => { + expect(migration860(encryptedSavedObjectsSetup)(monitor850Project)).toEqual({ + ...monitor850Project, + attributes: { + ...monitor850Project.attributes, + [ConfigKey.ID]: monitor850Project.attributes[ConfigKey.CUSTOM_HEARTBEAT_ID], + }, + }); + }); + + it('handles empty custom heartbeat id string', () => { + expect( + migration860(encryptedSavedObjectsSetup)({ + ...monitor850UI, + attributes: { ...monitor850UI.attributes, [ConfigKey.CUSTOM_HEARTBEAT_ID]: '' }, + }) + ).toEqual({ + ...monitor850UI, + attributes: { + ...monitor850UI.attributes, + [ConfigKey.ID]: monitor850UI.id, + }, + }); + }); + + it('handles null custom heartbeat id string', () => { + expect( + migration860(encryptedSavedObjectsSetup)({ + ...monitor850UI, + attributes: { ...monitor850UI.attributes, [ConfigKey.CUSTOM_HEARTBEAT_ID]: null }, + }) + ).toEqual({ + ...monitor850UI, + attributes: { + ...monitor850UI.attributes, + [ConfigKey.ID]: monitor850UI.id, + }, + }); + }); + + it('handles undefined custom heartbeat id string', () => { + expect( + migration860(encryptedSavedObjectsSetup)({ + ...monitor850UI, + attributes: { ...monitor850UI.attributes, [ConfigKey.CUSTOM_HEARTBEAT_ID]: undefined }, + }) + ).toEqual({ + ...monitor850UI, + attributes: { + ...monitor850UI.attributes, + [ConfigKey.ID]: monitor850UI.id, + }, + }); + }); +}); diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts new file mode 100644 index 00000000000000..a472e0c5297f79 --- /dev/null +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts @@ -0,0 +1,31 @@ +/* + * 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 { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server'; +import { SavedObjectUnsanitizedDoc } from '@kbn/core/server'; +import { ConfigKey, SyntheticsMonitor } from '../../../../../../common/runtime_types'; + +export const migration860 = (encryptedSavedObjects: EncryptedSavedObjectsPluginSetup) => { + return encryptedSavedObjects.createMigration({ + isMigrationNeededPredicate: function shouldBeMigrated( + doc + ): doc is SavedObjectUnsanitizedDoc { + return true; + }, + migration: ( + doc: SavedObjectUnsanitizedDoc + ): SavedObjectUnsanitizedDoc => { + const { attributes, id } = doc; + return { + ...doc, + attributes: { + ...attributes, + [ConfigKey.ID]: attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, + }, + }; + }, + }); +}; diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/index.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/index.ts new file mode 100644 index 00000000000000..14e2c2a76619fa --- /dev/null +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/index.ts @@ -0,0 +1,12 @@ +/* + * 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 { migrate860 } from './8.6.0'; + +export const monitorMigrations = { + '8.6.0': migrate860, +}; diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/saved_objects.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/saved_objects.ts index 0a06d1926a8552..24d3cc03b6ca20 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/saved_objects.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/saved_objects.ts @@ -15,7 +15,7 @@ import { DynamicSettings } from '../../../../common/runtime_types'; import { UMSavedObjectsQueryFn } from '../adapters'; import { UptimeConfig } from '../../../../common/config'; import { settingsObjectId, umDynamicSettings } from './uptime_settings'; -import { syntheticsMonitor } from './synthetics_monitor'; +import { syntheticsMonitorType, getSyntheticsMonitorSavedObjectType } from './synthetics_monitor'; import { syntheticsServiceApiKey } from './service_api_key'; export const registerUptimeSavedObjects = ( @@ -25,7 +25,7 @@ export const registerUptimeSavedObjects = ( savedObjectsService.registerType(umDynamicSettings); savedObjectsService.registerType(privateLocationsSavedObject); - savedObjectsService.registerType(syntheticsMonitor); + savedObjectsService.registerType(getSyntheticsMonitorSavedObjectType(encryptedSavedObjects)); savedObjectsService.registerType(syntheticsServiceApiKey); encryptedSavedObjects.registerType({ @@ -34,7 +34,7 @@ export const registerUptimeSavedObjects = ( }); encryptedSavedObjects.registerType({ - type: syntheticsMonitor.name, + type: syntheticsMonitorType, attributesToEncrypt: new Set([ 'secrets', /* adding secretKeys to the list of attributes to encrypt ensures diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/synthetics_monitor.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/synthetics_monitor.ts index 94a8a0085e1706..72715091c06de1 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/synthetics_monitor.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/synthetics_monitor.ts @@ -4,95 +4,103 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - +import { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server'; import { SavedObjectsType } from '@kbn/core/server'; import { i18n } from '@kbn/i18n'; +import { monitorMigrations } from './migrations/monitors'; export const syntheticsMonitorType = 'synthetics-monitor'; -export const syntheticsMonitor: SavedObjectsType = { - name: syntheticsMonitorType, - hidden: false, - namespaceType: 'single', - mappings: { - dynamic: false, - properties: { - name: { - type: 'text', - fields: { - keyword: { - type: 'keyword', - ignore_above: 256, - normalizer: 'lowercase', +export const getSyntheticsMonitorSavedObjectType = ( + encryptedSavedObjects: EncryptedSavedObjectsPluginSetup +): SavedObjectsType => { + return { + name: syntheticsMonitorType, + hidden: false, + namespaceType: 'single', + migrations: { + '8.6.0': monitorMigrations['8.6.0'](encryptedSavedObjects), + }, + mappings: { + dynamic: false, + properties: { + name: { + type: 'text', + fields: { + keyword: { + type: 'keyword', + ignore_above: 256, + normalizer: 'lowercase', + }, }, }, - }, - type: { - type: 'text', - fields: { - keyword: { - type: 'keyword', - ignore_above: 256, + type: { + type: 'text', + fields: { + keyword: { + type: 'keyword', + ignore_above: 256, + }, }, }, - }, - urls: { - type: 'text', - fields: { - keyword: { - type: 'keyword', - ignore_above: 256, + urls: { + type: 'text', + fields: { + keyword: { + type: 'keyword', + ignore_above: 256, + }, }, }, - }, - journey_id: { - type: 'keyword', - }, - project_id: { - type: 'keyword', - }, - origin: { - type: 'keyword', - }, - hash: { - type: 'keyword', - }, - locations: { - properties: { - id: { - type: 'keyword', - ignore_above: 256, - fields: { - text: { - type: 'text', + journey_id: { + type: 'keyword', + }, + project_id: { + type: 'keyword', + }, + origin: { + type: 'keyword', + }, + hash: { + type: 'keyword', + }, + locations: { + properties: { + id: { + type: 'keyword', + ignore_above: 256, + fields: { + text: { + type: 'text', + }, }, }, }, }, - }, - custom_heartbeat_id: { - type: 'keyword', - }, - tags: { - type: 'keyword', - }, - schedule: { - properties: { - number: { - type: 'integer', + custom_heartbeat_id: { + type: 'keyword', + }, + tags: { + type: 'keyword', + }, + schedule: { + properties: { + number: { + type: 'integer', + }, }, }, }, }, - }, - management: { - importableAndExportable: false, - icon: 'uptimeApp', - getTitle: (savedObject) => - savedObject.attributes.name + - ' - ' + - i18n.translate('xpack.synthetics.syntheticsMonitors', { - defaultMessage: 'Uptime - Monitor', - }), - }, + management: { + importableAndExportable: false, + icon: 'uptimeApp', + getTitle: (savedObject) => + savedObject.attributes.name + + ' - ' + + i18n.translate('xpack.synthetics.syntheticsMonitors', { + defaultMessage: 'Uptime - Monitor', + }), + }, + }; }; diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/delete_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/delete_monitor.ts index de1b0b90ef95cc..9524d504f85c53 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/delete_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/delete_monitor.ts @@ -19,10 +19,7 @@ import { } from '../../../common/runtime_types'; import { SyntheticsRestApiRouteFactory } from '../../legacy_uptime/routes/types'; import { API_URLS } from '../../../common/constants'; -import { - syntheticsMonitorType, - syntheticsMonitor, -} from '../../legacy_uptime/lib/saved_objects/synthetics_monitor'; +import { syntheticsMonitorType } from '../../legacy_uptime/lib/saved_objects/synthetics_monitor'; import { getMonitorNotFoundResponse } from '../synthetics_service/service_errors'; import { sendTelemetryEvents, @@ -100,7 +97,7 @@ export const deleteMonitor = async ({ const monitor = await encryptedSavedObjectsClient.getDecryptedAsInternalUser( - syntheticsMonitor.name, + syntheticsMonitorType, monitorId, { namespace: encryptedMonitor.namespaces?.[0], diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts index d6b50880ed3509..6289fba1f7b019 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts @@ -24,10 +24,7 @@ import { } from '../../../common/runtime_types'; import { SyntheticsRestApiRouteFactory } from '../../legacy_uptime/routes/types'; import { API_URLS } from '../../../common/constants'; -import { - syntheticsMonitorType, - syntheticsMonitor, -} from '../../legacy_uptime/lib/saved_objects/synthetics_monitor'; +import { syntheticsMonitorType } from '../../legacy_uptime/lib/saved_objects/synthetics_monitor'; import { validateMonitor } from './monitor_validation'; import { getMonitorNotFoundResponse } from '../synthetics_service/service_errors'; import { @@ -72,7 +69,7 @@ export const editSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () => ( * on the monitor list table. We do not decrypt monitors in bulk for the monitor list table */ const decryptedPreviousMonitor = await encryptedSavedObjectsClient.getDecryptedAsInternalUser( - syntheticsMonitor.name, + syntheticsMonitorType, monitorId, { namespace: previousMonitor.namespaces?.[0], diff --git a/x-pack/plugins/synthetics/server/routes/synthetics_service/test_now_monitor.ts b/x-pack/plugins/synthetics/server/routes/synthetics_service/test_now_monitor.ts index 0a2c3f599ff622..1c6d6548c575d1 100644 --- a/x-pack/plugins/synthetics/server/routes/synthetics_service/test_now_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/synthetics_service/test_now_monitor.ts @@ -14,10 +14,7 @@ import { } from '../../../common/runtime_types'; import { SyntheticsRestApiRouteFactory } from '../../legacy_uptime/routes/types'; import { API_URLS } from '../../../common/constants'; -import { - syntheticsMonitor, - syntheticsMonitorType, -} from '../../legacy_uptime/lib/saved_objects/synthetics_monitor'; +import { syntheticsMonitorType } from '../../legacy_uptime/lib/saved_objects/synthetics_monitor'; import { formatHeartbeatRequest } from '../../synthetics_service/formatters/format_configs'; import { normalizeSecrets } from '../../synthetics_service/utils/secrets'; @@ -45,7 +42,7 @@ export const testNowMonitorRoute: SyntheticsRestApiRouteFactory = () => ({ const monitorWithSecrets = await encryptedClient.getDecryptedAsInternalUser( - syntheticsMonitor.name, + syntheticsMonitorType, monitorId ); const normalizedMonitor = normalizeSecrets(monitorWithSecrets); diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts index f88f23ca380374..f45f04cbc986b5 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts @@ -35,8 +35,6 @@ export const commonFormatters: CommonFormatMap = { [ConfigKey.CUSTOM_HEARTBEAT_ID]: null, [ConfigKey.ORIGINAL_SPACE]: null, [ConfigKey.CONFIG_HASH]: null, - - // Deprecated, slated to be removed in a later releae [ConfigKey.ID]: null, }; diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/browser_monitor.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/browser_monitor.ts index 8eba2cd2651db3..778a801e3a00cd 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/browser_monitor.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/browser_monitor.ts @@ -54,7 +54,7 @@ export const getNormalizeBrowserFields = ({ monitor.throttling?.upload || defaultFields[ConfigKey.UPLOAD_SPEED] }`, [ConfigKey.IS_THROTTLING_ENABLED]: - Boolean(monitor.throttling) || defaultFields[ConfigKey.IS_THROTTLING_ENABLED], + Boolean(monitor.throttling) ?? defaultFields[ConfigKey.IS_THROTTLING_ENABLED], [ConfigKey.LATENCY]: `${monitor.throttling?.latency || defaultFields[ConfigKey.LATENCY]}`, [ConfigKey.IGNORE_HTTPS_ERRORS]: monitor.ignoreHTTPSErrors || defaultFields[ConfigKey.IGNORE_HTTPS_ERRORS], diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts index 6139b2fbe7959b..1c69c10552dd53 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts @@ -30,10 +30,7 @@ import { MonitorFields, PrivateLocation, } from '../../../common/runtime_types'; -import { - syntheticsMonitorType, - syntheticsMonitor, -} from '../../legacy_uptime/lib/saved_objects/synthetics_monitor'; +import { syntheticsMonitorType } from '../../legacy_uptime/lib/saved_objects/synthetics_monitor'; import type { UptimeServerSetup } from '../../legacy_uptime/lib/adapters'; import { formatSecrets, normalizeSecrets } from '../utils/secrets'; import { @@ -347,7 +344,7 @@ export class ProjectMonitorFormatter { monitors, async (monitor) => this.encryptedSavedObjectsClient.getDecryptedAsInternalUser( - syntheticsMonitor.name, + syntheticsMonitorType, monitor.id, { namespace: monitor.namespaces?.[0], diff --git a/x-pack/plugins/synthetics/server/synthetics_service/synthetics_service.ts b/x-pack/plugins/synthetics/server/synthetics_service/synthetics_service.ts index 457d4e79e418ea..f4d505de5baac5 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/synthetics_service.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/synthetics_service.ts @@ -21,10 +21,7 @@ import { UptimeServerSetup } from '../legacy_uptime/lib/adapters'; import { installSyntheticsIndexTemplates } from '../routes/synthetics_service/install_index_templates'; import { SyntheticsServiceApiKey } from '../../common/runtime_types/synthetics_service_api_key'; import { getAPIKeyForSyntheticsService } from './get_api_key'; -import { - syntheticsMonitorType, - syntheticsMonitor, -} from '../legacy_uptime/lib/saved_objects/synthetics_monitor'; +import { syntheticsMonitorType } from '../legacy_uptime/lib/saved_objects/synthetics_monitor'; import { getEsHosts } from './get_es_hosts'; import { ServiceConfig } from '../../common/config'; import { ServiceAPIClient } from './service_api_client'; @@ -422,7 +419,7 @@ export class SyntheticsService { new Promise((resolve) => { encryptedClient .getDecryptedAsInternalUser( - syntheticsMonitor.name, + syntheticsMonitorType, monitor.id, { namespace: monitor.namespaces?.[0], From 9bf96f9dfd30079d0e936a708a6c078c473b11a4 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 24 Oct 2022 13:00:33 -0400 Subject: [PATCH 02/34] add id to all monitors --- .../synthetics/server/routes/monitor_cruds/add_monitor.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts index 1f9a55e3476188..34bde8957df090 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts @@ -118,7 +118,7 @@ export const createNewSavedObjectMonitor = async ({ savedObjectsClient, normalizedMonitor, }: { - id?: string; + id: string; savedObjectsClient: SavedObjectsClientContract; normalizedMonitor: SyntheticsMonitor; }) => { @@ -126,6 +126,8 @@ export const createNewSavedObjectMonitor = async ({ syntheticsMonitorType, formatSecrets({ ...normalizedMonitor, + [ConfigKey.ID]: normalizedMonitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, + [ConfigKey.CONFIG_ID]: id, revision: 1, }), id From 508278a00120f33e938ed5ff1e8e6f23d76eaebe Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 24 Oct 2022 13:24:14 -0400 Subject: [PATCH 03/34] add config id to migration --- .../migrations/monitors/8.6.0.test.ts | 61 ++++++++++++------- .../migrations/monitors/8.6.0.ts | 14 +++-- 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts index 26fc393206fa13..0fc846124b2cd3 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts @@ -7,7 +7,7 @@ import { encryptedSavedObjectsMock } from '@kbn/encrypted-saved-objects-plugin/server/mocks'; import { migration860 } from './8.6.0'; import { migrationMocks } from '@kbn/core/server/mocks'; -import { ConfigKey } from '../../../../../../common/runtime_types'; +import { ConfigKey, SyntheticsMonitorWithSecrets } from '../../../../../../common/runtime_types'; const context = migrationMocks.createContext(); const encryptedSavedObjectsSetup = encryptedSavedObjectsMock.createSetup(); @@ -49,7 +49,7 @@ const monitor850UI = { revision: 1, secrets: '{"password":"","check.request.body":{"type":"text","value":""},"check.request.headers":{},"check.response.body.negative":[],"check.response.body.positive":[],"check.response.headers":{},"ssl.key":"","ssl.key_passphrase":"","username":""}', - }, + } as SyntheticsMonitorWithSecrets, references: [], coreMigrationVersion: '8.5.0', }; @@ -77,7 +77,7 @@ const monitor850Project = { geo: { lat: 41.25, lon: -95.86 }, url: 'https://us-central.synthetics.elastic.dev', isServiceManaged: true, - status: 'beta', + status: 'ga', isInvalid: false, }, ], @@ -115,7 +115,7 @@ const monitor850Project = { revision: 1, secrets: '{"params":"{\\"url\\":\\"https://elastic.github.io/synthetics-demo/\\"}","source.inline.script":"","source.project.content":"UEsDBBQACAAIAAAAIQAAAAAAAAAAAAAAAAAXAAAAam91cm5leXMvb25lLmpvdXJuZXkudHNVkL1uwzAMhHc/BeFJAQyrLdAlQYouXbp3KjqwMhMrlUVVohMYgd+9in+AdCHED6c7kloDpkSy1R+JYtINd9bb356Mw/hDuqGzToOXlsSapIWSPOkT99HTkDR7qpemllTYLnAUuMLCKkhCoYKOvRWOMMIhcgflKzlM2e/OudwVZ4xgIqHQ+/wd9qA8drSB/QtcC1h96j6RuvUA0kYWcdYftzATgIYv3jE2W3h8qBbWh5k8r8DlGG+Gm2YiY67jZpfrMvuUXIG6QsBjfgSM2KWsWYeBaTlVOuy9aQFDcNagWPZllW86eAPqTgyAF7QyudVHFlazY91HN+Wu+bc67orPErNP+V1+1QeOb2hapXDy+3ejzLL+D1BLBwgqc7lrFgEAAMYBAABQSwECLQMUAAgACAAAACEAKnO5axYBAADGAQAAFwAAAAAAAAAAACAApIEAAAAAam91cm5leXMvb25lLmpvdXJuZXkudHNQSwUGAAAAAAEAAQBFAAAAWwEAAAAA","source.zip_url.username":"","source.zip_url.password":"","synthetics_args":[],"ssl.key":"","ssl.key_passphrase":""}', - }, + } as SyntheticsMonitorWithSecrets, references: [], coreMigrationVersion: '8.5.0', }; @@ -127,66 +127,85 @@ describe('Case migrations v8.5.0 -> v8.6.0', () => { }); it('UI monitors - adds saved object id to the id field', () => { - expect(migration860(encryptedSavedObjectsSetup)(monitor850UI)).toEqual({ + expect(migration860(encryptedSavedObjectsSetup)(monitor850UI, context)).toEqual({ ...monitor850UI, attributes: { ...monitor850UI.attributes, [ConfigKey.ID]: monitor850UI.id, + [ConfigKey.CONFIG_ID]: monitor850UI.id, }, }); }); it('project monitors - adds custom heartbeat id to id field', () => { - expect(migration860(encryptedSavedObjectsSetup)(monitor850Project)).toEqual({ + expect(migration860(encryptedSavedObjectsSetup)(monitor850Project, context)).toEqual({ ...monitor850Project, attributes: { ...monitor850Project.attributes, [ConfigKey.ID]: monitor850Project.attributes[ConfigKey.CUSTOM_HEARTBEAT_ID], + [ConfigKey.CONFIG_ID]: monitor850Project.id, }, }); }); it('handles empty custom heartbeat id string', () => { + const attributes = { ...monitor850UI.attributes, [ConfigKey.CUSTOM_HEARTBEAT_ID]: '' }; expect( - migration860(encryptedSavedObjectsSetup)({ - ...monitor850UI, - attributes: { ...monitor850UI.attributes, [ConfigKey.CUSTOM_HEARTBEAT_ID]: '' }, - }) + migration860(encryptedSavedObjectsSetup)( + { + ...monitor850UI, + attributes, + }, + context + ) ).toEqual({ ...monitor850UI, attributes: { - ...monitor850UI.attributes, + ...attributes, [ConfigKey.ID]: monitor850UI.id, + [ConfigKey.CONFIG_ID]: monitor850UI.id, }, }); }); it('handles null custom heartbeat id string', () => { + const attributes = { ...monitor850UI.attributes, [ConfigKey.CUSTOM_HEARTBEAT_ID]: null }; + expect( - migration860(encryptedSavedObjectsSetup)({ - ...monitor850UI, - attributes: { ...monitor850UI.attributes, [ConfigKey.CUSTOM_HEARTBEAT_ID]: null }, - }) + migration860(encryptedSavedObjectsSetup)( + { + ...monitor850UI, + // @ts-ignore + attributes, + }, + context + ) ).toEqual({ ...monitor850UI, attributes: { - ...monitor850UI.attributes, + ...attributes, [ConfigKey.ID]: monitor850UI.id, + [ConfigKey.CONFIG_ID]: monitor850UI.id, }, }); }); it('handles undefined custom heartbeat id string', () => { + const attributes = { ...monitor850UI.attributes, [ConfigKey.CUSTOM_HEARTBEAT_ID]: undefined }; expect( - migration860(encryptedSavedObjectsSetup)({ - ...monitor850UI, - attributes: { ...monitor850UI.attributes, [ConfigKey.CUSTOM_HEARTBEAT_ID]: undefined }, - }) + migration860(encryptedSavedObjectsSetup)( + { + ...monitor850UI, + attributes, + }, + context + ) ).toEqual({ ...monitor850UI, attributes: { - ...monitor850UI.attributes, + ...attributes, [ConfigKey.ID]: monitor850UI.id, + [ConfigKey.CONFIG_ID]: monitor850UI.id, }, }); }); diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts index a472e0c5297f79..a8ef0b16dac4f3 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts @@ -6,24 +6,28 @@ */ import { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server'; import { SavedObjectUnsanitizedDoc } from '@kbn/core/server'; -import { ConfigKey, SyntheticsMonitor } from '../../../../../../common/runtime_types'; +import { ConfigKey, SyntheticsMonitorWithSecrets } from '../../../../../../common/runtime_types'; export const migration860 = (encryptedSavedObjects: EncryptedSavedObjectsPluginSetup) => { - return encryptedSavedObjects.createMigration({ + return encryptedSavedObjects.createMigration< + SyntheticsMonitorWithSecrets, + SyntheticsMonitorWithSecrets + >({ isMigrationNeededPredicate: function shouldBeMigrated( doc - ): doc is SavedObjectUnsanitizedDoc { + ): doc is SavedObjectUnsanitizedDoc { return true; }, migration: ( - doc: SavedObjectUnsanitizedDoc - ): SavedObjectUnsanitizedDoc => { + doc: SavedObjectUnsanitizedDoc + ): SavedObjectUnsanitizedDoc => { const { attributes, id } = doc; return { ...doc, attributes: { ...attributes, [ConfigKey.ID]: attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, + [ConfigKey.CONFIG_ID]: id, }, }; }, From 06a0434c80c9843fefb4229ad6e9b91ff01509a8 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 24 Oct 2022 13:33:59 -0400 Subject: [PATCH 04/34] adjust import --- .../lib/saved_objects/migrations/monitors/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/index.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/index.ts index 14e2c2a76619fa..bb26f51a603e68 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/index.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/index.ts @@ -5,8 +5,8 @@ * 2.0. */ -import { migrate860 } from './8.6.0'; +import { migration860 } from './8.6.0'; export const monitorMigrations = { - '8.6.0': migrate860, + '8.6.0': migration860, }; From 56c8e44bdac11fc72be4ff5a1aab791868c76f9a Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 25 Oct 2022 14:44:21 -0400 Subject: [PATCH 05/34] update tests --- .../routes/monitor_cruds/add_monitor.ts | 6 +-- .../bulk_cruds/add_monitor_bulk.ts | 2 + .../apis/uptime/rest/add_monitor.ts | 13 +++++- .../apis/uptime/rest/add_monitor_project.ts | 41 ++++++++----------- .../apis/uptime/rest/edit_monitor.ts | 32 +++++++++++++-- 5 files changed, 62 insertions(+), 32 deletions(-) diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts index 34bde8957df090..4e6a6a06da1f36 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts @@ -132,9 +132,9 @@ export const createNewSavedObjectMonitor = async ({ }), id ? { - id, - overwrite: true, - } + id, + overwrite: true, + } : undefined ); }; diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts index 0f32882974279c..d8297403aa5e1c 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts @@ -35,6 +35,8 @@ export const createNewSavedObjectMonitorBulk = async ({ type: syntheticsMonitorType, attributes: formatSecrets({ ...monitor, + [ConfigKey.ID]: monitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, + [ConfigKey.CONFIG_ID]: id, revision: 1, }), })); diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts index f96479a50bc6f9..c04b3e22fbd9fe 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts @@ -48,7 +48,16 @@ export default function ({ getService }: FtrProviderContext) { .set('kbn-xsrf', 'true') .send(newMonitor); - expect(apiResponse.body.attributes).eql(omit(newMonitor, secretKeys)); + expect(apiResponse.body.attributes).eql( + omit( + { + ...newMonitor, + [ConfigKey.ID]: apiResponse.body.id, + [ConfigKey.CONFIG_ID]: apiResponse.body.id, + }, + secretKeys + ) + ); }); it('returns bad request if payload is invalid for HTTP monitor', async () => { @@ -106,6 +115,8 @@ export default function ({ getService }: FtrProviderContext) { { ...DEFAULT_FIELDS[DataStream.HTTP], ...newMonitor, + [ConfigKey.ID]: apiResponse.body.id, + [ConfigKey.CONFIG_ID]: apiResponse.body.id, revision: 1, }, secretKeys diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts index 02a40be5d2f40f..00175994721e1f 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts @@ -131,7 +131,7 @@ export default function ({ getService }: FtrProviderContext) { is_generated_script: false, }, }, - config_id: '', + config_id: decryptedCreatedMonitor.body.id, custom_heartbeat_id: `${journeyId}-test-suite-default`, enabled: true, 'filter_journeys.match': 'check if title is present', @@ -193,7 +193,7 @@ export default function ({ getService }: FtrProviderContext) { type: 'browser', 'url.port': null, urls: '', - id: '', + id: decryptedCreatedMonitor.body.id, hash: 'ekrjelkjrelkjre', }); } @@ -364,7 +364,7 @@ export default function ({ getService }: FtrProviderContext) { __ui: { is_tls_enabled: false, }, - config_id: '', + config_id: decryptedCreatedMonitor.body.id, custom_heartbeat_id: `${journeyId}-test-suite-default`, 'check.receive': '', 'check.send': '', @@ -410,7 +410,7 @@ export default function ({ getService }: FtrProviderContext) { hosts: Array.isArray(monitor.hosts) ? monitor.hosts?.[0] : monitor.hosts, 'url.port': null, urls: '', - id: '', + id: decryptedCreatedMonitor.body.id, hash: 'ekrjelkjrelkjre', }); } @@ -463,7 +463,7 @@ export default function ({ getService }: FtrProviderContext) { .expect(200); expect(decryptedCreatedMonitor.body.attributes).to.eql({ - config_id: '', + config_id: decryptedCreatedMonitor.body.id, custom_heartbeat_id: `${journeyId}-test-suite-default`, enabled: true, form_monitor_type: 'icmp', @@ -513,7 +513,7 @@ export default function ({ getService }: FtrProviderContext) { monitor.wait?.slice(-1) === 's' ? monitor.wait?.slice(0, -1) : `${parseInt(monitor.wait?.slice(0, -1) || '1', 10) * 60}`, - id: '', + id: decryptedCreatedMonitor.body.id, hash: 'ekrjelkjrelkjre', }); } @@ -1449,8 +1449,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); expect(packagePolicy.name).eql( @@ -1508,8 +1507,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1530,8 +1528,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1568,8 +1565,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1603,8 +1599,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1648,8 +1643,8 @@ export default function ({ getService }: FtrProviderContext) { (pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + - '-' + - testPolicyId + '-' + + testPolicyId ); expect(packagePolicy.policy_id).eql(testPolicyId); @@ -1698,8 +1693,8 @@ export default function ({ getService }: FtrProviderContext) { (pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + - '-' + - testPolicyId + '-' + + testPolicyId ); expect(packagePolicy2).eql(undefined); @@ -1741,8 +1736,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1870,8 +1864,7 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${ - monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] } - ${testPolicyId}` ); diff --git a/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts index eb44aa36a76c80..f3ae9d4fcd8071 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts @@ -61,7 +61,16 @@ export default function ({ getService }: FtrProviderContext) { newMonitor as MonitorFields ); - expect(savedMonitor).eql(omit(newMonitor, secretKeys)); + expect(savedMonitor).eql( + omit( + { + ...newMonitor, + [ConfigKey.ID]: monitorId, + [ConfigKey.CONFIG_ID]: monitorId, + }, + secretKeys + ) + ); const updates: Partial = { [ConfigKey.URLS]: 'https://modified-host.com', @@ -116,7 +125,16 @@ export default function ({ getService }: FtrProviderContext) { newMonitor as MonitorFields ); - expect(savedMonitor).eql(omit(newMonitor, secretKeys)); + expect(savedMonitor).eql( + omit( + { + ...newMonitor, + [ConfigKey.ID]: monitorId, + [ConfigKey.CONFIG_ID]: monitorId, + }, + secretKeys + ) + ); const updates: Partial = { [ConfigKey.URLS]: 'https://modified-host.com', @@ -147,7 +165,6 @@ export default function ({ getService }: FtrProviderContext) { const modifiedMonitor = omit( { - ...newMonitor, ...updates, [ConfigKey.METADATA]: { ...newMonitor[ConfigKey.METADATA], @@ -164,7 +181,14 @@ export default function ({ getService }: FtrProviderContext) { .expect(200); expect(editResponse.body.attributes).eql( - omit({ ...modifiedMonitor, revision: 2 }, secretKeys) + omit( + { + ...savedMonitor, + ...modifiedMonitor, + revision: 2, + }, + secretKeys + ) ); expect(editResponse.body.attributes).not.to.have.keys('unknownkey'); }); From 71c47a610be8429851991fdb7103a97f04921012 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 25 Oct 2022 18:51:31 +0000 Subject: [PATCH 06/34] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../routes/monitor_cruds/add_monitor.ts | 6 ++-- .../apis/uptime/rest/add_monitor_project.ts | 29 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts index 4e6a6a06da1f36..34bde8957df090 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts @@ -132,9 +132,9 @@ export const createNewSavedObjectMonitor = async ({ }), id ? { - id, - overwrite: true, - } + id, + overwrite: true, + } : undefined ); }; diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts index 00175994721e1f..4f0b17b4c94e8e 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts @@ -1449,7 +1449,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); expect(packagePolicy.name).eql( @@ -1507,7 +1508,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1528,7 +1530,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1565,7 +1568,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1599,7 +1603,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1643,8 +1648,8 @@ export default function ({ getService }: FtrProviderContext) { (pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + - '-' + - testPolicyId + '-' + + testPolicyId ); expect(packagePolicy.policy_id).eql(testPolicyId); @@ -1693,8 +1698,8 @@ export default function ({ getService }: FtrProviderContext) { (pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + - '-' + - testPolicyId + '-' + + testPolicyId ); expect(packagePolicy2).eql(undefined); @@ -1736,7 +1741,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1864,7 +1870,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] } - ${testPolicyId}` ); From 1e3fba1b0b6b593f55db470ac06649d01910659a Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 26 Oct 2022 13:03:12 -0400 Subject: [PATCH 07/34] update tests --- .../migrations/check_registered_types.test.ts | 2 +- .../e2e/page_objects/synthetics_app.tsx | 2 +- .../project_monitor_formatter.test.ts | 20 ++++++++-- .../project_monitor_formatter.ts | 13 ++++--- .../rest/add_monitor_private_location.ts | 21 +++++++++- .../apis/uptime/rest/add_monitor_project.ts | 39 +++++++++++-------- .../apis/uptime/rest/get_monitor.ts | 4 +- 7 files changed, 72 insertions(+), 29 deletions(-) diff --git a/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts b/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts index 7dce76528a5a05..a548c765720245 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts @@ -130,7 +130,7 @@ describe('checking migration metadata changes on all registered SO types', () => "siem-ui-timeline-pinned-event": "e2697b38751506c7fce6e8b7207a830483dc4283", "space": "c4a0acce1bd4b9cce85154f2a350624a53111c59", "spaces-usage-stats": "922d3235bbf519e3fb3b260e27248b1df8249b79", - "synthetics-monitor": "7bebb6511c70359386f9e20c982db86259c7915c", + "synthetics-monitor": "0c62bf304aebd2134b20627519713819da896eb1", "synthetics-privates-locations": "dd00385f4a27ef062c3e57312eeb3799872fa4af", "tag": "39413f4578cc2128c9a0fda97d0acd1c8862c47a", "task": "ef53d0f070bd54957b8fe22fae3b1ff208913f76", diff --git a/x-pack/plugins/synthetics/e2e/page_objects/synthetics_app.tsx b/x-pack/plugins/synthetics/e2e/page_objects/synthetics_app.tsx index fc365abd823b92..66d086fcea9d7b 100644 --- a/x-pack/plugins/synthetics/e2e/page_objects/synthetics_app.tsx +++ b/x-pack/plugins/synthetics/e2e/page_objects/synthetics_app.tsx @@ -82,7 +82,7 @@ export function syntheticsAppPageProvider({ page, kibanaUrl }: { page: Page; kib async navigateToEditMonitor() { await this.clickByTestSubj('syntheticsMonitorListActions'); - await page.click('text=Edit'); + await page.click('text=Edit', { timeout: 2 * 60 * 1000 }); await this.findByText('Edit monitor'); }, diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.test.ts index 5892f53344d48f..b840b5104c09f3 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.test.ts @@ -10,7 +10,7 @@ import { INSUFFICIENT_FLEET_PERMISSIONS, ProjectMonitorFormatter, } from './project_monitor_formatter'; -import { DataStream, LocationStatus } from '../../../common/runtime_types'; +import { ConfigKey, DataStream, LocationStatus } from '../../../common/runtime_types'; import { DEFAULT_FIELDS } from '../../../common/constants/monitor_defaults'; import { times } from 'lodash'; import { SyntheticsService } from '../synthetics_service'; @@ -468,8 +468,22 @@ describe('ProjectMonitorFormatter', () => { expect(soClient.bulkCreate).toHaveBeenCalledWith( expect.arrayContaining([ - expect.objectContaining(soData[0]), - expect.objectContaining(soData[1]), + expect.objectContaining({ + ...soData[0], + attributes: { + ...soData[0].attributes, + [ConfigKey.ID]: expect.any(String), + [ConfigKey.CONFIG_ID]: expect.any(String), + }, + }), + expect.objectContaining({ + ...soData[1], + attributes: { + ...soData[1].attributes, + [ConfigKey.ID]: expect.any(String), + [ConfigKey.CONFIG_ID]: expect.any(String), + }, + }), ]) ); diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts index 1c69c10552dd53..34a30c423a4c16 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts @@ -5,7 +5,7 @@ * 2.0. */ import type { Subject } from 'rxjs'; -import { isEqual } from 'lodash'; +import { isEqual, omit } from 'lodash'; import pMap from 'p-map'; import { KibanaRequest } from '@kbn/core/server'; import { @@ -375,10 +375,13 @@ export class ProjectMonitorFormatter { const previousMonitor = monitors[i].previousMonitor; const normalizedMonitor = monitors[i].monitor; - const { - attributes: { [ConfigKey.REVISION]: _, ...normalizedPreviousMonitorAttributes }, - } = normalizeSecrets(decryptedPreviousMonitor); - const hasMonitorBeenEdited = !isEqual(normalizedMonitor, normalizedPreviousMonitorAttributes); + const keysToOmit = [ConfigKey.REVISION, ConfigKey.ID, ConfigKey.CONFIG_ID]; + const { attributes: normalizedPreviousMonitorAttributes } = + normalizeSecrets(decryptedPreviousMonitor); + const hasMonitorBeenEdited = !isEqual( + omit(normalizedMonitor, keysToOmit), + omit(normalizedPreviousMonitorAttributes, keysToOmit) + ); if (hasMonitorBeenEdited) { const monitorWithRevision = formatSecrets({ diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts index 12ef5ac9754064..357524401b0824 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts @@ -100,7 +100,16 @@ export default function ({ getService }: FtrProviderContext) { .set('kbn-xsrf', 'true') .send(newMonitor); - expect(apiResponse.body.attributes).eql(omit(newMonitor, secretKeys)); + expect(apiResponse.body.attributes).eql( + omit( + { + ...newMonitor, + [ConfigKey.ID]: apiResponse.body.id, + [ConfigKey.CONFIG_ID]: apiResponse.body.id, + }, + secretKeys + ) + ); newMonitorId = apiResponse.body.id; }); @@ -266,7 +275,15 @@ export default function ({ getService }: FtrProviderContext) { .expect(200); expect(apiResponse.body.attributes).eql( - omit({ ...monitor, [ConfigKey.NAMESPACE]: formatKibanaNamespace(SPACE_ID) }, secretKeys) + omit( + { + ...monitor, + [ConfigKey.ID]: apiResponse.body.id, + [ConfigKey.CONFIG_ID]: apiResponse.body.id, + [ConfigKey.NAMESPACE]: formatKibanaNamespace(SPACE_ID), + }, + secretKeys + ) ); monitorId = apiResponse.body.id; diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts index 00175994721e1f..d815e95613f7c2 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_project.ts @@ -193,7 +193,7 @@ export default function ({ getService }: FtrProviderContext) { type: 'browser', 'url.port': null, urls: '', - id: decryptedCreatedMonitor.body.id, + id: `${journeyId}-test-suite-default`, hash: 'ekrjelkjrelkjre', }); } @@ -251,7 +251,7 @@ export default function ({ getService }: FtrProviderContext) { }, 'check.request.method': 'POST', 'check.response.status': ['200'], - config_id: '', + config_id: decryptedCreatedMonitor.body.id, custom_heartbeat_id: `${journeyId}-test-suite-default`, 'check.response.body.negative': [], 'check.response.body.positive': ['Saved', 'saved'], @@ -308,7 +308,7 @@ export default function ({ getService }: FtrProviderContext) { type: 'http', urls: Array.isArray(monitor.urls) ? monitor.urls?.[0] : monitor.urls, 'url.port': null, - id: '', + id: `${journeyId}-test-suite-default`, hash: 'ekrjelkjrelkjre', }); } @@ -410,7 +410,7 @@ export default function ({ getService }: FtrProviderContext) { hosts: Array.isArray(monitor.hosts) ? monitor.hosts?.[0] : monitor.hosts, 'url.port': null, urls: '', - id: decryptedCreatedMonitor.body.id, + id: `${journeyId}-test-suite-default`, hash: 'ekrjelkjrelkjre', }); } @@ -513,7 +513,7 @@ export default function ({ getService }: FtrProviderContext) { monitor.wait?.slice(-1) === 's' ? monitor.wait?.slice(0, -1) : `${parseInt(monitor.wait?.slice(0, -1) || '1', 10) * 60}`, - id: decryptedCreatedMonitor.body.id, + id: `${journeyId}-test-suite-default`, hash: 'ekrjelkjrelkjre', }); } @@ -1449,7 +1449,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); expect(packagePolicy.name).eql( @@ -1507,7 +1508,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1528,7 +1530,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1565,7 +1568,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1599,7 +1603,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1643,8 +1648,8 @@ export default function ({ getService }: FtrProviderContext) { (pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + - '-' + - testPolicyId + '-' + + testPolicyId ); expect(packagePolicy.policy_id).eql(testPolicyId); @@ -1693,8 +1698,8 @@ export default function ({ getService }: FtrProviderContext) { (pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + - '-' + - testPolicyId + '-' + + testPolicyId ); expect(packagePolicy2).eql(undefined); @@ -1736,7 +1741,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy = apiResponsePolicy.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] }-${testPolicyId}` ); @@ -1864,7 +1870,8 @@ export default function ({ getService }: FtrProviderContext) { const packagePolicy2 = apiResponsePolicy2.body.items.find( (pkgPolicy: PackagePolicy) => pkgPolicy.id === - `${monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] + `${ + monitorsResponse.body.monitors[0].attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] } - ${testPolicyId}` ); diff --git a/x-pack/test/api_integration/apis/uptime/rest/get_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/get_monitor.ts index b90014b657b4ab..ac8211b2cad420 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/get_monitor.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/get_monitor.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { SimpleSavedObject } from '@kbn/core/public'; -import { MonitorFields } from '@kbn/synthetics-plugin/common/runtime_types'; +import { ConfigKey, MonitorFields } from '@kbn/synthetics-plugin/common/runtime_types'; import { API_URLS } from '@kbn/synthetics-plugin/common/constants'; import { FtrProviderContext } from '../../../ftr_provider_context'; import { getFixtureJson } from './helper/get_fixture_json'; @@ -97,6 +97,8 @@ export default function ({ getService }: FtrProviderContext) { expect(apiResponse.body.attributes).eql({ ...monitors[0], + [ConfigKey.ID]: apiResponse.body.id, + [ConfigKey.CONFIG_ID]: apiResponse.body.id, revision: 1, }); }); From 2f7266703a3295830b170e21275fed436d3f5ee0 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 26 Oct 2022 13:20:36 -0400 Subject: [PATCH 08/34] adjust types --- .../common/runtime_types/monitor_management/locations.ts | 2 +- .../monitor_management/synthetics_private_locations.ts | 1 + .../lib/saved_objects/migrations/monitors/8.6.0.test.ts | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/locations.ts b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/locations.ts index 9f27becbbb023f..30ab08b880c201 100644 --- a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/locations.ts +++ b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/locations.ts @@ -82,8 +82,8 @@ export const MonitorServiceLocationCodec = t.intersection([ label: t.string, geo: LocationGeoCodec, url: t.string, - isInvalid: t.boolean, isServiceManaged: t.boolean, + status: t.string, }), ]); diff --git a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/synthetics_private_locations.ts b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/synthetics_private_locations.ts index 556f1e56ed1021..822b59741f844e 100644 --- a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/synthetics_private_locations.ts +++ b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/synthetics_private_locations.ts @@ -16,6 +16,7 @@ export const PrivateLocationCodec = t.intersection([ }), t.partial({ isServiceManaged: t.boolean, + isInvalid: t.boolean, /* Empty Lat lon was accidentally saved as an empty string instead of undefined or null * Need a migration to fix */ geo: t.interface({ lat: t.union([t.string, t.number]), lon: t.union([t.string, t.number]) }), diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts index 0fc846124b2cd3..6d09295c63288b 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts @@ -7,7 +7,11 @@ import { encryptedSavedObjectsMock } from '@kbn/encrypted-saved-objects-plugin/server/mocks'; import { migration860 } from './8.6.0'; import { migrationMocks } from '@kbn/core/server/mocks'; -import { ConfigKey, SyntheticsMonitorWithSecrets } from '../../../../../../common/runtime_types'; +import { + ConfigKey, + LocationStatus, + SyntheticsMonitorWithSecrets, +} from '../../../../../../common/runtime_types'; const context = migrationMocks.createContext(); const encryptedSavedObjectsSetup = encryptedSavedObjectsMock.createSetup(); @@ -77,7 +81,7 @@ const monitor850Project = { geo: { lat: 41.25, lon: -95.86 }, url: 'https://us-central.synthetics.elastic.dev', isServiceManaged: true, - status: 'ga', + status: LocationStatus.GA, isInvalid: false, }, ], From 4757a8322d13f5d6eff7c689972e752269c1b183 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Thu, 27 Oct 2022 09:02:00 -0400 Subject: [PATCH 09/34] rename id key --- .../runtime_types/monitor_management/monitor_types.ts | 4 ++-- .../components/fleet_package/common/normalizers.ts | 2 +- .../saved_objects/migrations/monitors/8.6.0.test.ts | 10 +++++----- .../server/routes/monitor_cruds/add_monitor.ts | 2 +- .../monitor_cruds/bulk_cruds/add_monitor_bulk.ts | 2 +- .../project_monitor/project_monitor_formatter.test.ts | 4 ++-- .../project_monitor/project_monitor_formatter.ts | 2 +- .../api_integration/apis/uptime/rest/add_monitor.ts | 4 ++-- .../apis/uptime/rest/add_monitor_private_location.ts | 4 ++-- .../api_integration/apis/uptime/rest/edit_monitor.ts | 4 ++-- .../api_integration/apis/uptime/rest/get_monitor.ts | 2 +- 11 files changed, 20 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts index 78bca7a6814616..3dd10f854fab79 100644 --- a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts +++ b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts @@ -75,19 +75,19 @@ export const CommonFieldsCodec = t.intersection([ [ConfigKey.APM_SERVICE_NAME]: t.string, [ConfigKey.TAGS]: t.array(t.string), [ConfigKey.LOCATIONS]: t.array(t.union([MonitorServiceLocationCodec, PrivateLocationCodec])), + [ConfigKey.HEARTBEAT_ID]: t.string, + [ConfigKey.CONFIG_ID]: t.string, }), t.partial({ [ConfigKey.FORM_MONITOR_TYPE]: FormMonitorTypeCodec, [ConfigKey.TIMEOUT]: t.union([t.string, t.null]), [ConfigKey.REVISION]: t.number, [ConfigKey.MONITOR_SOURCE_TYPE]: SourceTypeCodec, - [ConfigKey.CONFIG_ID]: t.string, [ConfigKey.CONFIG_HASH]: t.string, [ConfigKey.JOURNEY_ID]: t.string, [ConfigKey.PROJECT_ID]: t.string, [ConfigKey.ORIGINAL_SPACE]: t.string, [ConfigKey.CUSTOM_HEARTBEAT_ID]: t.string, - [ConfigKey.ID]: t.string, }), ]); diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts index 0f6b1f465a9a3a..46e60b0b2d2740 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts @@ -97,5 +97,5 @@ export const commonNormalizers: CommonNormalizerMap = { [ConfigKey.CUSTOM_HEARTBEAT_ID]: getCommonNormalizer(ConfigKey.CUSTOM_HEARTBEAT_ID), [ConfigKey.ORIGINAL_SPACE]: getCommonNormalizer(ConfigKey.ORIGINAL_SPACE), [ConfigKey.CONFIG_HASH]: getCommonNormalizer(ConfigKey.CONFIG_HASH), - [ConfigKey.ID]: getCommonNormalizer(ConfigKey.ID), + [ConfigKey.HEARTBEAT_ID]: getCommonNormalizer(ConfigKey.HEARTBEAT_ID), }; diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts index 6d09295c63288b..d35dfaa25aa10f 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts @@ -135,7 +135,7 @@ describe('Case migrations v8.5.0 -> v8.6.0', () => { ...monitor850UI, attributes: { ...monitor850UI.attributes, - [ConfigKey.ID]: monitor850UI.id, + [ConfigKey.HEARTBEAT_ID]: monitor850UI.id, [ConfigKey.CONFIG_ID]: monitor850UI.id, }, }); @@ -146,7 +146,7 @@ describe('Case migrations v8.5.0 -> v8.6.0', () => { ...monitor850Project, attributes: { ...monitor850Project.attributes, - [ConfigKey.ID]: monitor850Project.attributes[ConfigKey.CUSTOM_HEARTBEAT_ID], + [ConfigKey.HEARTBEAT_ID]: monitor850Project.attributes[ConfigKey.CUSTOM_HEARTBEAT_ID], [ConfigKey.CONFIG_ID]: monitor850Project.id, }, }); @@ -166,7 +166,7 @@ describe('Case migrations v8.5.0 -> v8.6.0', () => { ...monitor850UI, attributes: { ...attributes, - [ConfigKey.ID]: monitor850UI.id, + [ConfigKey.HEARTBEAT_ID]: monitor850UI.id, [ConfigKey.CONFIG_ID]: monitor850UI.id, }, }); @@ -188,7 +188,7 @@ describe('Case migrations v8.5.0 -> v8.6.0', () => { ...monitor850UI, attributes: { ...attributes, - [ConfigKey.ID]: monitor850UI.id, + [ConfigKey.HEARTBEAT_ID]: monitor850UI.id, [ConfigKey.CONFIG_ID]: monitor850UI.id, }, }); @@ -208,7 +208,7 @@ describe('Case migrations v8.5.0 -> v8.6.0', () => { ...monitor850UI, attributes: { ...attributes, - [ConfigKey.ID]: monitor850UI.id, + [ConfigKey.HEARTBEAT_ID]: monitor850UI.id, [ConfigKey.CONFIG_ID]: monitor850UI.id, }, }); diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts index 34bde8957df090..1303c029bbc67e 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts @@ -126,7 +126,7 @@ export const createNewSavedObjectMonitor = async ({ syntheticsMonitorType, formatSecrets({ ...normalizedMonitor, - [ConfigKey.ID]: normalizedMonitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, + [ConfigKey.HEARTBEAT_ID]: normalizedMonitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, [ConfigKey.CONFIG_ID]: id, revision: 1, }), diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts index d8297403aa5e1c..7279f636bec7ad 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts @@ -35,7 +35,7 @@ export const createNewSavedObjectMonitorBulk = async ({ type: syntheticsMonitorType, attributes: formatSecrets({ ...monitor, - [ConfigKey.ID]: monitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, + [ConfigKey.HEARTBEAT_ID]: monitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, [ConfigKey.CONFIG_ID]: id, revision: 1, }), diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.test.ts index b840b5104c09f3..4ca83d7b784610 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.test.ts @@ -472,7 +472,7 @@ describe('ProjectMonitorFormatter', () => { ...soData[0], attributes: { ...soData[0].attributes, - [ConfigKey.ID]: expect.any(String), + [ConfigKey.HEARTBEAT_ID]: expect.any(String), [ConfigKey.CONFIG_ID]: expect.any(String), }, }), @@ -480,7 +480,7 @@ describe('ProjectMonitorFormatter', () => { ...soData[1], attributes: { ...soData[1].attributes, - [ConfigKey.ID]: expect.any(String), + [ConfigKey.HEARTBEAT_ID]: expect.any(String), [ConfigKey.CONFIG_ID]: expect.any(String), }, }), diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts index 34a30c423a4c16..ad47edd3d6b196 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts @@ -375,7 +375,7 @@ export class ProjectMonitorFormatter { const previousMonitor = monitors[i].previousMonitor; const normalizedMonitor = monitors[i].monitor; - const keysToOmit = [ConfigKey.REVISION, ConfigKey.ID, ConfigKey.CONFIG_ID]; + const keysToOmit = [ConfigKey.REVISION, ConfigKey.HEARTBEAT_ID, ConfigKey.CONFIG_ID]; const { attributes: normalizedPreviousMonitorAttributes } = normalizeSecrets(decryptedPreviousMonitor); const hasMonitorBeenEdited = !isEqual( diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts index c04b3e22fbd9fe..7b76de68b4deb8 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts @@ -52,7 +52,7 @@ export default function ({ getService }: FtrProviderContext) { omit( { ...newMonitor, - [ConfigKey.ID]: apiResponse.body.id, + [ConfigKey.HEARTBEAT_ID]: apiResponse.body.id, [ConfigKey.CONFIG_ID]: apiResponse.body.id, }, secretKeys @@ -115,7 +115,7 @@ export default function ({ getService }: FtrProviderContext) { { ...DEFAULT_FIELDS[DataStream.HTTP], ...newMonitor, - [ConfigKey.ID]: apiResponse.body.id, + [ConfigKey.HEARTBEAT_ID]: apiResponse.body.id, [ConfigKey.CONFIG_ID]: apiResponse.body.id, revision: 1, }, diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts index 357524401b0824..cae29a4307717c 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts @@ -104,7 +104,7 @@ export default function ({ getService }: FtrProviderContext) { omit( { ...newMonitor, - [ConfigKey.ID]: apiResponse.body.id, + [ConfigKey.HEARTBEAT_ID]: apiResponse.body.id, [ConfigKey.CONFIG_ID]: apiResponse.body.id, }, secretKeys @@ -278,7 +278,7 @@ export default function ({ getService }: FtrProviderContext) { omit( { ...monitor, - [ConfigKey.ID]: apiResponse.body.id, + [ConfigKey.HEARTBEAT_ID]: apiResponse.body.id, [ConfigKey.CONFIG_ID]: apiResponse.body.id, [ConfigKey.NAMESPACE]: formatKibanaNamespace(SPACE_ID), }, diff --git a/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts index f3ae9d4fcd8071..a91c066ddee801 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts @@ -65,7 +65,7 @@ export default function ({ getService }: FtrProviderContext) { omit( { ...newMonitor, - [ConfigKey.ID]: monitorId, + [ConfigKey.HEARTBEAT_ID]: monitorId, [ConfigKey.CONFIG_ID]: monitorId, }, secretKeys @@ -129,7 +129,7 @@ export default function ({ getService }: FtrProviderContext) { omit( { ...newMonitor, - [ConfigKey.ID]: monitorId, + [ConfigKey.HEARTBEAT_ID]: monitorId, [ConfigKey.CONFIG_ID]: monitorId, }, secretKeys diff --git a/x-pack/test/api_integration/apis/uptime/rest/get_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/get_monitor.ts index ac8211b2cad420..a4caca5914cfaf 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/get_monitor.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/get_monitor.ts @@ -97,7 +97,7 @@ export default function ({ getService }: FtrProviderContext) { expect(apiResponse.body.attributes).eql({ ...monitors[0], - [ConfigKey.ID]: apiResponse.body.id, + [ConfigKey.HEARTBEAT_ID]: apiResponse.body.id, [ConfigKey.CONFIG_ID]: apiResponse.body.id, revision: 1, }); From 558e7fcfcdd4b9251da734d04b2394b4c5efa251 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Thu, 27 Oct 2022 13:27:47 -0400 Subject: [PATCH 10/34] rename id key --- .../plugins/synthetics/common/constants/monitor_defaults.ts | 2 +- .../plugins/synthetics/common/constants/monitor_management.ts | 4 +--- .../plugins/synthetics/common/formatters/common/formatters.ts | 2 +- .../monitor_details/monitor_summary/last_ten_test_runs.tsx | 3 ++- .../lib/saved_objects/migrations/monitors/8.6.0.ts | 2 +- .../synthetics/server/synthetics_service/formatters/common.ts | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts index 9426e498879ab0..f091e6d19d1d55 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts @@ -48,7 +48,7 @@ export const DEFAULT_COMMON_FIELDS: CommonFields = { [ConfigKey.MONITOR_SOURCE_TYPE]: SourceType.UI, [ConfigKey.JOURNEY_ID]: '', [ConfigKey.CONFIG_HASH]: '', - [ConfigKey.ID]: '', + [ConfigKey.HEARTBEAT_ID]: '', }; export const DEFAULT_BROWSER_ADVANCED_FIELDS: BrowserAdvancedFields = { diff --git a/x-pack/plugins/synthetics/common/constants/monitor_management.ts b/x-pack/plugins/synthetics/common/constants/monitor_management.ts index bdf5dc6548f20b..7d367b0078a3b0 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_management.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_management.ts @@ -78,9 +78,7 @@ export enum ConfigKey { ZIP_URL_TLS_KEY_PASSPHRASE = 'source.zip_url.ssl.key_passphrase', ZIP_URL_TLS_VERIFICATION_MODE = 'source.zip_url.ssl.verification_mode', ZIP_URL_TLS_VERSION = 'source.zip_url.ssl.supported_protocols', - - // deprecated, slated to be removed in a future version - ID = 'id', + HEARTBEAT_ID = 'id', } export const secretKeys = [ diff --git a/x-pack/plugins/synthetics/common/formatters/common/formatters.ts b/x-pack/plugins/synthetics/common/formatters/common/formatters.ts index 619adfce73e74d..7003c6251cab5d 100644 --- a/x-pack/plugins/synthetics/common/formatters/common/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/common/formatters.ts @@ -33,7 +33,7 @@ export const commonFormatters: CommonFormatMap = { [ConfigKey.CUSTOM_HEARTBEAT_ID]: null, [ConfigKey.ORIGINAL_SPACE]: null, [ConfigKey.CONFIG_HASH]: null, - [ConfigKey.ID]: null, + [ConfigKey.HEARTBEAT_ID]: null, }; export const arrayToJsonFormatter = (value: string[] = []) => diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/last_ten_test_runs.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/last_ten_test_runs.tsx index eddf40739e55db..210f902d35e15b 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/last_ten_test_runs.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/last_ten_test_runs.tsx @@ -119,7 +119,8 @@ export const LastTenTestRuns = () => { }, ]; - const historyIdParam = monitor?.[ConfigKey.CUSTOM_HEARTBEAT_ID] ?? monitor?.[ConfigKey.ID]; + const historyIdParam = + monitor?.[ConfigKey.CUSTOM_HEARTBEAT_ID] ?? monitor?.[ConfigKey.HEARTBEAT_ID]; return ( diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts index a8ef0b16dac4f3..e056b7d1a014e5 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts @@ -26,7 +26,7 @@ export const migration860 = (encryptedSavedObjects: EncryptedSavedObjectsPluginS ...doc, attributes: { ...attributes, - [ConfigKey.ID]: attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, + [ConfigKey.HEARTBEAT_ID]: attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, [ConfigKey.CONFIG_ID]: id, }, }; diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts index f45f04cbc986b5..18acd2e1378bab 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts @@ -35,7 +35,7 @@ export const commonFormatters: CommonFormatMap = { [ConfigKey.CUSTOM_HEARTBEAT_ID]: null, [ConfigKey.ORIGINAL_SPACE]: null, [ConfigKey.CONFIG_HASH]: null, - [ConfigKey.ID]: null, + [ConfigKey.HEARTBEAT_ID]: null, }; export const arrayFormatter = (value: string[] = []) => (value.length ? value : null); From 2c1446450ba4d08fdbde97be34e607ef048eef40 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Fri, 28 Oct 2022 09:33:36 -0400 Subject: [PATCH 11/34] adjust types and tests --- .../components/monitor_add_edit/form/defaults.test.tsx | 2 ++ .../synthetics/utils/testing/__mocks__/synthetics_store.mock.ts | 1 + .../server/routes/monitor_cruds/monitor_validation.test.ts | 2 ++ 3 files changed, 5 insertions(+) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/defaults.test.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/defaults.test.tsx index 192c76e414b07a..e691eeec7b264d 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/defaults.test.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/defaults.test.tsx @@ -72,6 +72,8 @@ describe('defaults', () => { type: 'browser', 'url.port': null, urls: '', + id: '', + config_id: '', } as SyntheticsMonitor; it('correctly formats monitor type to form type', () => { diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/utils/testing/__mocks__/synthetics_store.mock.ts b/x-pack/plugins/synthetics/public/apps/synthetics/utils/testing/__mocks__/synthetics_store.mock.ts index 6031707c1fd19e..21522878155743 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/utils/testing/__mocks__/synthetics_store.mock.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/utils/testing/__mocks__/synthetics_store.mock.ts @@ -299,6 +299,7 @@ function getMonitorDetailsMockSlice() { loading: false, syntheticsMonitor: { id: '4afd3980-0b72-11ed-9c10-b57918ea89d6', + config_id: '4afd3980-0b72-11ed-9c10-b57918ea89d6', type: DataStream.BROWSER, enabled: true, schedule: { unit: ScheduleUnit.MINUTES, number: '10' }, diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.test.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.test.ts index 76bda0f4a2f12d..9c852bd994a6c9 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.test.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.test.ts @@ -58,6 +58,7 @@ describe('validateMonitor', () => { [ConfigKey.MONITOR_TYPE]: DataStream.ICMP, [ConfigKey.NAME]: 'test-monitor-name', [ConfigKey.CONFIG_ID]: 'test-monitor-id', + [ConfigKey.HEARTBEAT_ID]: '', [ConfigKey.ENABLED]: true, [ConfigKey.TAGS]: testTags, [ConfigKey.SCHEDULE]: testSchedule, @@ -445,6 +446,7 @@ function getJsonPayload() { ' ],' + ' "name": "test-monitor-name",' + ' "config_id": "test-monitor-id",' + + ' "id": "test-id",' + ' "namespace": "testnamespace",' + ' "locations": [{' + ' "id": "eu-west-01",' + From 1e3acaa19706e1c9bc310609ebe9e9a00f82064e Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Fri, 28 Oct 2022 11:44:34 -0400 Subject: [PATCH 12/34] adjust test --- .../components/monitor_add_edit/form/defaults.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/defaults.test.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/defaults.test.tsx index e691eeec7b264d..dcb009c809a5ea 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/defaults.test.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/defaults.test.tsx @@ -78,6 +78,7 @@ describe('defaults', () => { it('correctly formats monitor type to form type', () => { expect(formatDefaultFormValues(monitorValues)).toEqual({ + ...monitorValues, __ui: { script_source: { file_name: '', From 15414c53d1f2c1bd08801f0691dac1c41212ee73 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Fri, 28 Oct 2022 11:52:10 -0400 Subject: [PATCH 13/34] synthetics - update references to CUSTOM_HEARTBEAT_ID to prefer HEARTBEAT_ID --- .../routes/monitor_cruds/bulk_cruds/delete_monitor_bulk.ts | 2 +- .../synthetics/server/routes/monitor_cruds/delete_monitor.ts | 4 +--- .../plugins/synthetics/server/routes/status/current_status.ts | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/delete_monitor_bulk.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/delete_monitor_bulk.ts index 862bab6915f36a..dcdf0a2c513ad3 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/delete_monitor_bulk.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/delete_monitor_bulk.ts @@ -41,7 +41,7 @@ export const deleteMonitorBulk = async ({ const deleteSyncPromise = syntheticsMonitorClient.deleteMonitors( monitors.map((normalizedMonitor) => ({ ...normalizedMonitor.attributes, - id: normalizedMonitor.attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] || normalizedMonitor.id, + id: normalizedMonitor.attributes[ConfigKey.HEARTBEAT_ID], })) as EncryptedSyntheticsMonitorWithId[], request, savedObjectsClient, diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/delete_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/delete_monitor.ts index 9524d504f85c53..8c54926d4c4ec3 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/delete_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/delete_monitor.ts @@ -110,9 +110,7 @@ export const deleteMonitor = async ({ [ { ...normalizedMonitor.attributes, - id: - (normalizedMonitor.attributes as MonitorFields)[ConfigKey.CUSTOM_HEARTBEAT_ID] || - monitorId, + id: (normalizedMonitor.attributes as MonitorFields)[ConfigKey.HEARTBEAT_ID], }, ], request, diff --git a/x-pack/plugins/synthetics/server/routes/status/current_status.ts b/x-pack/plugins/synthetics/server/routes/status/current_status.ts index 0de4de69776af3..a2b054d04ec166 100644 --- a/x-pack/plugins/synthetics/server/routes/status/current_status.ts +++ b/x-pack/plugins/synthetics/server/routes/status/current_status.ts @@ -162,7 +162,7 @@ export async function getStatus( if (monitor.attributes[ConfigKey.ENABLED] === false) { disabledCount += monitor.attributes[ConfigKey.LOCATIONS].length; } else { - enabledIds.push(monitor.attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] || monitor.id); + enabledIds.push(monitor.attributes[ConfigKey.HEARTBEAT_ID]); maxLocations = Math.max(maxLocations, monitor.attributes.locations.length); maxPeriod = Math.max(maxPeriod, periodToMs(monitor.attributes.schedule)); } From 1f377683345e2f48929f7282dcb91cf9083aea5a Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Fri, 28 Oct 2022 12:07:50 -0400 Subject: [PATCH 14/34] update formatHeartbeatRequest --- .../monitor_list/monitor_list.tsx | 2 +- .../routes/synthetics_service/run_once_monitor.ts | 1 + .../routes/synthetics_service/test_now_monitor.ts | 4 +--- .../formatters/format_configs.test.ts | 13 +++++++++---- .../synthetics_service/formatters/format_configs.ts | 6 +++--- .../synthetics_monitor/synthetics_monitor_client.ts | 4 ++-- .../server/synthetics_service/synthetics_service.ts | 2 +- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/monitor_list.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/monitor_list.tsx index c603035130ca33..db7ba9e85d1aa3 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/monitor_list.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/monitor_list.tsx @@ -127,7 +127,7 @@ export const MonitorManagementList = ({ render: (name: string, monitor: EncryptedSyntheticsMonitorWithId) => ( {name} diff --git a/x-pack/plugins/synthetics/server/routes/synthetics_service/run_once_monitor.ts b/x-pack/plugins/synthetics/server/routes/synthetics_service/run_once_monitor.ts index 5bbc8c27e3ebe6..a730daa79ef873 100644 --- a/x-pack/plugins/synthetics/server/routes/synthetics_service/run_once_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/synthetics_service/run_once_monitor.ts @@ -38,6 +38,7 @@ export const runOnceSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () = // making it enabled, even if it's disabled in the UI monitor: { ...validationResult.decodedMonitor, enabled: true }, monitorId, + heartbeatId: monitorId, runOnce: true, }), ]); diff --git a/x-pack/plugins/synthetics/server/routes/synthetics_service/test_now_monitor.ts b/x-pack/plugins/synthetics/server/routes/synthetics_service/test_now_monitor.ts index 1c6d6548c575d1..2c3e6787f6c2de 100644 --- a/x-pack/plugins/synthetics/server/routes/synthetics_service/test_now_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/synthetics_service/test_now_monitor.ts @@ -58,9 +58,7 @@ export const testNowMonitorRoute: SyntheticsRestApiRouteFactory = () => ({ // making it enabled, even if it's disabled in the UI monitor: { ...normalizedMonitor.attributes, enabled: true }, monitorId, - customHeartbeatId: (normalizedMonitor.attributes as MonitorFields)[ - ConfigKey.CUSTOM_HEARTBEAT_ID - ], + heartbeatId: (normalizedMonitor.attributes as MonitorFields)[ConfigKey.HEARTBEAT_ID], testRunId, }), ]); diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/format_configs.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/format_configs.test.ts index 7bdbcc9e2554d7..84b9063fcc88bf 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/format_configs.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/format_configs.test.ts @@ -205,17 +205,17 @@ describe('formatMonitorConfig', () => { }); describe('formatHeartbeatRequest', () => { - it('uses custom heartbeat id when defined', () => { + it('uses heartbeat id', () => { const monitorId = 'test-monitor-id'; - const customHeartbeatId = 'test-custom-heartbeat-id'; + const heartbeatId = 'test-custom-heartbeat-id'; const actual = formatHeartbeatRequest({ monitor: testBrowserConfig as SyntheticsMonitor, monitorId, - customHeartbeatId, + heartbeatId, }); expect(actual).toEqual({ ...testBrowserConfig, - id: customHeartbeatId, + id: heartbeatId, fields: { config_id: monitorId, 'monitor.project.name': testBrowserConfig.project_id, @@ -232,6 +232,7 @@ describe('formatHeartbeatRequest', () => { const actual = formatHeartbeatRequest({ monitor: testBrowserConfig as SyntheticsMonitor, monitorId, + heartbeatId: monitorId, }); expect(actual).toEqual({ ...testBrowserConfig, @@ -253,6 +254,7 @@ describe('formatHeartbeatRequest', () => { const actual = formatHeartbeatRequest({ monitor, monitorId, + heartbeatId: monitorId, }); expect(actual).toEqual({ @@ -275,6 +277,7 @@ describe('formatHeartbeatRequest', () => { const actual = formatHeartbeatRequest({ monitor, monitorId, + heartbeatId: monitorId, }); expect(actual).toEqual({ @@ -297,6 +300,7 @@ describe('formatHeartbeatRequest', () => { monitor: testBrowserConfig as SyntheticsMonitor, monitorId, runOnce: true, + heartbeatId: monitorId, }); expect(actual).toEqual({ @@ -320,6 +324,7 @@ describe('formatHeartbeatRequest', () => { monitor: testBrowserConfig as SyntheticsMonitor, monitorId, testRunId, + heartbeatId: monitorId, }); expect(actual).toEqual({ diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/format_configs.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/format_configs.ts index 320d3c28b48d38..8c81191ee626be 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/format_configs.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/format_configs.ts @@ -65,20 +65,20 @@ export const formatMonitorConfig = (configKeys: ConfigKey[], config: Partial { const projectId = (monitor as BrowserFields)[ConfigKey.PROJECT_ID]; return { ...monitor, - id: customHeartbeatId || monitorId, + id: heartbeatId, fields: { config_id: monitorId, 'monitor.project.name': projectId || undefined, diff --git a/x-pack/plugins/synthetics/server/synthetics_service/synthetics_monitor/synthetics_monitor_client.ts b/x-pack/plugins/synthetics/server/synthetics_service/synthetics_monitor/synthetics_monitor_client.ts index 8218a6f0b3baf1..d4ba1c83d75ee0 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/synthetics_monitor/synthetics_monitor_client.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/synthetics_monitor/synthetics_monitor_client.ts @@ -44,7 +44,7 @@ export class SyntheticsMonitorClient { const config = formatHeartbeatRequest({ monitor, monitorId: id, - customHeartbeatId: monitor[ConfigKey.CUSTOM_HEARTBEAT_ID], + heartbeatId: monitor[ConfigKey.HEARTBEAT_ID], }); const { privateLocations, publicLocations } = this.parseLocations(config); @@ -96,7 +96,7 @@ export class SyntheticsMonitorClient { const editedConfig = formatHeartbeatRequest({ monitor: editedMonitor.monitor, monitorId: editedMonitor.id, - customHeartbeatId: (editedMonitor.monitor as MonitorFields)[ConfigKey.CUSTOM_HEARTBEAT_ID], + heartbeatId: (editedMonitor.monitor as MonitorFields)[ConfigKey.HEARTBEAT_ID], }); const { publicLocations, privateLocations } = this.parseLocations(editedConfig); if (publicLocations.length > 0) { diff --git a/x-pack/plugins/synthetics/server/synthetics_service/synthetics_service.ts b/x-pack/plugins/synthetics/server/synthetics_service/synthetics_service.ts index f4d505de5baac5..bb2c5ac3b81b7e 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/synthetics_service.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/synthetics_service.ts @@ -459,7 +459,7 @@ export class SyntheticsService { return formatHeartbeatRequest({ monitor: normalizeSecrets(monitor).attributes, monitorId: monitor.id, - customHeartbeatId: attributes[ConfigKey.CUSTOM_HEARTBEAT_ID], + heartbeatId: attributes[ConfigKey.HEARTBEAT_ID], }); }) ); From 93681bf83e9ea5e777d5e54fcd96407041ec57cb Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Fri, 28 Oct 2022 12:17:43 -0400 Subject: [PATCH 15/34] update legacy uptime monitor details saved object query --- .../server/legacy_uptime/routes/monitors/monitor_status.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/routes/monitors/monitor_status.ts b/x-pack/plugins/synthetics/server/legacy_uptime/routes/monitors/monitor_status.ts index 2bf898bf309d4c..a22de0104013e1 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/routes/monitors/monitor_status.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/routes/monitors/monitor_status.ts @@ -47,7 +47,7 @@ export const createGetStatusBarRoute: UMRestApiRouteFactory = (libs: UMServerLib type: syntheticsMonitorType, perPage: 1, page: 1, - filter: `${syntheticsMonitorType}.id: "${syntheticsMonitorType}:${monitorId}" OR ${syntheticsMonitorType}.attributes.${ConfigKey.CUSTOM_HEARTBEAT_ID}: "${monitorId}"`, + filter: `${syntheticsMonitorType}.attributes.${ConfigKey.HEARTBEAT_ID}: "${monitorId}"`, }); if (!monitorSavedObject) { From 887f0c0bf71cc667b0616bda5d8d4c39597c611d Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Fri, 28 Oct 2022 13:37:00 -0400 Subject: [PATCH 16/34] update jest test --- .../server/routes/monitor_cruds/edit_monitor.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.test.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.test.ts index 9f4492ce2dc708..33227665ad692b 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.test.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.test.ts @@ -79,7 +79,7 @@ describe('syncEditedMonitor', () => { } as unknown as SyntheticsMonitor; const previousMonitor = { - id: 'saved-obj-id', + id: '7af7e2f0-d5dc-11ec-87ac-bdfdb894c53d', attributes: { name: editedMonitor.name, locations: [] } as any, type: 'synthetics-monitor', references: [], @@ -109,14 +109,14 @@ describe('syncEditedMonitor', () => { expect(syntheticsService.editConfig).toHaveBeenCalledWith( expect.arrayContaining([ expect.objectContaining({ - id: 'saved-obj-id', + id: '7af7e2f0-d5dc-11ec-87ac-bdfdb894c53d', }), ]) ); expect(serverMock.authSavedObjectsClient?.update).toHaveBeenCalledWith( 'synthetics-monitor', - 'saved-obj-id', + '7af7e2f0-d5dc-11ec-87ac-bdfdb894c53d', expect.objectContaining({ enabled: true, }) From ea01bb8d0b149285a9bb9c14e581636ec471c04b Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Fri, 28 Oct 2022 16:29:09 -0400 Subject: [PATCH 17/34] adjust tests --- .../bulk_cruds/add_monitor_bulk.ts | 18 +++++++++++------- .../bulk_cruds/edit_monitor_bulk.ts | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts index 7279f636bec7ad..c35422ca95548a 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts @@ -35,8 +35,6 @@ export const createNewSavedObjectMonitorBulk = async ({ type: syntheticsMonitorType, attributes: formatSecrets({ ...monitor, - [ConfigKey.HEARTBEAT_ID]: monitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, - [ConfigKey.CONFIG_ID]: id, revision: 1, }), })); @@ -62,11 +60,17 @@ export const syncNewMonitorBulk = async ({ spaceId: string; }) => { let newMonitors: SavedObjectsBulkResponse | null = null; - - const monitorsToCreate = normalizedMonitors.map((monitor) => ({ - id: uuidV4(), - monitor: monitor as MonitorFields, - })); + const monitorsToCreate = normalizedMonitors.map((monitor) => { + const monitorSavedObjectId = uuidV4(); + return { + id: monitorSavedObjectId, + monitor: { + ...monitor, + [ConfigKey.CONFIG_ID]: monitorSavedObjectId, + [ConfigKey.HEARTBEAT_ID]: monitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || monitorSavedObjectId, + } as MonitorFields, + }; + }); try { const [createdMonitors, { syncErrors }] = await Promise.all([ diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/edit_monitor_bulk.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/edit_monitor_bulk.ts index 5c28bdab9d3d13..2a0b61401e68d9 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/edit_monitor_bulk.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/edit_monitor_bulk.ts @@ -60,7 +60,12 @@ export const syncEditedMonitorBulk = async ({ monitorsToUpdate.map(({ previousMonitor, monitorWithRevision }) => ({ type: syntheticsMonitorType, id: previousMonitor.id, - attributes: monitorWithRevision, + attributes: { + ...monitorWithRevision, + [ConfigKey.CONFIG_ID]: previousMonitor.id, + [ConfigKey.HEARTBEAT_ID]: + monitorWithRevision[ConfigKey.CUSTOM_HEARTBEAT_ID] || previousMonitor.id, + }, })) ); savedObjectsSuccessful = true; @@ -74,7 +79,12 @@ export const syncEditedMonitorBulk = async ({ try { const editSyncPromise = await syntheticsMonitorClient.editMonitors( monitorsToUpdate.map(({ normalizedMonitor, previousMonitor }) => ({ - monitor: normalizedMonitor as MonitorFields, + monitor: { + ...(normalizedMonitor as MonitorFields), + [ConfigKey.CONFIG_ID]: previousMonitor.id, + [ConfigKey.HEARTBEAT_ID]: + normalizedMonitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || previousMonitor.id, + }, id: previousMonitor.id, previousMonitor, })), From 53c1d9ede6c1fa68a27ca101fabfb7cbdc2c357c Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Fri, 28 Oct 2022 17:07:43 -0400 Subject: [PATCH 18/34] adjust tests --- .../monitor_details_link.tsx | 5 ++++- .../server/routes/monitor_cruds/add_monitor.ts | 4 ++-- .../routes/monitor_cruds/edit_monitor.test.ts | 2 -- .../routes/monitor_cruds/edit_monitor.ts | 18 +++++++++++------- .../rest/add_monitor_private_location.ts | 10 +++++++++- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/monitor_details_link.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/monitor_details_link.tsx index 8a92811b9b5c8b..701fd0d0580ed2 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/monitor_details_link.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/management/monitor_list_table/monitor_details_link.tsx @@ -31,7 +31,10 @@ export const MonitorDetailsLink = ({ const locationId = lastSelectedLocationId && monitorHasLocation ? lastSelectedLocationId : firstMonitorLocationId; - const monitorDetailLinkUrl = useMonitorDetailLocator({ monitorId: monitor.id, locationId }); + const monitorDetailLinkUrl = useMonitorDetailLocator({ + monitorId: monitor[ConfigKey.CONFIG_ID], + locationId, + }); return ( <> diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts index 1303c029bbc67e..61fa20225d5f3c 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts @@ -126,8 +126,6 @@ export const createNewSavedObjectMonitor = async ({ syntheticsMonitorType, formatSecrets({ ...normalizedMonitor, - [ConfigKey.HEARTBEAT_ID]: normalizedMonitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, - [ConfigKey.CONFIG_ID]: id, revision: 1, }), id @@ -167,6 +165,8 @@ export const syncNewMonitor = async ({ let monitorSavedObject: SavedObject | null = null; const monitorWithNamespace = { ...normalizedMonitor, + [ConfigKey.HEARTBEAT_ID]: normalizedMonitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || newMonitorId, + [ConfigKey.CONFIG_ID]: newMonitorId, [ConfigKey.NAMESPACE]: preserveNamespace ? normalizedMonitor[ConfigKey.NAMESPACE] : getMonitorNamespace(server, request, normalizedMonitor[ConfigKey.NAMESPACE]), diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.test.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.test.ts index 33227665ad692b..42999a49959cbc 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.test.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.test.ts @@ -16,7 +16,6 @@ import { import { UptimeServerSetup } from '../../legacy_uptime/lib/adapters'; import { SyntheticsService } from '../../synthetics_service/synthetics_service'; import { SyntheticsMonitorClient } from '../../synthetics_service/synthetics_monitor/synthetics_monitor_client'; -import { formatSecrets } from '../../synthetics_service/utils'; jest.mock('../telemetry/monitor_upgrade_sender', () => ({ sendTelemetryEvents: jest.fn(), @@ -94,7 +93,6 @@ describe('syncEditedMonitor', () => { it('includes the isEdit flag', async () => { await syncEditedMonitor({ normalizedMonitor: editedMonitor, - monitorWithRevision: formatSecrets(editedMonitor), previousMonitor, decryptedPreviousMonitor: previousMonitor as unknown as SavedObject, diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts index 6289fba1f7b019..910bca14fbb2c3 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/edit_monitor.ts @@ -90,7 +90,6 @@ export const editSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () => ( ...validationResult.decodedMonitor, revision: (previousMonitor.attributes[ConfigKey.REVISION] || 0) + 1, }; - const formattedMonitor = formatSecrets(monitorWithRevision); const { errors, editedMonitor: editedMonitorSavedObject } = await syncEditedMonitor({ server, @@ -99,8 +98,7 @@ export const editSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () => ( syntheticsMonitorClient, savedObjectsClient, request, - normalizedMonitor: validationResult.decodedMonitor, - monitorWithRevision: formattedMonitor, + normalizedMonitor: monitorWithRevision, spaceId, }); @@ -125,7 +123,6 @@ export const editSyntheticsMonitorRoute: SyntheticsRestApiRouteFactory = () => ( export const syncEditedMonitor = async ({ normalizedMonitor, - monitorWithRevision, previousMonitor, decryptedPreviousMonitor, server, @@ -135,7 +132,6 @@ export const syncEditedMonitor = async ({ spaceId, }: { normalizedMonitor: SyntheticsMonitor; - monitorWithRevision: SyntheticsMonitorWithSecrets; previousMonitor: SavedObject; decryptedPreviousMonitor: SavedObject; server: UptimeServerSetup; @@ -145,16 +141,24 @@ export const syncEditedMonitor = async ({ spaceId: string; }) => { try { + const monitorWithId = { + ...normalizedMonitor, + [ConfigKey.HEARTBEAT_ID]: + normalizedMonitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || previousMonitor.id, + [ConfigKey.CONFIG_ID]: previousMonitor.id, + }; + const formattedMonitor = formatSecrets(monitorWithId); + const editedSOPromise = savedObjectsClient.update( syntheticsMonitorType, previousMonitor.id, - monitorWithRevision + formattedMonitor ); const allPrivateLocations = await getSyntheticsPrivateLocations(savedObjectsClient); const editSyncPromise = syntheticsMonitorClient.editMonitors( - [{ monitor: normalizedMonitor as MonitorFields, id: previousMonitor.id, previousMonitor }], + [{ monitor: monitorWithId as MonitorFields, id: previousMonitor.id, previousMonitor }], request, savedObjectsClient, allPrivateLocations, diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts index cae29a4307717c..39b66982ec5013 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts @@ -148,7 +148,15 @@ export default function ({ getService }: FtrProviderContext) { .send(httpMonitorJson); expect(apiResponse.body.attributes).eql( - omit({ ...httpMonitorJson, revision: 2 }, secretKeys) + omit( + { + ...httpMonitorJson, + [ConfigKey.HEARTBEAT_ID]: apiResponse.body.id, + [ConfigKey.CONFIG_ID]: apiResponse.body.id, + revision: 2, + }, + secretKeys + ) ); }); From 6ba17df071e2f60556ceb6017e4de2ecbcba7011 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Fri, 28 Oct 2022 17:16:07 -0400 Subject: [PATCH 19/34] update selectors and hooks --- .../monitor_details/hooks/use_monitor_query_id.ts | 6 +----- .../monitor_details/hooks/use_selected_monitor.tsx | 4 ++-- .../monitor_summary/monitor_details_panel.tsx | 2 +- .../public/apps/synthetics/state/monitor_list/selectors.ts | 4 ++-- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_monitor_query_id.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_monitor_query_id.ts index 4b1e88461fa161..a96f449ca23103 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_monitor_query_id.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_monitor_query_id.ts @@ -14,9 +14,5 @@ export const useMonitorQueryId = () => { const { monitor } = useSelectedMonitor(); - if (monitor && monitor.origin === 'project') { - return monitor[ConfigKey.CUSTOM_HEARTBEAT_ID]!; - } - - return monitorId; + return monitor[ConfigKey.HEARTBEAT_ID] || monitorId; }; diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_selected_monitor.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_selected_monitor.tsx index 6e4d972fb445b9..28a4aa99898dfe 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_selected_monitor.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_selected_monitor.tsx @@ -8,6 +8,7 @@ import { useEffect, useMemo } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useParams } from 'react-router-dom'; +import { ConfigKey } from '../../../../../../common/runtime_types'; import { getMonitorAction, selectEncryptedSyntheticsSavedMonitors, @@ -20,10 +21,9 @@ export const useSelectedMonitor = () => { const monitorsList = useSelector(selectEncryptedSyntheticsSavedMonitors); const { loading: monitorListLoading } = useSelector(selectMonitorListState); const monitorFromList = useMemo( - () => monitorsList.find((monitor) => monitor.id === monitorId) ?? null, + () => monitorsList.find((monitor) => monitor[ConfigKey.CONFIG_ID] === monitorId) ?? null, [monitorId, monitorsList] ); - const { syntheticsMonitor, syntheticsMonitorLoading } = useSelector(selectorMonitorDetailsState); const dispatch = useDispatch(); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_details_panel.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_details_panel.tsx index 2fd702a187e36f..2faa662980ed1f 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_details_panel.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_details_panel.tsx @@ -40,7 +40,7 @@ export const MonitorDetailsPanel = () => { if ( (latestPing && latestPing?.config_id !== monitorId) || - (monitor && monitor.id !== monitorId) + (monitor && monitor[ConfigKey.CONFIG_ID] !== monitorId) ) { return ; } diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/selectors.ts b/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/selectors.ts index d53e6ea9f2b7f4..13ff6b8b148008 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/selectors.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/state/monitor_list/selectors.ts @@ -7,7 +7,7 @@ import { createSelector } from 'reselect'; -import { EncryptedSyntheticsSavedMonitor } from '../../../../../common/runtime_types'; +import { ConfigKey, EncryptedSyntheticsSavedMonitor } from '../../../../../common/runtime_types'; import { SyntheticsAppState } from '../root_reducer'; export const selectMonitorListState = (state: SyntheticsAppState) => state.monitorList; @@ -16,7 +16,7 @@ export const selectEncryptedSyntheticsSavedMonitors = createSelector( (state) => state.data.monitors.map((monitor) => ({ ...monitor.attributes, - id: monitor.id, + id: monitor.attributes[ConfigKey.HEARTBEAT_ID], updated_at: monitor.updated_at, })) as EncryptedSyntheticsSavedMonitor[] ); From d7a5fa9c4515a77d652fb04c814a8c670ea4c16f Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 1 Nov 2022 15:52:17 -0400 Subject: [PATCH 20/34] rename HEARTBEAT_ID to MONITOR_QUERY_ID --- .../synthetics/common/constants/monitor_defaults.ts | 2 +- .../synthetics/common/constants/monitor_management.ts | 2 +- .../synthetics/common/formatters/common/formatters.ts | 2 +- .../runtime_types/monitor_management/monitor_types.ts | 2 +- .../monitor_summary/test_runs_table.tsx | 2 +- .../components/fleet_package/common/normalizers.ts | 2 +- .../saved_objects/migrations/monitors/8.6.0.test.ts | 10 +++++----- .../lib/saved_objects/migrations/monitors/8.6.0.ts | 2 +- .../server/routes/monitor_cruds/add_monitor.ts | 2 +- .../monitor_cruds/bulk_cruds/add_monitor_bulk.ts | 2 +- .../routes/monitor_cruds/monitor_validation.test.ts | 2 +- .../server/synthetics_service/formatters/common.ts | 2 +- .../project_monitor/project_monitor_formatter.test.ts | 4 ++-- .../project_monitor/project_monitor_formatter.ts | 2 +- .../api_integration/apis/uptime/rest/add_monitor.ts | 4 ++-- .../apis/uptime/rest/add_monitor_private_location.ts | 4 ++-- .../api_integration/apis/uptime/rest/edit_monitor.ts | 4 ++-- .../api_integration/apis/uptime/rest/get_monitor.ts | 2 +- 18 files changed, 26 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts index f091e6d19d1d55..71db982ef750dd 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts @@ -48,7 +48,7 @@ export const DEFAULT_COMMON_FIELDS: CommonFields = { [ConfigKey.MONITOR_SOURCE_TYPE]: SourceType.UI, [ConfigKey.JOURNEY_ID]: '', [ConfigKey.CONFIG_HASH]: '', - [ConfigKey.HEARTBEAT_ID]: '', + [ConfigKey.MONITOR_QUERY_ID]: '', }; export const DEFAULT_BROWSER_ADVANCED_FIELDS: BrowserAdvancedFields = { diff --git a/x-pack/plugins/synthetics/common/constants/monitor_management.ts b/x-pack/plugins/synthetics/common/constants/monitor_management.ts index 7d367b0078a3b0..63f4a64447b3bc 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_management.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_management.ts @@ -78,7 +78,7 @@ export enum ConfigKey { ZIP_URL_TLS_KEY_PASSPHRASE = 'source.zip_url.ssl.key_passphrase', ZIP_URL_TLS_VERIFICATION_MODE = 'source.zip_url.ssl.verification_mode', ZIP_URL_TLS_VERSION = 'source.zip_url.ssl.supported_protocols', - HEARTBEAT_ID = 'id', + MONITOR_QUERY_ID = 'id', } export const secretKeys = [ diff --git a/x-pack/plugins/synthetics/common/formatters/common/formatters.ts b/x-pack/plugins/synthetics/common/formatters/common/formatters.ts index 7003c6251cab5d..794de9a6b62a4a 100644 --- a/x-pack/plugins/synthetics/common/formatters/common/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/common/formatters.ts @@ -33,7 +33,7 @@ export const commonFormatters: CommonFormatMap = { [ConfigKey.CUSTOM_HEARTBEAT_ID]: null, [ConfigKey.ORIGINAL_SPACE]: null, [ConfigKey.CONFIG_HASH]: null, - [ConfigKey.HEARTBEAT_ID]: null, + [ConfigKey.MONITOR_QUERY_ID]: null, }; export const arrayToJsonFormatter = (value: string[] = []) => diff --git a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts index 3dd10f854fab79..e76ab594e7de77 100644 --- a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts +++ b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_types.ts @@ -75,7 +75,7 @@ export const CommonFieldsCodec = t.intersection([ [ConfigKey.APM_SERVICE_NAME]: t.string, [ConfigKey.TAGS]: t.array(t.string), [ConfigKey.LOCATIONS]: t.array(t.union([MonitorServiceLocationCodec, PrivateLocationCodec])), - [ConfigKey.HEARTBEAT_ID]: t.string, + [ConfigKey.MONITOR_QUERY_ID]: t.string, [ConfigKey.CONFIG_ID]: t.string, }), t.partial({ diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/test_runs_table.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/test_runs_table.tsx index c779b28214c530..e7d90a64288db3 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/test_runs_table.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/test_runs_table.tsx @@ -140,7 +140,7 @@ export const TestRunsTable = ({ paginable = true, from, to }: TestRunsTableProps ]; const historyIdParam = - monitor?.[ConfigKey.CUSTOM_HEARTBEAT_ID] ?? monitor?.[ConfigKey.HEARTBEAT_ID]; + monitor?.[ConfigKey.CUSTOM_HEARTBEAT_ID] ?? monitor?.[ConfigKey.MONITOR_QUERY_ID]; return ( diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts index 46e60b0b2d2740..79e50bf8a9d96b 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/common/normalizers.ts @@ -97,5 +97,5 @@ export const commonNormalizers: CommonNormalizerMap = { [ConfigKey.CUSTOM_HEARTBEAT_ID]: getCommonNormalizer(ConfigKey.CUSTOM_HEARTBEAT_ID), [ConfigKey.ORIGINAL_SPACE]: getCommonNormalizer(ConfigKey.ORIGINAL_SPACE), [ConfigKey.CONFIG_HASH]: getCommonNormalizer(ConfigKey.CONFIG_HASH), - [ConfigKey.HEARTBEAT_ID]: getCommonNormalizer(ConfigKey.HEARTBEAT_ID), + [ConfigKey.MONITOR_QUERY_ID]: getCommonNormalizer(ConfigKey.MONITOR_QUERY_ID), }; diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts index d35dfaa25aa10f..68e3416174c8fd 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.test.ts @@ -135,7 +135,7 @@ describe('Case migrations v8.5.0 -> v8.6.0', () => { ...monitor850UI, attributes: { ...monitor850UI.attributes, - [ConfigKey.HEARTBEAT_ID]: monitor850UI.id, + [ConfigKey.MONITOR_QUERY_ID]: monitor850UI.id, [ConfigKey.CONFIG_ID]: monitor850UI.id, }, }); @@ -146,7 +146,7 @@ describe('Case migrations v8.5.0 -> v8.6.0', () => { ...monitor850Project, attributes: { ...monitor850Project.attributes, - [ConfigKey.HEARTBEAT_ID]: monitor850Project.attributes[ConfigKey.CUSTOM_HEARTBEAT_ID], + [ConfigKey.MONITOR_QUERY_ID]: monitor850Project.attributes[ConfigKey.CUSTOM_HEARTBEAT_ID], [ConfigKey.CONFIG_ID]: monitor850Project.id, }, }); @@ -166,7 +166,7 @@ describe('Case migrations v8.5.0 -> v8.6.0', () => { ...monitor850UI, attributes: { ...attributes, - [ConfigKey.HEARTBEAT_ID]: monitor850UI.id, + [ConfigKey.MONITOR_QUERY_ID]: monitor850UI.id, [ConfigKey.CONFIG_ID]: monitor850UI.id, }, }); @@ -188,7 +188,7 @@ describe('Case migrations v8.5.0 -> v8.6.0', () => { ...monitor850UI, attributes: { ...attributes, - [ConfigKey.HEARTBEAT_ID]: monitor850UI.id, + [ConfigKey.MONITOR_QUERY_ID]: monitor850UI.id, [ConfigKey.CONFIG_ID]: monitor850UI.id, }, }); @@ -208,7 +208,7 @@ describe('Case migrations v8.5.0 -> v8.6.0', () => { ...monitor850UI, attributes: { ...attributes, - [ConfigKey.HEARTBEAT_ID]: monitor850UI.id, + [ConfigKey.MONITOR_QUERY_ID]: monitor850UI.id, [ConfigKey.CONFIG_ID]: monitor850UI.id, }, }); diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts index e056b7d1a014e5..d4bea87a45bb45 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.6.0.ts @@ -26,7 +26,7 @@ export const migration860 = (encryptedSavedObjects: EncryptedSavedObjectsPluginS ...doc, attributes: { ...attributes, - [ConfigKey.HEARTBEAT_ID]: attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, + [ConfigKey.MONITOR_QUERY_ID]: attributes[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, [ConfigKey.CONFIG_ID]: id, }, }; diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts index 1303c029bbc67e..8b41b83c72e3c7 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts @@ -126,7 +126,7 @@ export const createNewSavedObjectMonitor = async ({ syntheticsMonitorType, formatSecrets({ ...normalizedMonitor, - [ConfigKey.HEARTBEAT_ID]: normalizedMonitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, + [ConfigKey.MONITOR_QUERY_ID]: normalizedMonitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, [ConfigKey.CONFIG_ID]: id, revision: 1, }), diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts index 7279f636bec7ad..89c08db5542e45 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/add_monitor_bulk.ts @@ -35,7 +35,7 @@ export const createNewSavedObjectMonitorBulk = async ({ type: syntheticsMonitorType, attributes: formatSecrets({ ...monitor, - [ConfigKey.HEARTBEAT_ID]: monitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, + [ConfigKey.MONITOR_QUERY_ID]: monitor[ConfigKey.CUSTOM_HEARTBEAT_ID] || id, [ConfigKey.CONFIG_ID]: id, revision: 1, }), diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.test.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.test.ts index 9c852bd994a6c9..b927e1a37e21af 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.test.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/monitor_validation.test.ts @@ -58,7 +58,7 @@ describe('validateMonitor', () => { [ConfigKey.MONITOR_TYPE]: DataStream.ICMP, [ConfigKey.NAME]: 'test-monitor-name', [ConfigKey.CONFIG_ID]: 'test-monitor-id', - [ConfigKey.HEARTBEAT_ID]: '', + [ConfigKey.MONITOR_QUERY_ID]: '', [ConfigKey.ENABLED]: true, [ConfigKey.TAGS]: testTags, [ConfigKey.SCHEDULE]: testSchedule, diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts index 18acd2e1378bab..5db57ee5fdeb8f 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts @@ -35,7 +35,7 @@ export const commonFormatters: CommonFormatMap = { [ConfigKey.CUSTOM_HEARTBEAT_ID]: null, [ConfigKey.ORIGINAL_SPACE]: null, [ConfigKey.CONFIG_HASH]: null, - [ConfigKey.HEARTBEAT_ID]: null, + [ConfigKey.MONITOR_QUERY_ID]: null, }; export const arrayFormatter = (value: string[] = []) => (value.length ? value : null); diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.test.ts index 4ca83d7b784610..2566c6a358fba7 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.test.ts @@ -472,7 +472,7 @@ describe('ProjectMonitorFormatter', () => { ...soData[0], attributes: { ...soData[0].attributes, - [ConfigKey.HEARTBEAT_ID]: expect.any(String), + [ConfigKey.MONITOR_QUERY_ID]: expect.any(String), [ConfigKey.CONFIG_ID]: expect.any(String), }, }), @@ -480,7 +480,7 @@ describe('ProjectMonitorFormatter', () => { ...soData[1], attributes: { ...soData[1].attributes, - [ConfigKey.HEARTBEAT_ID]: expect.any(String), + [ConfigKey.MONITOR_QUERY_ID]: expect.any(String), [ConfigKey.CONFIG_ID]: expect.any(String), }, }), diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts index ad47edd3d6b196..67a4433bf5779c 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/project_monitor_formatter.ts @@ -375,7 +375,7 @@ export class ProjectMonitorFormatter { const previousMonitor = monitors[i].previousMonitor; const normalizedMonitor = monitors[i].monitor; - const keysToOmit = [ConfigKey.REVISION, ConfigKey.HEARTBEAT_ID, ConfigKey.CONFIG_ID]; + const keysToOmit = [ConfigKey.REVISION, ConfigKey.MONITOR_QUERY_ID, ConfigKey.CONFIG_ID]; const { attributes: normalizedPreviousMonitorAttributes } = normalizeSecrets(decryptedPreviousMonitor); const hasMonitorBeenEdited = !isEqual( diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts index 7b76de68b4deb8..7aa6222b380e72 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor.ts @@ -52,7 +52,7 @@ export default function ({ getService }: FtrProviderContext) { omit( { ...newMonitor, - [ConfigKey.HEARTBEAT_ID]: apiResponse.body.id, + [ConfigKey.MONITOR_QUERY_ID]: apiResponse.body.id, [ConfigKey.CONFIG_ID]: apiResponse.body.id, }, secretKeys @@ -115,7 +115,7 @@ export default function ({ getService }: FtrProviderContext) { { ...DEFAULT_FIELDS[DataStream.HTTP], ...newMonitor, - [ConfigKey.HEARTBEAT_ID]: apiResponse.body.id, + [ConfigKey.MONITOR_QUERY_ID]: apiResponse.body.id, [ConfigKey.CONFIG_ID]: apiResponse.body.id, revision: 1, }, diff --git a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts index cae29a4307717c..0119e17b56f0c7 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/add_monitor_private_location.ts @@ -104,7 +104,7 @@ export default function ({ getService }: FtrProviderContext) { omit( { ...newMonitor, - [ConfigKey.HEARTBEAT_ID]: apiResponse.body.id, + [ConfigKey.MONITOR_QUERY_ID]: apiResponse.body.id, [ConfigKey.CONFIG_ID]: apiResponse.body.id, }, secretKeys @@ -278,7 +278,7 @@ export default function ({ getService }: FtrProviderContext) { omit( { ...monitor, - [ConfigKey.HEARTBEAT_ID]: apiResponse.body.id, + [ConfigKey.MONITOR_QUERY_ID]: apiResponse.body.id, [ConfigKey.CONFIG_ID]: apiResponse.body.id, [ConfigKey.NAMESPACE]: formatKibanaNamespace(SPACE_ID), }, diff --git a/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts index a91c066ddee801..02a1633bcd892e 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/edit_monitor.ts @@ -65,7 +65,7 @@ export default function ({ getService }: FtrProviderContext) { omit( { ...newMonitor, - [ConfigKey.HEARTBEAT_ID]: monitorId, + [ConfigKey.MONITOR_QUERY_ID]: monitorId, [ConfigKey.CONFIG_ID]: monitorId, }, secretKeys @@ -129,7 +129,7 @@ export default function ({ getService }: FtrProviderContext) { omit( { ...newMonitor, - [ConfigKey.HEARTBEAT_ID]: monitorId, + [ConfigKey.MONITOR_QUERY_ID]: monitorId, [ConfigKey.CONFIG_ID]: monitorId, }, secretKeys diff --git a/x-pack/test/api_integration/apis/uptime/rest/get_monitor.ts b/x-pack/test/api_integration/apis/uptime/rest/get_monitor.ts index a4caca5914cfaf..42bc7e8111e4fd 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/get_monitor.ts +++ b/x-pack/test/api_integration/apis/uptime/rest/get_monitor.ts @@ -97,7 +97,7 @@ export default function ({ getService }: FtrProviderContext) { expect(apiResponse.body.attributes).eql({ ...monitors[0], - [ConfigKey.HEARTBEAT_ID]: apiResponse.body.id, + [ConfigKey.MONITOR_QUERY_ID]: apiResponse.body.id, [ConfigKey.CONFIG_ID]: apiResponse.body.id, revision: 1, }); From 9e6297855b9cff9bdd2dfc10a6b8518a6be58b0d Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Thu, 3 Nov 2022 09:25:59 -0400 Subject: [PATCH 21/34] update flaky test --- .../e2e/journeys/synthetics/getting_started.journey.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/x-pack/plugins/synthetics/e2e/journeys/synthetics/getting_started.journey.ts b/x-pack/plugins/synthetics/e2e/journeys/synthetics/getting_started.journey.ts index 2d9f1f888a9361..bffc68911b2f68 100644 --- a/x-pack/plugins/synthetics/e2e/journeys/synthetics/getting_started.journey.ts +++ b/x-pack/plugins/synthetics/e2e/journeys/synthetics/getting_started.journey.ts @@ -7,6 +7,7 @@ import { journey, step, expect, before, Page } from '@elastic/synthetics'; import { syntheticsAppPageProvider } from '../../page_objects/synthetics_app'; +import { cleanTestMonitors } from './services/add_monitor'; journey(`Getting Started Page`, async ({ page, params }: { page: Page; params: any }) => { const syntheticsApp = syntheticsAppPageProvider({ page, kibanaUrl: params.kibanaUrl }); @@ -19,6 +20,7 @@ journey(`Getting Started Page`, async ({ page, params }: { page: Page; params: a }; before(async () => { + await cleanTestMonitors(params); await syntheticsApp.waitForLoadingToFinish(); }); From b81bd78402b3fb13b96143ddcc5d46466fd0799b Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 3 Nov 2022 17:42:50 +0000 Subject: [PATCH 22/34] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../synthetics/server/routes/monitor_cruds/add_monitor.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts index d4b53791782847..dad93a0f60aae9 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor.ts @@ -132,9 +132,9 @@ export const createNewSavedObjectMonitor = async ({ }), id ? { - id, - overwrite: true, - } + id, + overwrite: true, + } : undefined ); }; From 739b1f600cedaa9e4da374753a4818c5cb653c63 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Thu, 3 Nov 2022 14:00:04 -0400 Subject: [PATCH 23/34] adjust id uses --- .../monitor_summary/duration_sparklines.tsx | 7 ++--- .../monitors_page/hooks/use_inline_errors.ts | 2 +- .../hooks/use_inline_errors_count.ts | 2 +- .../synthetics/hooks/use_last_x_checks.ts | 2 +- .../hooks/use_inline_errors.test.tsx | 2 +- .../hooks/use_inline_errors.ts | 2 +- .../hooks/use_inline_errors_count.ts | 2 +- .../monitor_list/actions.tsx | 15 +++++++--- .../monitor_list/monitor_list.tsx | 2 +- .../synthetics/check_steps/stderr_logs.tsx | 6 ++-- .../check_steps/use_std_error_logs.ts | 28 +++++++++---------- 11 files changed, 38 insertions(+), 32 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_sparklines.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_sparklines.tsx index eee490054a2983..1c3ce36cd801e9 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_sparklines.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_sparklines.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { useKibana } from '@kbn/kibana-react-plugin/public'; import { ReportTypes, useTheme } from '@kbn/observability-plugin/public'; -import { useParams } from 'react-router-dom'; +import { useMonitorQueryId } from '../hooks/use_monitor_query_id'; import { ClientPluginsStart } from '../../../../../plugin'; interface DurationSparklinesProps { @@ -22,8 +22,7 @@ export const DurationSparklines = (props: DurationSparklinesProps) => { observability: { ExploratoryViewEmbeddable }, }, } = useKibana(); - const { monitorId } = useParams<{ monitorId: string }>(); - + const monitorId = useMonitorQueryId(); const theme = useTheme(); return ( @@ -40,7 +39,7 @@ export const DurationSparklines = (props: DurationSparklinesProps) => { name: 'Monitor duration', dataType: 'synthetics', selectedMetricField: 'monitor.duration.us', - reportDefinitions: { config_id: [monitorId] }, + reportDefinitions: { 'monitor.id': [monitorId] }, color: theme.eui.euiColorVis1, }, ]} diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_inline_errors.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_inline_errors.ts index c8dac37aebcb7c..800692d2847264 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_inline_errors.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_inline_errors.ts @@ -89,7 +89,7 @@ export function useInlineErrors({ filter: getInlineErrorFilters(), }, }, - collapse: { field: 'config_id' }, + collapse: { field: 'monitor.id' }, sort: sortFieldMap[sortField] ? [{ [sortFieldMap[sortField]]: sortOrder }] : undefined, }, }, diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_inline_errors_count.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_inline_errors_count.ts index be6e80e3f84695..0ef0c8d3bb2020 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_inline_errors_count.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitors_page/hooks/use_inline_errors_count.ts @@ -30,7 +30,7 @@ export function useInlineErrorsCount() { }, aggs: { total: { - cardinality: { field: 'config_id' }, + cardinality: { field: 'monitor.id' }, }, }, }, diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_last_x_checks.ts b/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_last_x_checks.ts index 17455ba09bb50d..fd9ee82ecbb9c7 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_last_x_checks.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/hooks/use_last_x_checks.ts @@ -44,7 +44,7 @@ export function useLastXChecks({ EXCLUDE_RUN_ONCE_FILTER, { term: { - config_id: monitorId, + 'monitor.id': monitorId, }, }, ], diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors.test.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors.test.tsx index 5f331ee5f48c80..5d5aad7a37a875 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors.test.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors.test.tsx @@ -33,7 +33,7 @@ describe('useInlineErrors', function () { 3, { body: { - collapse: { field: 'config_id' }, + collapse: { field: 'monitor.id' }, query: { bool: { filter: [ diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors.ts b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors.ts index 9970622ca416b4..9086ce641870db 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors.ts +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors.ts @@ -89,7 +89,7 @@ export function useInlineErrors({ filter: getInlineErrorFilters(), }, }, - collapse: { field: 'config_id' }, + collapse: { field: 'monitor.id' }, sort: [{ [sortFieldMap[sortField]]: sortOrder }], }, }, diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors_count.ts b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors_count.ts index dc69346e6c9a50..154d7921d3b75f 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors_count.ts +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors_count.ts @@ -30,7 +30,7 @@ export function useInlineErrorsCount() { }, aggs: { total: { - cardinality: { field: 'config_id' }, + cardinality: { field: 'monitor.id' }, }, }, }, diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/actions.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/actions.tsx index 2532b82f389b49..fac6e2d7b2bf3e 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/actions.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/actions.tsx @@ -23,7 +23,7 @@ import { } from '../../../../../common/runtime_types'; interface Props { - id: string; + configId: string; name: string; isDisabled?: boolean; onUpdate: () => void; @@ -31,12 +31,19 @@ interface Props { monitors: MonitorManagementListResult['monitors']; } -export const Actions = ({ id, name, onUpdate, isDisabled, errorSummaries, monitors }: Props) => { +export const Actions = ({ + configId, + name, + onUpdate, + isDisabled, + errorSummaries, + monitors, +}: Props) => { const { basePath } = useContext(UptimeSettingsContext); - let errorSummary = errorSummaries?.find((summary) => summary.config_id === id); + let errorSummary = errorSummaries?.find((summary) => summary.config_id === configId); - const monitor = monitors.find((monitorT) => monitorT.id === id); + const monitor = monitors.find((monitorT) => monitorT.id === configId); const isProjectMonitor = (monitor?.attributes as BrowserFields)[ConfigKey.MONITOR_SOURCE_TYPE] === SourceType.PROJECT; diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/monitor_list.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/monitor_list.tsx index 3195e0e09f8224..079ee513cc7ae9 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/monitor_list.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/monitor_list.tsx @@ -206,7 +206,7 @@ export const MonitorManagementList = ({ }), render: (fields: EncryptedSyntheticsMonitorWithId) => ( >; - const { items, loading } = useStdErrorLogs({ configId, checkGroup }); + const { items, loading } = useStdErrorLogs({ monitorId, checkGroup }); const { discover, observability } = useKibana().services; diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/synthetics/check_steps/use_std_error_logs.ts b/x-pack/plugins/synthetics/public/legacy_uptime/components/synthetics/check_steps/use_std_error_logs.ts index d6abd2445a9a7b..f7da5126d3ef92 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/synthetics/check_steps/use_std_error_logs.ts +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/synthetics/check_steps/use_std_error_logs.ts @@ -11,16 +11,16 @@ import { selectDynamicSettings } from '../../../state/selectors'; import { Ping } from '../../../../../common/runtime_types'; export const useStdErrorLogs = ({ - configId, + monitorId, checkGroup, }: { - configId?: string; + monitorId?: string; checkGroup?: string; }) => { const { settings } = useSelector(selectDynamicSettings); const { data, loading } = useEsSearch( createEsParams({ - index: !configId && !checkGroup ? '' : settings?.heartbeatIndices, + index: !monitorId && !checkGroup ? '' : settings?.heartbeatIndices, body: { size: 1000, query: { @@ -31,23 +31,23 @@ export const useStdErrorLogs = ({ 'synthetics.type': 'stderr', }, }, - ...(configId + ...(monitorId ? [ - { - term: { - config_id: configId, - }, + { + term: { + 'monitor.id': monitorId, }, - ] + }, + ] : []), ...(checkGroup ? [ - { - term: { - 'monitor.check_group': checkGroup, - }, + { + term: { + 'monitor.check_group': checkGroup, }, - ] + }, + ] : []), ], }, From 1fc1bd083356fdf6a97aa8f90b473b413394d6f6 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 3 Nov 2022 18:35:53 +0000 Subject: [PATCH 24/34] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../check_steps/use_std_error_logs.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/synthetics/check_steps/use_std_error_logs.ts b/x-pack/plugins/synthetics/public/legacy_uptime/components/synthetics/check_steps/use_std_error_logs.ts index f7da5126d3ef92..c2ef56213c48ea 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/synthetics/check_steps/use_std_error_logs.ts +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/synthetics/check_steps/use_std_error_logs.ts @@ -33,21 +33,21 @@ export const useStdErrorLogs = ({ }, ...(monitorId ? [ - { - term: { - 'monitor.id': monitorId, + { + term: { + 'monitor.id': monitorId, + }, }, - }, - ] + ] : []), ...(checkGroup ? [ - { - term: { - 'monitor.check_group': checkGroup, + { + term: { + 'monitor.check_group': checkGroup, + }, }, - }, - ] + ] : []), ], }, From bc09dc7c57a1284b40892d4e6f79779d116343f1 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 8 Nov 2022 08:41:30 -0500 Subject: [PATCH 25/34] update monitor list tests --- .../monitor_list/actions.test.tsx | 6 +++-- .../monitor_list/actions.tsx | 4 ++-- .../monitor_list/delete_monitor.test.tsx | 23 ++++++++++--------- .../monitor_list/delete_monitor.tsx | 8 +++---- .../monitor_list/monitor_list.test.tsx | 1 + 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/actions.test.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/actions.test.tsx index 589403dcfee0a5..930d89f97af2af 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/actions.test.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/actions.test.tsx @@ -23,7 +23,7 @@ describe('', () => { it('navigates to edit monitor flow on edit pencil', () => { render( ', () => { { id: 'test-id', attributes: { + [ConfigKey.CONFIG_ID]: 'test-id', [ConfigKey.MONITOR_SOURCE_TYPE]: SourceType.PROJECT, } as BrowserFields, }, @@ -48,13 +49,14 @@ describe('', () => { it('disables deleting for project monitors', () => { render( @@ -87,7 +87,7 @@ export const Actions = ({ diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/delete_monitor.test.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/delete_monitor.test.tsx index 8aa30dfde72ab4..e708be5c8921f8 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/delete_monitor.test.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/delete_monitor.test.tsx @@ -6,8 +6,7 @@ */ import React from 'react'; -import { screen } from '@testing-library/react'; -import userEvent from '@testing-library/user-event'; +import { screen, fireEvent } from '@testing-library/react'; import { render } from '../../../lib/helper/rtl_helpers'; import * as fetchers from '../../../state/api/monitor_management'; import { FETCH_STATUS, useFetcher as originalUseFetcher } from '@kbn/observability-plugin/public'; @@ -21,7 +20,7 @@ import { SourceType, } from '../../../../../common/runtime_types'; -describe('', () => { +describe('', () => { const onUpdate = jest.fn(); const useFetcher = spyOnUseFetcher({}); @@ -29,13 +28,13 @@ describe('', () => { useFetcher.mockImplementation(originalUseFetcher); const deleteMonitor = jest.spyOn(fetchers, 'deleteMonitor'); const id = 'test-id'; - render(); + render(); expect(deleteMonitor).not.toBeCalled(); - userEvent.click(screen.getByRole('button')); + fireEvent.click(screen.getByRole('button')); - userEvent.click(screen.getByTestId('confirmModalConfirmButton')); + fireEvent.click(screen.getByTestId('confirmModalConfirmButton')); expect(deleteMonitor).toBeCalledWith({ id }); }); @@ -45,15 +44,16 @@ describe('', () => { const name = 'sample monitor'; render( ', () => { /> ); - userEvent.click(screen.getByLabelText('Delete monitor')); + fireEvent.click(screen.getByLabelText('Delete monitor')); expect(onUpdate).toHaveBeenCalled(); }); @@ -75,15 +75,16 @@ describe('', () => { }); render( void; @@ -36,9 +36,9 @@ export const DeleteMonitor = ({ const { status } = useFetcher(() => { if (isDeleting) { - return deleteMonitor({ id }); + return deleteMonitor({ id: configId }); } - }, [id, isDeleting]); + }, [configId, isDeleting]); const handleDelete = () => { showDeleteModal(); diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/monitor_list.test.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/monitor_list.test.tsx index d35ee0e41cf943..73d0dd1bbaa95d 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/monitor_list.test.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/monitor_list/monitor_list.test.tsx @@ -29,6 +29,7 @@ describe('', () => { id: `test-monitor-id-${i}`, updated_at: '123', attributes: { + config_id: `test-monitor-id-${i}`, name: `test-monitor-${i}`, enabled: true, schedule: { From 7571acd64a49274291844896a54949e63bcaa3b6 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 8 Nov 2022 08:55:44 -0500 Subject: [PATCH 26/34] adjust inline error tests --- .../monitor_management/hooks/use_inline_errors_count.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors_count.test.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors_count.test.tsx index e12dbe88d2d2b0..4c9d555a5cdec2 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors_count.test.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/monitor_management/hooks/use_inline_errors_count.test.tsx @@ -33,7 +33,7 @@ describe('useInlineErrorsCount', function () { 2, { body: { - aggs: { total: { cardinality: { field: 'config_id' } } }, + aggs: { total: { cardinality: { field: 'monitor.id' } } }, query: { bool: { filter: [ From b5fa7c7da155fbcc3dd9132c541059c119826824 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 8 Nov 2022 08:58:27 -0500 Subject: [PATCH 27/34] adjusts edit monitor api tests --- x-pack/test/api_integration/apis/synthetics/edit_monitor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/api_integration/apis/synthetics/edit_monitor.ts b/x-pack/test/api_integration/apis/synthetics/edit_monitor.ts index 6d9b1db7a753fc..209ba0c4d9a38c 100644 --- a/x-pack/test/api_integration/apis/synthetics/edit_monitor.ts +++ b/x-pack/test/api_integration/apis/synthetics/edit_monitor.ts @@ -99,7 +99,7 @@ export default function ({ getService }: FtrProviderContext) { }; const modifiedMonitor = { - ...newMonitor, + ...savedMonitor, ...updates, [ConfigKey.METADATA]: { ...newMonitor[ConfigKey.METADATA], From d2ad438ec761c617b66b90beabeac94f01638422 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 8 Nov 2022 10:39:42 -0500 Subject: [PATCH 28/34] adjust query ids --- .../monitor_details/hooks/use_monitor_query_id.ts | 5 +---- .../monitor_details/hooks/use_ping_statuses.tsx | 9 ++++++--- .../monitor_details/hooks/use_selected_monitor.tsx | 5 +++-- .../monitor_details/monitor_errors/failed_tests.tsx | 8 ++++++-- .../monitor_details/monitor_errors/monitor_errors.tsx | 8 ++++---- .../monitor_status/monitor_status_header.tsx | 8 ++++++-- .../monitor_summary/availability_panel.tsx | 4 ++++ .../public/apps/synthetics/state/monitor_details/api.ts | 1 - .../monitor_management/monitor_list/monitor_list.tsx | 3 +-- .../synthetics/server/common/pings/query_pings.ts | 2 +- 10 files changed, 32 insertions(+), 21 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_monitor_query_id.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_monitor_query_id.ts index 91bdbbfc262c84..ab908652d23846 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_monitor_query_id.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_monitor_query_id.ts @@ -5,14 +5,11 @@ * 2.0. */ -import { useParams } from 'react-router-dom'; import { ConfigKey } from '../../../../../../common/runtime_types'; import { useSelectedMonitor } from './use_selected_monitor'; export const useMonitorQueryId = () => { - const { monitorId } = useParams<{ monitorId: string }>(); - const { monitor } = useSelectedMonitor(); - return monitor[ConfigKey.MONITOR_QUERY_ID] || monitorId; + return monitor?.[ConfigKey.MONITOR_QUERY_ID]; }; diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_ping_statuses.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_ping_statuses.tsx index ca107c7af3ae1a..cb408678c022cd 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_ping_statuses.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_ping_statuses.tsx @@ -8,7 +8,7 @@ import { useEffect, useCallback, useRef } from 'react'; import { useSelector, useDispatch } from 'react-redux'; -import { PingStatus } from '../../../../../../common/runtime_types'; +import { ConfigKey, PingStatus } from '../../../../../../common/runtime_types'; import { getMonitorPingStatusesAction, selectIsMonitorStatusesLoading, @@ -35,8 +35,11 @@ export const usePingStatuses = ({ const location = useSelectedLocation(); const pingStatusesSelector = useCallback(() => { - return selectPingStatusesForMonitorAndLocationAsc(monitor?.id ?? '', location?.label ?? ''); - }, [monitor?.id, location?.label]); + return selectPingStatusesForMonitorAndLocationAsc( + monitor?.[ConfigKey.CONFIG_ID] ?? '', + location?.label ?? '' + ); + }, [monitor, location?.label]); const isLoading = useSelector(selectIsMonitorStatusesLoading); const pingStatuses = useSelector(pingStatusesSelector()) as PingStatus[]; const dispatch = useDispatch(); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_selected_monitor.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_selected_monitor.tsx index 28a4aa99898dfe..12fb086326f003 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_selected_monitor.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/hooks/use_selected_monitor.tsx @@ -27,9 +27,10 @@ export const useSelectedMonitor = () => { const { syntheticsMonitor, syntheticsMonitorLoading } = useSelector(selectorMonitorDetailsState); const dispatch = useDispatch(); - const isMonitorFromListValid = monitorId && monitorFromList && monitorFromList?.id === monitorId; + const isMonitorFromListValid = + monitorId && monitorFromList && monitorFromList[ConfigKey.CONFIG_ID] === monitorId; const isLoadedSyntheticsMonitorValid = - monitorId && syntheticsMonitor && syntheticsMonitor?.id === monitorId; + monitorId && syntheticsMonitor && syntheticsMonitor[ConfigKey.CONFIG_ID] === monitorId; const availableMonitor = isLoadedSyntheticsMonitorValid ? syntheticsMonitor : isMonitorFromListValid diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_errors/failed_tests.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_errors/failed_tests.tsx index 8db063f50d63a9..c801036e78fd58 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_errors/failed_tests.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_errors/failed_tests.tsx @@ -7,7 +7,7 @@ import React from 'react'; import { useKibana } from '@kbn/kibana-react-plugin/public'; -import { useParams } from 'react-router-dom'; +import { useMonitorQueryId } from '../hooks/use_monitor_query_id'; import { ClientPluginsStart } from '../../../../../plugin'; export const MonitorFailedTests = ({ time }: { time: { to: string; from: string } }) => { @@ -15,7 +15,11 @@ export const MonitorFailedTests = ({ time }: { time: { to: string; from: string const { ExploratoryViewEmbeddable } = observability; - const { monitorId } = useParams<{ monitorId: string }>(); + const monitorId = useMonitorQueryId(); + + if (!monitorId) { + return null; + } return ( { - +

{OVERVIEW_LABEL}

@@ -52,7 +52,7 @@ export const MonitorErrors = () => {
- +

{FAILED_TESTS_LABEL}

@@ -62,7 +62,7 @@ export const MonitorErrors = () => {
- +

{ERRORS_LABEL}

@@ -70,7 +70,7 @@ export const MonitorErrors = () => {
- +

{FAILED_TESTS_BY_STEPS_LABEL} diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_status/monitor_status_header.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_status/monitor_status_header.tsx index 8de032f1ccd536..dc01cf6c97e5ad 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_status/monitor_status_header.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_status/monitor_status_header.tsx @@ -17,6 +17,7 @@ import { import { css } from '@emotion/css'; import { useHistory } from 'react-router-dom'; +import { ConfigKey } from '../../../../../../common/runtime_types'; import { MONITOR_HISTORY_ROUTE } from '../../../../../../common/constants'; import { stringifyUrlParams } from '../../../utils/url_params'; import { useGetUrlParams } from '../../../hooks'; @@ -69,9 +70,12 @@ export const MonitorStatusHeader = ({ { const monitorId = useMonitorQueryId(); + if (!monitorId) { + return null; + } + return ( list.monitors.map((monitor) => ({ ...monitor.attributes, - id: monitor.id, })), [list.monitors] ); @@ -192,7 +191,7 @@ export const MonitorManagementList = ({ }), render: (_enabled: boolean, monitor: EncryptedSyntheticsMonitorWithId) => ( ( bool: { filter: [ { range: { '@timestamp': { gte: from, lte: to } } }, - ...(monitorId ? [{ term: { config_id: monitorId } }] : []), + ...(monitorId ? [{ term: { 'monitor.id': monitorId } }] : []), ...(status ? [{ term: { 'monitor.status': status } }] : []), ] as QueryDslQueryContainer[], ...REMOVE_NON_SUMMARY_BROWSER_CHECKS, From 3b5727c8ba00d182af244a3babead9d0acc9eccb Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 8 Nov 2022 17:41:43 -0500 Subject: [PATCH 29/34] adjust types --- .../monitor_details/monitor_errors/failed_tests_count.tsx | 4 ++++ .../monitor_summary/availability_sparklines.tsx | 4 ++++ .../monitor_details/monitor_summary/duration_panel.tsx | 4 ++++ .../monitor_details/monitor_summary/duration_sparklines.tsx | 4 ++++ .../monitor_details/monitor_summary/duration_trend.tsx | 4 ++++ .../monitor_details/monitor_summary/monitor_errors_count.tsx | 4 ++++ .../monitor_details/monitor_summary/step_duration_panel.tsx | 4 ++++ 7 files changed, 28 insertions(+) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_errors/failed_tests_count.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_errors/failed_tests_count.tsx index c04c959d077dbc..37e5a2cc97d229 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_errors/failed_tests_count.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_errors/failed_tests_count.tsx @@ -17,6 +17,10 @@ export const FailedTestsCount = (time: { to: string; from: string }) => { const monitorId = useMonitorQueryId(); + if (!monitorId) { + return null; + } + return ( { const theme = useTheme(); + if (!monitorId) { + return null; + } + return ( { } = useKibana(); const monitorId = useMonitorQueryId(); + if (!monitorId) { + return null; + } + return ( { const monitorId = useMonitorQueryId(); const theme = useTheme(); + if (!monitorId) { + return null; + } + return ( <> { const metricsToShow = ['min', 'max', 'median', '25th', '75th']; + if (!monitorId) { + return null; + } + return ( { const monitorId = useMonitorQueryId(); + if (!monitorId) { + return null; + } + return ( { const isBrowser = monitor?.type === 'browser'; + if (!monitorId) { + return null; + } + return ( From df6fd2330e23fd3f84ad7ab86fa283218de90435 Mon Sep 17 00:00:00 2001 From: shahzad31 Date: Thu, 10 Nov 2022 12:18:37 +0100 Subject: [PATCH 30/34] resolve conflicts --- .../monitor_details/monitor_summary/duration_trend.tsx | 6 +----- .../monitor_summary/monitor_errors_count.tsx | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx index ad57da33ae7b21..c77fde3775114c 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx @@ -26,11 +26,7 @@ export const MonitorDurationTrend = (props: MonitorDurationTrendProps) => { const metricsToShow = ['min', 'max', 'median', '25th', '75th']; - if (!selectedLocation) { - return null; - } - - if (!monitorId) { + if (!selectedLocation || !monitorId) { return null; } diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_errors_count.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_errors_count.tsx index 1b49c4bc46591e..071b35f51b0282 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_errors_count.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_errors_count.tsx @@ -24,13 +24,9 @@ export const MonitorErrorsCount = (props: MonitorErrorsCountProps) => { const monitorId = useMonitorQueryId(); - if (!monitorId) { - return null; - } - const selectedLocation = useSelectedLocation(); - if (!selectedLocation) { + if (!selectedLocation || !monitorId) { return null; } From 30823eb8a0f3584fd8fddc2e70952b7779d76003 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 10 Nov 2022 11:51:52 +0000 Subject: [PATCH 31/34] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../monitor_details/monitor_summary/availability_sparklines.tsx | 1 - .../monitor_details/monitor_summary/duration_panel.tsx | 1 - .../monitor_details/monitor_summary/duration_sparklines.tsx | 1 - 3 files changed, 3 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/availability_sparklines.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/availability_sparklines.tsx index 064b760c37adc0..2197d443b469ca 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/availability_sparklines.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/availability_sparklines.tsx @@ -33,7 +33,6 @@ export const AvailabilitySparklines = (props: AvailabilitySparklinesProps) => { return null; } - return ( { return null; } - return ( { return null; } - return ( <> Date: Mon, 14 Nov 2022 17:04:21 +0100 Subject: [PATCH 32/34] update types --- .../monitor_summary/monitor_complete_count.tsx | 4 ++++ .../monitor_summary/monitor_complete_sparklines.tsx | 4 ++++ .../monitor_summary/monitor_total_runs_count.tsx | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_complete_count.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_complete_count.tsx index 7740ba9ce0670e..fd2e9f5f1b2bc3 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_complete_count.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/monitor_complete_count.tsx @@ -23,6 +23,10 @@ export const MonitorCompleteCount = (props: MonitorCompleteCountProps) => { const monitorId = useMonitorQueryId(); + if (!monitorId) { + return null; + } + return ( { const { euiTheme } = useEuiTheme(); + if (!monitorId) { + return null; + } + return ( { const monitorId = useMonitorQueryId(); + if (!monitorId) { + return null; + } + return ( Date: Tue, 15 Nov 2022 11:09:35 +0100 Subject: [PATCH 33/34] Update x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx --- .../monitor_details/monitor_summary/duration_trend.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx index 057a0675cc1a73..362c6a61ef3874 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx @@ -25,7 +25,6 @@ export const MonitorDurationTrend = (props: MonitorDurationTrendProps) => { const monitorId = useMonitorQueryId(); const selectedLocation = useSelectedLocation(); - const metricsToShow = ['min', 'max', 'median', '25th', '75th']; if (!selectedLocation || !monitorId) { return null; From d4da6f8bedeefeb0647c6390931cb894109d526d Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 15 Nov 2022 10:15:55 +0000 Subject: [PATCH 34/34] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../monitor_details/monitor_summary/duration_trend.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx index 362c6a61ef3874..3df65533802474 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_details/monitor_summary/duration_trend.tsx @@ -25,7 +25,6 @@ export const MonitorDurationTrend = (props: MonitorDurationTrendProps) => { const monitorId = useMonitorQueryId(); const selectedLocation = useSelectedLocation(); - if (!selectedLocation || !monitorId) { return null; }