Skip to content

Commit

Permalink
[Synthetics] add migration to supported monitor schedules and remove …
Browse files Browse the repository at this point in the history
…deprecated zip url fields (elastic#154010)

## Summary

Relates to elastic#142655
Resolves elastic#142653

All monitor schedules in Uptime Monitor Management/Synthetics app apart
from the [supported
schedules](https://github.com/elastic/kibana/pull/154010/files#diff-6e5ef49468e646b5569e213b03876de143291ca3870a7092974793837f1ddc61R33)
have been deprecated.

The only allowed schedules are the below:

<img width="1241" alt="Screen Shot 2023-04-02 at 10 28 20 PM"
src="https://user-images.githubusercontent.com/11356435/229397972-fe2fcaa2-d3c7-450b-9b40-f8c71e6c7dcf.png">

Adds a migration to transform unsupportes schedules from Uptime Monitor
Management to supported Synthetics app schedules. Also adds validation
when an invalid schedule is used.

Also removes zip url fields from monitors. These fields were originally
included in the saved object spec anticipating a future zip url feature.
That feature has now been replaced by project monitors, removing the
need for zip url fields.

## Testing

⚠️ Note ⚠️ 
--

It's suggested that you use a fresh instance of ES to test this PR. This
can either be done by creating a brand new oblt cluster via oblt-cli, or
by running `yarn es snapshot`. If you run this PR on an existing
oblt-cluster, then switch back to main on that same cluster before this
PR is broken, you'll break the cluster.

Instructions
--
1. Check out 8.7.0
2. Create Uptime monitors with invalid schedules. Ideally, create one of
each monitor type. Some example invalid schedules are 4, 8, 11, and 16,
for example.
3. Create at least one of each type of project monitor by pushing
monitors via the synthetics agent
4. Check out this branch
5. Navigate to Synthetics or Uptime once Kibana is done loading. Observe
that each one of the invalid schedules was transformed into a supported
schedule.
6. (Testing that decryption is still working after migration). Navigate
to each one of the UI monitors' edit pages. Click save to resave each
monitor. Then, visit the edit page again. If you don't see any page
level errors, decryption is still working successfully
7. (Testing that decryption is still working after migration for project
monitors). Change the global schedule your project monitors and repush.
Check the global schedule of your project monitors one more time and
repush again. If both pushes are successful, decryption is still working
after the migration.

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
2 people authored and nreese committed Apr 6, 2023
1 parent 0a61058 commit 1024736
Show file tree
Hide file tree
Showing 41 changed files with 1,317 additions and 430 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"slo": "ee0e16abebba5779c37277bc3fe8da1fe1207b7a",
"space": "7fc578a1f9f7708cb07479f03953d664ad9f1dae",
"spaces-usage-stats": "084bd0f080f94fb5735d7f3cf12f13ec92f36bad",
"synthetics-monitor": "96cc312bfa597022f83dfb3b5d1501e27a73e8d5",
"synthetics-monitor": "7136a2669a65323c56da849f26c369cdeeb3b381",
"synthetics-param": "9776c9b571d35f0d0397e8915e035ea1dc026db7",
"synthetics-privates-locations": "7d032fc788905e32152029ae7ab3d6038c48ae44",
"tag": "87f21f07df9cc37001b15a26e413c18f50d1fbfe",
Expand Down
27 changes: 13 additions & 14 deletions x-pack/plugins/synthetics/common/constants/monitor_defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ import { ConfigKey } from './monitor_management';

export const DEFAULT_NAMESPACE_STRING = 'default';

export const ALLOWED_SCHEDULES_IN_MINUTES = [
'1',
'3',
'5',
'10',
'15',
'20',
'30',
'60',
'120',
'240',
];

export const DEFAULT_COMMON_FIELDS: CommonFields = {
[ConfigKey.MONITOR_TYPE]: DataStream.HTTP,
[ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.MULTISTEP,
Expand Down Expand Up @@ -74,7 +87,6 @@ export const DEFAULT_BROWSER_SIMPLE_FIELDS: BrowserSimpleFields = {
is_generated_script: false,
file_name: '',
},
is_zip_url_tls_enabled: false,
},
[ConfigKey.MONITOR_TYPE]: DataStream.BROWSER,
[ConfigKey.PARAMS]: '',
Expand All @@ -85,23 +97,10 @@ export const DEFAULT_BROWSER_SIMPLE_FIELDS: BrowserSimpleFields = {
},
[ConfigKey.SOURCE_INLINE]: '',
[ConfigKey.SOURCE_PROJECT_CONTENT]: '',
[ConfigKey.SOURCE_ZIP_URL]: '',
[ConfigKey.SOURCE_ZIP_USERNAME]: '',
[ConfigKey.SOURCE_ZIP_PASSWORD]: '',
[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,
};

export const DEFAULT_HTTP_SIMPLE_FIELDS: HTTPSimpleFields = {
Expand Down
29 changes: 14 additions & 15 deletions x-pack/plugins/synthetics/common/constants/monitor_management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ export enum ConfigKey {
SCREENSHOTS = 'screenshots',
SOURCE_PROJECT_CONTENT = 'source.project.content',
SOURCE_INLINE = 'source.inline.script',
SOURCE_ZIP_URL = 'source.zip_url.url',
SOURCE_ZIP_USERNAME = 'source.zip_url.username',
SOURCE_ZIP_PASSWORD = 'source.zip_url.password',
SOURCE_ZIP_FOLDER = 'source.zip_url.folder',
SOURCE_ZIP_PROXY_URL = 'source.zip_url.proxy_url',
PROJECT_ID = 'project_id',
SYNTHETICS_ARGS = 'synthetics_args',
TEXT_ASSERTION = 'playwright_text_assertion',
Expand All @@ -78,12 +73,6 @@ export enum ConfigKey {
URLS = 'urls',
USERNAME = 'username',
WAIT = 'wait',
ZIP_URL_TLS_CERTIFICATE_AUTHORITIES = 'source.zip_url.ssl.certificate_authorities',
ZIP_URL_TLS_CERTIFICATE = 'source.zip_url.ssl.certificate',
ZIP_URL_TLS_KEY = 'source.zip_url.ssl.key',
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',
MONITOR_QUERY_ID = 'id',
}

Expand All @@ -99,12 +88,22 @@ export const secretKeys = [
ConfigKey.RESPONSE_RECEIVE_CHECK,
ConfigKey.SOURCE_INLINE,
ConfigKey.SOURCE_PROJECT_CONTENT,
ConfigKey.SOURCE_ZIP_USERNAME,
ConfigKey.SOURCE_ZIP_PASSWORD,
ConfigKey.SYNTHETICS_ARGS,
ConfigKey.TLS_KEY,
ConfigKey.TLS_KEY_PASSPHRASE,
ConfigKey.USERNAME,
ConfigKey.ZIP_URL_TLS_KEY,
ConfigKey.ZIP_URL_TLS_KEY_PASSPHRASE,
] as const;

export enum LegacyConfigKey {
SOURCE_ZIP_URL = 'source.zip_url.url',
SOURCE_ZIP_USERNAME = 'source.zip_url.username',
SOURCE_ZIP_PASSWORD = 'source.zip_url.password',
SOURCE_ZIP_FOLDER = 'source.zip_url.folder',
SOURCE_ZIP_PROXY_URL = 'source.zip_url.proxy_url',
ZIP_URL_TLS_CERTIFICATE_AUTHORITIES = 'source.zip_url.ssl.certificate_authorities',
ZIP_URL_TLS_CERTIFICATE = 'source.zip_url.ssl.certificate',
ZIP_URL_TLS_KEY = 'source.zip_url.ssl.key',
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',
}
18 changes: 0 additions & 18 deletions x-pack/plugins/synthetics/common/formatters/browser/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import {
arrayToJsonFormatter,
objectToJsonFormatter,
stringToJsonFormatter,
tlsArrayToYamlFormatter,
tlsValueToStringFormatter,
tlsValueToYamlFormatter,
} from '../formatting_utils';

import { tlsFormatters } from '../tls/formatters';
Expand All @@ -35,20 +32,6 @@ const throttlingFormatter: Formatter = (fields) => {
.join('/');
};

export const deprecatedZipUrlFormatters = {
[ConfigKey.SOURCE_ZIP_URL]: null,
[ConfigKey.SOURCE_ZIP_USERNAME]: null,
[ConfigKey.SOURCE_ZIP_PASSWORD]: null,
[ConfigKey.SOURCE_ZIP_FOLDER]: null,
[ConfigKey.SOURCE_ZIP_PROXY_URL]: null,
[ConfigKey.ZIP_URL_TLS_CERTIFICATE_AUTHORITIES]: tlsValueToYamlFormatter,
[ConfigKey.ZIP_URL_TLS_CERTIFICATE]: tlsValueToYamlFormatter,
[ConfigKey.ZIP_URL_TLS_KEY]: tlsValueToYamlFormatter,
[ConfigKey.ZIP_URL_TLS_KEY_PASSPHRASE]: tlsValueToStringFormatter,
[ConfigKey.ZIP_URL_TLS_VERIFICATION_MODE]: tlsValueToStringFormatter,
[ConfigKey.ZIP_URL_TLS_VERSION]: tlsArrayToYamlFormatter,
};

export const browserFormatters: BrowserFormatMap = {
[ConfigKey.SOURCE_PROJECT_CONTENT]: null,
[ConfigKey.PARAMS]: null,
Expand All @@ -68,7 +51,6 @@ export const browserFormatters: BrowserFormatMap = {
[ConfigKey.JOURNEY_FILTERS_MATCH]: stringToJsonFormatter,
[ConfigKey.JOURNEY_FILTERS_TAGS]: arrayToJsonFormatter,
[ConfigKey.THROTTLING_CONFIG]: throttlingFormatter,
...deprecatedZipUrlFormatters,
...commonFormatters,
...tlsFormatters,
};
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ describe('formatSyntheticsPolicy', () => {
__ui: {
type: 'yaml',
value:
'{"script_source":{"is_generated_script":false,"file_name":""},"is_zip_url_tls_enabled":false,"is_tls_enabled":false}',
'{"script_source":{"is_generated_script":false,"file_name":""},"is_tls_enabled":false}',
},
config_id: {
type: 'text',
Expand Down Expand Up @@ -411,44 +411,6 @@ describe('formatSyntheticsPolicy', () => {
type: 'text',
value: '',
},
'source.zip_url.folder': {
type: 'text',
value: '',
},
'source.zip_url.password': {
type: 'password',
value: '',
},
'source.zip_url.proxy_url': {
type: 'text',
value: '',
},
'source.zip_url.ssl.certificate': {
type: 'yaml',
},
'source.zip_url.ssl.certificate_authorities': {
type: 'yaml',
},
'source.zip_url.ssl.key': {
type: 'yaml',
},
'source.zip_url.ssl.key_passphrase': {
type: 'text',
},
'source.zip_url.ssl.supported_protocols': {
type: 'yaml',
},
'source.zip_url.ssl.verification_mode': {
type: 'text',
},
'source.zip_url.url': {
type: 'text',
value: '',
},
'source.zip_url.username': {
type: 'text',
value: '',
},
synthetics_args: {
type: 'text',
value: null,
Expand Down Expand Up @@ -918,39 +880,6 @@ describe('formatSyntheticsPolicy', () => {
'source.project.content': {
type: 'text',
},
'source.zip_url.folder': {
type: 'text',
},
'source.zip_url.password': {
type: 'password',
},
'source.zip_url.proxy_url': {
type: 'text',
},
'source.zip_url.ssl.certificate': {
type: 'yaml',
},
'source.zip_url.ssl.certificate_authorities': {
type: 'yaml',
},
'source.zip_url.ssl.key': {
type: 'yaml',
},
'source.zip_url.ssl.key_passphrase': {
type: 'text',
},
'source.zip_url.ssl.supported_protocols': {
type: 'yaml',
},
'source.zip_url.ssl.verification_mode': {
type: 'text',
},
'source.zip_url.url': {
type: 'text',
},
'source.zip_url.username': {
type: 'text',
},
synthetics_args: {
type: 'text',
},
Expand Down Expand Up @@ -1147,10 +1076,6 @@ const testNewPolicy = {
'service.name': { type: 'text' },
timeout: { type: 'text' },
tags: { type: 'yaml' },
'source.zip_url.url': { type: 'text' },
'source.zip_url.username': { type: 'text' },
'source.zip_url.folder': { type: 'text' },
'source.zip_url.password': { type: 'password' },
'source.inline.script': { type: 'yaml' },
'source.project.content': { type: 'text' },
params: { type: 'yaml' },
Expand All @@ -1161,13 +1086,6 @@ const testNewPolicy = {
'throttling.config': { type: 'text' },
'filter_journeys.tags': { type: 'yaml' },
'filter_journeys.match': { type: 'text' },
'source.zip_url.ssl.certificate_authorities': { type: 'yaml' },
'source.zip_url.ssl.certificate': { type: 'yaml' },
'source.zip_url.ssl.key': { type: 'yaml' },
'source.zip_url.ssl.key_passphrase': { type: 'text' },
'source.zip_url.ssl.verification_mode': { type: 'text' },
'source.zip_url.ssl.supported_protocols': { type: 'yaml' },
'source.zip_url.proxy_url': { type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
id: { type: 'text' },
config_id: { type: 'text' },
Expand Down Expand Up @@ -1212,7 +1130,6 @@ const browserConfig: any = {
playwright_options: '',
__ui: {
script_source: { is_generated_script: false, file_name: '' },
is_zip_url_tls_enabled: false,
is_tls_enabled: false,
},
params:
Expand All @@ -1221,11 +1138,6 @@ const browserConfig: any = {
'source.inline.script':
'step("Visit /users api route", async () => {\\n const response = await page.goto(\'https://nextjs-test-synthetics.vercel.app/api/users\');\\n expect(response.status()).toEqual(200);\\n});',
'source.project.content': '',
'source.zip_url.url': '',
'source.zip_url.username': '',
'source.zip_url.password': '',
'source.zip_url.folder': '',
'source.zip_url.proxy_url': '',
playwright_text_assertion: '',
urls: '',
screenshots: 'on',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const ScriptSourceCodec = t.interface({

export const MetadataCodec = t.partial({
is_tls_enabled: t.boolean,
is_zip_url_tls_enabled: t.boolean,
script_source: ScriptSourceCodec,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,6 @@ export const TLSCodec = t.intersection([TLSFieldsCodec, TLSSensitiveFieldsCodec]

export type TLSFields = t.TypeOf<typeof TLSCodec>;

// ZipUrlTLSFields
export const ZipUrlTLSFieldsCodec = t.partial({
[ConfigKey.ZIP_URL_TLS_CERTIFICATE_AUTHORITIES]: t.string,
[ConfigKey.ZIP_URL_TLS_CERTIFICATE]: t.string,
[ConfigKey.ZIP_URL_TLS_VERIFICATION_MODE]: VerificationModeCodec,
[ConfigKey.ZIP_URL_TLS_VERSION]: t.array(TLSVersionCodec),
});

export const ZipUrlTLSSensitiveFieldsCodec = t.partial({
[ConfigKey.ZIP_URL_TLS_KEY]: t.string,
[ConfigKey.ZIP_URL_TLS_KEY_PASSPHRASE]: t.string,
});

export const ZipUrlTLSCodec = t.intersection([ZipUrlTLSFieldsCodec, ZipUrlTLSSensitiveFieldsCodec]);

export type ZipUrlTLSFields = t.TypeOf<typeof ZipUrlTLSCodec>;

// CommonFields
export const CommonFieldsCodec = t.intersection([
t.interface({
Expand Down Expand Up @@ -222,31 +205,23 @@ export const EncryptedBrowserSimpleFieldsCodec = t.intersection([
t.intersection([
t.interface({
[ConfigKey.METADATA]: MetadataCodec,
[ConfigKey.SOURCE_ZIP_URL]: t.string,
[ConfigKey.SOURCE_ZIP_FOLDER]: t.string,
[ConfigKey.SOURCE_ZIP_PROXY_URL]: t.string,
}),
t.partial({
[ConfigKey.PLAYWRIGHT_OPTIONS]: t.string,
[ConfigKey.TEXT_ASSERTION]: t.string,
}),
]),
ZipUrlTLSFieldsCodec,
ZipUrlTLSSensitiveFieldsCodec,
CommonFieldsCodec,
]);

export const BrowserSensitiveSimpleFieldsCodec = t.intersection([
t.interface({
[ConfigKey.SOURCE_INLINE]: t.string,
[ConfigKey.SOURCE_PROJECT_CONTENT]: t.string,
[ConfigKey.SOURCE_ZIP_USERNAME]: t.string,
[ConfigKey.SOURCE_ZIP_PASSWORD]: t.string,
[ConfigKey.PARAMS]: t.string,
[ConfigKey.URLS]: t.union([t.string, t.null]),
[ConfigKey.PORT]: t.union([t.number, t.null]),
}),
ZipUrlTLSFieldsCodec,
CommonFieldsCodec,
]);

Expand All @@ -265,7 +240,6 @@ export const EncryptedBrowserAdvancedFieldsCodec = t.interface({
export const BrowserSimpleFieldsCodec = t.intersection([
EncryptedBrowserSimpleFieldsCodec,
BrowserSensitiveSimpleFieldsCodec,
ZipUrlTLSSensitiveFieldsCodec,
]);

export const BrowserSensitiveAdvancedFieldsCodec = t.interface({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,12 @@ export const testDataMonitor = {
playwright_options: '',
__ui: {
script_source: { is_generated_script: false, file_name: '' },
is_zip_url_tls_enabled: false,
},
params: '',
'url.port': null,
'source.inline.script':
"step('Go to https://www.google.com', async () => {\n await page.goto('https://www.google.com');\n expect(await page.isVisible('text=Data')).toBeTruthy();\n });",
'source.project.content': '',
'source.zip_url.url': '',
'source.zip_url.username': '',
'source.zip_url.password': '',
'source.zip_url.folder': '',
'source.zip_url.proxy_url': '',
playwright_text_assertion: 'Data',
urls: 'https://www.google.com',
screenshots: 'on',
Expand Down

0 comments on commit 1024736

Please sign in to comment.