From 9444b706bb513bd580d8296bd6e15aded8a18ced Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 4 Oct 2022 12:57:41 -0600 Subject: [PATCH] [Synthetics] preserve id field on monitor attributes (#142478) (#142648) * synthetics - preserve id field on monitor attributes * adjust tests * [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' * adjust jest tests * adjust tests * adjust types * adjust tests * adjust types * update tests * [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 61342b30738c499ac5b078d912d18cd8b10c10cf) Co-authored-by: Dominique Clarke --- .../synthetics/common/constants/monitor_defaults.ts | 12 +++++++++--- .../common/constants/monitor_management.ts | 3 +++ .../common/formatters/common/formatters.ts | 3 +++ .../synthetics/common/formatters/tcp/formatters.ts | 1 + .../monitor_management/monitor_types.ts | 4 ++++ .../monitor_add_edit/form/formatter.test.tsx | 3 +++ .../components/fleet_package/common/normalizers.ts | 3 +++ .../components/fleet_package/tcp/normalizers.ts | 1 + .../server/synthetics_service/formatters/common.ts | 3 +++ .../server/synthetics_service/formatters/tcp.ts | 1 + .../normalizers/browser_monitor.test.ts | 3 +++ .../project_monitor/normalizers/http_monitor.test.ts | 2 ++ .../project_monitor/normalizers/icmp_monitor.test.ts | 3 +++ .../project_monitor/normalizers/tcp_monitor.test.ts | 6 ++++++ .../project_monitor_formatter.test.ts | 2 ++ .../apis/uptime/rest/add_monitor_project.ts | 5 +++++ .../apis/uptime/rest/fixtures/browser_monitor.json | 3 ++- .../apis/uptime/rest/fixtures/http_monitor.json | 3 ++- .../apis/uptime/rest/fixtures/icmp_monitor.json | 3 ++- .../apis/uptime/rest/fixtures/tcp_monitor.json | 4 +++- 20 files changed, 61 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts index a926cba109e62..ff2aefa12d94d 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts @@ -47,6 +47,9 @@ export const DEFAULT_COMMON_FIELDS: CommonFields = { [ConfigKey.NAMESPACE]: DEFAULT_NAMESPACE_STRING, [ConfigKey.MONITOR_SOURCE_TYPE]: SourceType.UI, [ConfigKey.JOURNEY_ID]: '', + + // Deprecated, slated to be removed in a future version + [ConfigKey.ID]: '', }; export const DEFAULT_BROWSER_ADVANCED_FIELDS: BrowserAdvancedFields = { @@ -88,15 +91,17 @@ export const DEFAULT_BROWSER_SIMPLE_FIELDS: BrowserSimpleFields = { [ConfigKey.SOURCE_ZIP_FOLDER]: '', [ConfigKey.SOURCE_ZIP_PROXY_URL]: '', [ConfigKey.TEXT_ASSERTION]: '', + [ConfigKey.URLS]: '', + [ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.MULTISTEP, + [ConfigKey.TIMEOUT]: null, + + // Deprecated, slated to be removed in a future version [ConfigKey.ZIP_URL_TLS_CERTIFICATE_AUTHORITIES]: undefined, [ConfigKey.ZIP_URL_TLS_CERTIFICATE]: undefined, [ConfigKey.ZIP_URL_TLS_KEY]: undefined, [ConfigKey.ZIP_URL_TLS_KEY_PASSPHRASE]: undefined, [ConfigKey.ZIP_URL_TLS_VERIFICATION_MODE]: undefined, [ConfigKey.ZIP_URL_TLS_VERSION]: undefined, - [ConfigKey.URLS]: '', - [ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.MULTISTEP, - [ConfigKey.TIMEOUT]: null, }; export const DEFAULT_HTTP_SIMPLE_FIELDS: HTTPSimpleFields = { @@ -143,6 +148,7 @@ export const DEFAULT_TCP_SIMPLE_FIELDS: TCPSimpleFields = { is_tls_enabled: false, }, [ConfigKey.HOSTS]: '', + [ConfigKey.URLS]: '', [ConfigKey.MONITOR_TYPE]: DataStream.TCP, [ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.TCP, [ConfigKey.PORT]: null, diff --git a/x-pack/plugins/synthetics/common/constants/monitor_management.ts b/x-pack/plugins/synthetics/common/constants/monitor_management.ts index d613d234fc3c1..da3f138091723 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_management.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_management.ts @@ -77,6 +77,9 @@ 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', } 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 739c7184e7221..882182b2fe07f 100644 --- a/x-pack/plugins/synthetics/common/formatters/common/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/common/formatters.ts @@ -32,6 +32,9 @@ export const commonFormatters: CommonFormatMap = { [ConfigKey.PROJECT_ID]: null, [ConfigKey.CUSTOM_HEARTBEAT_ID]: null, [ConfigKey.ORIGINAL_SPACE]: null, + + // Deprecated, slated to be removed in a later release + [ConfigKey.ID]: null, }; export const arrayToJsonFormatter = (value: string[] = []) => diff --git a/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts b/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts index bec7ceb444845..98c9a50bcd2fb 100644 --- a/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts @@ -20,6 +20,7 @@ export const tcpFormatters: TCPFormatMap = { [ConfigKey.RESPONSE_RECEIVE_CHECK]: null, [ConfigKey.REQUEST_SEND_CHECK]: null, [ConfigKey.PORT]: null, + [ConfigKey.URLS]: null, ...tlsFormatters, ...commonFormatters, }; 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 bbb6eb1bb30d6..163041986f1a3 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 @@ -86,6 +86,7 @@ export const CommonFieldsCodec = t.intersection([ [ConfigKey.PROJECT_ID]: t.string, [ConfigKey.ORIGINAL_SPACE]: t.string, [ConfigKey.CUSTOM_HEARTBEAT_ID]: t.string, + [ConfigKey.ID]: t.string, }), ]); @@ -98,6 +99,9 @@ export const TCPSimpleFieldsCodec = t.intersection([ [ConfigKey.HOSTS]: t.string, [ConfigKey.PORT]: t.union([t.number, t.null]), }), + t.partial({ + [ConfigKey.URLS]: t.string, + }), CommonFieldsCodec, ]); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/formatter.test.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/formatter.test.tsx index 6ff7cd651b334..2903a0375d038 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/formatter.test.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/formatter.test.tsx @@ -136,6 +136,7 @@ describe('format', () => { urls: 'sample url', 'url.port': null, username: '', + id: '', }); }); @@ -284,6 +285,7 @@ describe('format', () => { type: 'browser', 'url.port': null, urls: '', + id: '', }); } ); @@ -350,6 +352,7 @@ describe('format', () => { urls: 'sample url', 'url.port': null, username: '', + id: '', }); }); }); 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 d05730c5dbe17..31ba9784e22a4 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 @@ -96,4 +96,7 @@ export const commonNormalizers: CommonNormalizerMap = { [ConfigKey.PROJECT_ID]: getCommonNormalizer(ConfigKey.PROJECT_ID), [ConfigKey.CUSTOM_HEARTBEAT_ID]: getCommonNormalizer(ConfigKey.CUSTOM_HEARTBEAT_ID), [ConfigKey.ORIGINAL_SPACE]: getCommonNormalizer(ConfigKey.ORIGINAL_SPACE), + + // Deprecated, slated to be removed in a future release + [ConfigKey.ID]: getCommonNormalizer(ConfigKey.ID), }; diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/tcp/normalizers.ts b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/tcp/normalizers.ts index 86efeeae69206..4fd671732260b 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/tcp/normalizers.ts +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/tcp/normalizers.ts @@ -38,6 +38,7 @@ export const tcpNormalizers: TCPNormalizerMap = { [ConfigKey.PROXY_USE_LOCAL_RESOLVER]: getTCPNormalizer(ConfigKey.PROXY_USE_LOCAL_RESOLVER), [ConfigKey.RESPONSE_RECEIVE_CHECK]: getTCPNormalizer(ConfigKey.RESPONSE_RECEIVE_CHECK), [ConfigKey.REQUEST_SEND_CHECK]: getTCPNormalizer(ConfigKey.REQUEST_SEND_CHECK), + [ConfigKey.URLS]: getTCPNormalizer(ConfigKey.URLS), ...tlsNormalizers, ...commonNormalizers, }; 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 a2427357e3682..5e9f35f030bd8 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/common.ts @@ -34,6 +34,9 @@ export const commonFormatters: CommonFormatMap = { [ConfigKey.PROJECT_ID]: null, [ConfigKey.CUSTOM_HEARTBEAT_ID]: null, [ConfigKey.ORIGINAL_SPACE]: null, + + // Deprecated, slated to be removed in a later releae + [ConfigKey.ID]: null, }; export const arrayFormatter = (value: string[] = []) => (value.length ? value : null); diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/tcp.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/tcp.ts index 25ba5c08e9b3c..7b89a464039fc 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/tcp.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/tcp.ts @@ -19,6 +19,7 @@ export const tcpFormatters: TCPFormatMap = { [ConfigKey.PROXY_USE_LOCAL_RESOLVER]: null, [ConfigKey.RESPONSE_RECEIVE_CHECK]: null, [ConfigKey.REQUEST_SEND_CHECK]: null, + [ConfigKey.URLS]: null, ...tlsFormatters, ...commonFormatters, }; diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/browser_monitor.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/browser_monitor.test.ts index 9b32b61a59b35..3133e98b57935 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/browser_monitor.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/browser_monitor.test.ts @@ -157,6 +157,7 @@ describe('browser normalizers', () => { original_space: 'test-space', custom_heartbeat_id: 'test-id-1-test-project-id-test-space', timeout: null, + id: '', }, unsupportedKeys: [], errors: [], @@ -213,6 +214,7 @@ describe('browser normalizers', () => { original_space: 'test-space', custom_heartbeat_id: 'test-id-2-test-project-id-test-space', timeout: null, + id: '', }, unsupportedKeys: [], errors: [], @@ -276,6 +278,7 @@ describe('browser normalizers', () => { original_space: 'test-space', custom_heartbeat_id: 'test-id-3-test-project-id-test-space', timeout: null, + id: '', }, unsupportedKeys: [], errors: [], diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.test.ts index cea5aa8b50de8..055c375bfb3b3 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.test.ts @@ -181,6 +181,7 @@ describe('http normalizers', () => { urls: 'http://localhost:9200', 'url.port': null, username: '', + id: '', }, unsupportedKeys: ['check.response.body', 'unsupportedKey.nestedUnsupportedKey'], }, @@ -235,6 +236,7 @@ describe('http normalizers', () => { urls: 'http://localhost:9200', 'url.port': null, username: '', + id: '', }, unsupportedKeys: [], }, diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/icmp_monitor.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/icmp_monitor.test.ts index 74ac2cb2bfaf3..17bdd9e8ca24e 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/icmp_monitor.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/icmp_monitor.test.ts @@ -127,6 +127,7 @@ describe('icmp normalizers', () => { timeout: '60', type: 'icmp', wait: '30', + id: '', }, unsupportedKeys: [], }, @@ -166,6 +167,7 @@ describe('icmp normalizers', () => { timeout: '16', type: 'icmp', wait: '60', + id: '', }, unsupportedKeys: [], }, @@ -218,6 +220,7 @@ describe('icmp normalizers', () => { timeout: '16', type: 'icmp', wait: '1', + id: '', }, unsupportedKeys: ['unsupportedKey.nestedUnsupportedKey'], }, diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/tcp_monitor.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/tcp_monitor.test.ts index a479bbc09d47b..9fbcb0c3b4ddf 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/tcp_monitor.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/tcp_monitor.test.ts @@ -142,6 +142,8 @@ describe('tcp normalizers', () => { tags: ['service:smtp', 'org:google'], timeout: '16', type: 'tcp', + id: '', + urls: '', }, unsupportedKeys: [], }, @@ -194,6 +196,8 @@ describe('tcp normalizers', () => { tags: ['tag1', 'tag2'], timeout: '16', type: 'tcp', + id: '', + urls: '', }, unsupportedKeys: [], }, @@ -259,6 +263,8 @@ describe('tcp normalizers', () => { tags: ['tag1', 'tag2'], timeout: '16', type: 'tcp', + id: '', + urls: '', }, unsupportedKeys: ['ports', 'unsupportedKey.nestedUnsupportedKey'], }, 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 a5fb9b774cf2c..6cefad03b83fc 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 @@ -549,6 +549,7 @@ const payloadData = [ type: 'browser', 'url.port': null, urls: '', + id: '', }, { __ui: { @@ -607,6 +608,7 @@ const payloadData = [ type: 'browser', 'url.port': null, urls: '', + 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 9dce7e7d8fdaa..7406f572611a1 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,6 +193,7 @@ export default function ({ getService }: FtrProviderContext) { type: 'browser', 'url.port': null, urls: '', + id: '', }); } } finally { @@ -306,6 +307,7 @@ export default function ({ getService }: FtrProviderContext) { type: 'http', urls: Array.isArray(monitor.urls) ? monitor.urls?.[0] : monitor.urls, 'url.port': null, + id: '', }); } } finally { @@ -405,6 +407,8 @@ export default function ({ getService }: FtrProviderContext) { type: 'tcp', hosts: Array.isArray(monitor.hosts) ? monitor.hosts?.[0] : monitor.hosts, 'url.port': null, + urls: '', + id: '', }); } } finally { @@ -506,6 +510,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: '', }); } } finally { diff --git a/x-pack/test/api_integration/apis/uptime/rest/fixtures/browser_monitor.json b/x-pack/test/api_integration/apis/uptime/rest/fixtures/browser_monitor.json index cfd4fc1b7d122..0d1508bf780cc 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/fixtures/browser_monitor.json +++ b/x-pack/test/api_integration/apis/uptime/rest/fixtures/browser_monitor.json @@ -47,5 +47,6 @@ "origin": "ui", "form_monitor_type": "multistep", "urls": "", - "url.port": null + "url.port": null, + "id": "" } diff --git a/x-pack/test/api_integration/apis/uptime/rest/fixtures/http_monitor.json b/x-pack/test/api_integration/apis/uptime/rest/fixtures/http_monitor.json index 45a2e11e9f306..2f68e70f0e00d 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/fixtures/http_monitor.json +++ b/x-pack/test/api_integration/apis/uptime/rest/fixtures/http_monitor.json @@ -79,5 +79,6 @@ "revision": 1, "origin": "ui", "form_monitor_type": "http", - "journey_id": "" + "journey_id": "", + "id": "" } diff --git a/x-pack/test/api_integration/apis/uptime/rest/fixtures/icmp_monitor.json b/x-pack/test/api_integration/apis/uptime/rest/fixtures/icmp_monitor.json index 052c811461ae7..fb6efa3a604d2 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/fixtures/icmp_monitor.json +++ b/x-pack/test/api_integration/apis/uptime/rest/fixtures/icmp_monitor.json @@ -19,5 +19,6 @@ "name": "Test HTTP Monitor 04", "namespace": "testnamespace", "origin": "ui", - "form_monitor_type": "icmp" + "form_monitor_type": "icmp", + "id": "" } diff --git a/x-pack/test/api_integration/apis/uptime/rest/fixtures/tcp_monitor.json b/x-pack/test/api_integration/apis/uptime/rest/fixtures/tcp_monitor.json index e0b4ca03b1d8d..bfa0b3a1a7242 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/fixtures/tcp_monitor.json +++ b/x-pack/test/api_integration/apis/uptime/rest/fixtures/tcp_monitor.json @@ -15,6 +15,7 @@ "is_zip_url_tls_enabled": false }, "hosts": "example-host:40", + "urls": "example-host:40", "url.port": null, "proxy_url": "", "proxy_use_local_resolver": false, @@ -32,5 +33,6 @@ "name": "Test HTTP Monitor 04", "namespace": "testnamespace", "origin": "ui", - "form_monitor_type": "tcp" + "form_monitor_type": "tcp", + "id": "" }