Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Synthetics] Add lightweight params support #148634

Merged
merged 47 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
ab7b42d
Added lightweight params
shahzad31 Feb 2, 2023
8901d12
Merge branch 'main' into lightweight-params
shahzad31 Feb 2, 2023
72c8c82
enable ui by default
shahzad31 Feb 6, 2023
97ef4e4
Merge branch 'main' of github.com:elastic/kibana into remove-feature-…
shahzad31 Feb 6, 2023
eaf52f4
update test
shahzad31 Feb 6, 2023
dbdf74c
update test
shahzad31 Feb 6, 2023
eff0460
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Feb 6, 2023
70c32b0
Merge branch 'remove-feature-flag' into lightweight-params
shahzad31 Feb 6, 2023
c0cfdb9
Merge branch 'lightweight-params' of github.com:shahzad31/kibana into…
shahzad31 Feb 6, 2023
18e0863
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Feb 6, 2023
502ab98
update usage
shahzad31 Feb 6, 2023
38e5dde
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Feb 6, 2023
6aae1bf
update
shahzad31 Feb 6, 2023
a09ed9f
Merge branch 'main' into lightweight-params
shahzad31 Feb 7, 2023
babc23b
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Feb 7, 2023
596557d
wip
shahzad31 Feb 7, 2023
5b11ec1
Merge branch 'lightweight-params' of github.com:shahzad31/kibana into…
shahzad31 Feb 7, 2023
ba4f651
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 7, 2023
143a811
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Feb 7, 2023
9e1addd
fix types
shahzad31 Feb 7, 2023
fe9859c
Merge branch 'lightweight-params' of github.com:shahzad31/kibana into…
shahzad31 Feb 7, 2023
4db2d90
update test
shahzad31 Feb 7, 2023
dd40278
more updates
shahzad31 Feb 7, 2023
7b79b84
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Feb 7, 2023
def66bf
update types
shahzad31 Feb 7, 2023
5a1ffad
update test
shahzad31 Feb 7, 2023
a270086
delete
shahzad31 Feb 7, 2023
7ab77b5
delete
shahzad31 Feb 7, 2023
f9142c4
Merge branch 'main' into lightweight-params
shahzad31 Feb 8, 2023
a1fd0c4
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Feb 10, 2023
47eaffb
PR feedback
shahzad31 Feb 10, 2023
717f0a5
Merge branch 'lightweight-params' of github.com:shahzad31/kibana into…
shahzad31 Feb 10, 2023
e72a5fc
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Feb 10, 2023
058ba9b
Merge branch 'main' into lightweight-params
shahzad31 Mar 20, 2023
c6e6bb3
Merge branch 'main' into lightweight-params
shahzad31 Mar 22, 2023
ef0d75a
Merge branch 'main' into lightweight-params
dominiqueclarke Mar 24, 2023
c2cf72d
adjust lightweight param formatter
dominiqueclarke Mar 24, 2023
12f0117
Merge branch 'lightweight-params' of github.com:shahzad31/kibana into…
shahzad31 Mar 27, 2023
a92ac94
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Mar 27, 2023
c050f05
clean up
shahzad31 Mar 27, 2023
9966325
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Mar 27, 2023
5d87ae8
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Mar 27, 2023
d1f681b
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Mar 28, 2023
c517ade
fix all spaces
shahzad31 Mar 28, 2023
55f3ee6
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Mar 28, 2023
fbbf23c
Merge branch 'main' of github.com:elastic/kibana into lightweight-params
shahzad31 Mar 28, 2023
14946ae
Merge branch 'main' into lightweight-params
shahzad31 Mar 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ packages/kbn-yarn-lock-validator @elastic/kibana-operations
/x-pack/test/functional/es_archives/uptime @elastic/uptime
/x-pack/test/functional/services/uptime @elastic/uptime
/x-pack/test/api_integration/apis/uptime @elastic/uptime
/x-pack/test/api_integration/apis/synthetics @elastic/uptime
/x-pack/plugins/observability/public/components/shared/exploratory_view @elastic/uptime
/x-pack/plugins/observability/public/components/shared/field_value_suggestions @elastic/uptime
/x-pack/plugins/observability/public/components/shared/core_web_vitals @elastic/uptime
Expand Down
56 changes: 25 additions & 31 deletions x-pack/plugins/synthetics/common/formatters/browser/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
*/
import { BrowserFields, ConfigKey } from '../../runtime_types/monitor_management';

import { Formatter, commonFormatters } from '../common/formatters';
import {
Formatter,
commonFormatters,
objectToJsonFormatter,
arrayToJsonFormatter,
objectToJsonFormatter,
stringToJsonFormatter,
} from '../common/formatters';
import {
tlsValueToYamlFormatter,
tlsValueToStringFormatter,
tlsArrayToYamlFormatter,
} from '../tls/formatters';
tlsValueToStringFormatter,
tlsValueToYamlFormatter,
} from '../formatting_utils';

import { tlsFormatters } from '../tls/formatters';

export type BrowserFormatMap = Record<keyof BrowserFields, Formatter>;
Expand All @@ -37,44 +35,40 @@ const throttlingFormatter: Formatter = (fields) => {
.join('/');
};

export const browserFormatters: BrowserFormatMap = {
[ConfigKey.METADATA]: (fields) => objectToJsonFormatter(fields[ConfigKey.METADATA]),
[ConfigKey.URLS]: null,
[ConfigKey.PORT]: null,
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.SOURCE_INLINE]: (fields) => stringToJsonFormatter(fields[ConfigKey.SOURCE_INLINE]),
[ConfigKey.PARAMS]: null,
[ConfigKey.SCREENSHOTS]: null,
[ConfigKey.IS_THROTTLING_ENABLED]: null,
[ConfigKey.DOWNLOAD_SPEED]: null,
[ConfigKey.UPLOAD_SPEED]: null,
[ConfigKey.LATENCY]: null,
[ConfigKey.SYNTHETICS_ARGS]: (fields) => arrayToJsonFormatter(fields[ConfigKey.SYNTHETICS_ARGS]),
[ConfigKey.ZIP_URL_TLS_CERTIFICATE_AUTHORITIES]: (fields) =>
tlsValueToYamlFormatter(fields[ConfigKey.ZIP_URL_TLS_CERTIFICATE_AUTHORITIES]),
[ConfigKey.ZIP_URL_TLS_CERTIFICATE]: (fields) =>
tlsValueToYamlFormatter(fields[ConfigKey.ZIP_URL_TLS_CERTIFICATE]),
[ConfigKey.ZIP_URL_TLS_KEY]: (fields) =>
tlsValueToYamlFormatter(fields[ConfigKey.ZIP_URL_TLS_KEY]),
[ConfigKey.ZIP_URL_TLS_KEY_PASSPHRASE]: (fields) =>
tlsValueToStringFormatter(fields[ConfigKey.ZIP_URL_TLS_KEY_PASSPHRASE]),
[ConfigKey.ZIP_URL_TLS_VERIFICATION_MODE]: (fields) =>
tlsValueToStringFormatter(fields[ConfigKey.ZIP_URL_TLS_VERIFICATION_MODE]),
[ConfigKey.ZIP_URL_TLS_VERSION]: (fields) =>
tlsArrayToYamlFormatter(fields[ConfigKey.ZIP_URL_TLS_VERSION]),
[ConfigKey.JOURNEY_FILTERS_MATCH]: (fields) =>
stringToJsonFormatter(fields[ConfigKey.JOURNEY_FILTERS_MATCH]),
[ConfigKey.JOURNEY_FILTERS_TAGS]: (fields) =>
arrayToJsonFormatter(fields[ConfigKey.JOURNEY_FILTERS_TAGS]),
[ConfigKey.THROTTLING_CONFIG]: throttlingFormatter,
[ConfigKey.IGNORE_HTTPS_ERRORS]: null,
[ConfigKey.PLAYWRIGHT_OPTIONS]: null,
[ConfigKey.TEXT_ASSERTION]: null,
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
[ConfigKey.PORT]: null,
[ConfigKey.URLS]: null,
[ConfigKey.METADATA]: objectToJsonFormatter,
[ConfigKey.SOURCE_INLINE]: stringToJsonFormatter,
[ConfigKey.SYNTHETICS_ARGS]: arrayToJsonFormatter,
[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 @@ -5,49 +5,62 @@
* 2.0.
*/

import { ConfigKey } from '../../runtime_types';
import {
secondsToCronFormatter,
arrayToJsonFormatter,
objectToJsonFormatter,
stringToJsonFormatter,
secondsToCronFormatter,
} from './formatters';
} from '../formatting_utils';

describe('formatters', () => {
describe('cronToSecondsNormalizer', () => {
it('takes a number of seconds and converts it to cron format', () => {
expect(secondsToCronFormatter('3')).toEqual('3s');
expect(secondsToCronFormatter({ [ConfigKey.WAIT]: '3' }, ConfigKey.WAIT)).toEqual('3s');
});
});

describe('arrayToJsonFormatter', () => {
it('takes an array and converts it to json', () => {
expect(arrayToJsonFormatter(['tag1', 'tag2'])).toEqual('["tag1","tag2"]');
expect(arrayToJsonFormatter({ [ConfigKey.TAGS]: ['tag1', 'tag2'] }, ConfigKey.TAGS)).toEqual(
'["tag1","tag2"]'
);
});

it('returns null if the array has length of 0', () => {
expect(arrayToJsonFormatter([])).toEqual(null);
expect(arrayToJsonFormatter({ [ConfigKey.TAGS]: [] }, ConfigKey.TAGS)).toEqual(null);
});
});

describe('objectToJsonFormatter', () => {
it('takes a json object string and returns an object', () => {
expect(objectToJsonFormatter({ key: 'value' })).toEqual('{"key":"value"}');
expect(
objectToJsonFormatter(
{ [ConfigKey.RESPONSE_HEADERS_CHECK]: { key: 'value' } },
ConfigKey.RESPONSE_HEADERS_CHECK
)
).toEqual('{"key":"value"}');
});

it('returns null if the object has no keys', () => {
expect(objectToJsonFormatter({})).toEqual(null);
expect(objectToJsonFormatter({ [ConfigKey.METADATA]: {} }, ConfigKey.METADATA)).toEqual(null);
});
});

describe('stringToJsonFormatter', () => {
it('takes a string and returns an json string', () => {
expect(stringToJsonFormatter('step("test step", () => {})')).toEqual(
'"step(\\"test step\\", () => {})"'
);
expect(
stringToJsonFormatter(
{ [ConfigKey.SOURCE_INLINE]: 'step("test step", () => {})' },
ConfigKey.SOURCE_INLINE
)
).toEqual('"step(\\"test step\\", () => {})"');
});

it('returns null if the string is falsy', () => {
expect(stringToJsonFormatter('')).toEqual(null);
expect(
stringToJsonFormatter({ [ConfigKey.SOURCE_INLINE]: '' }, ConfigKey.SOURCE_INLINE)
).toEqual(null);
});
});
});
29 changes: 12 additions & 17 deletions x-pack/plugins/synthetics/common/formatters/common/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@
* 2.0.
*/

import { CommonFields, ConfigKey, MonitorFields } from '../../runtime_types/monitor_management';
import { CommonFields, ConfigKey, SourceType } from '../../runtime_types/monitor_management';
import { arrayToJsonFormatter, FormatterFn } from '../formatting_utils';

export type Formatter = null | ((fields: Partial<MonitorFields>) => string | null);
export type Formatter = null | FormatterFn;

export type CommonFormatMap = Record<keyof CommonFields | ConfigKey.NAME, Formatter>;

export const commonFormatters: CommonFormatMap = {
[ConfigKey.APM_SERVICE_NAME]: null,
[ConfigKey.NAME]: null,
[ConfigKey.LOCATIONS]: null,
[ConfigKey.MONITOR_TYPE]: null,
[ConfigKey.ENABLED]: null,
[ConfigKey.ALERT_CONFIG]: null,
[ConfigKey.CONFIG_ID]: null,
[ConfigKey.SCHEDULE]: (fields) =>
JSON.stringify(
`@every ${fields[ConfigKey.SCHEDULE]?.number}${fields[ConfigKey.SCHEDULE]?.unit}`
),
[ConfigKey.APM_SERVICE_NAME]: null,
[ConfigKey.TAGS]: (fields) => arrayToJsonFormatter(fields[ConfigKey.TAGS]),
[ConfigKey.TIMEOUT]: (fields) => secondsToCronFormatter(fields[ConfigKey.TIMEOUT] || undefined),
[ConfigKey.NAMESPACE]: null,
[ConfigKey.REVISION]: null,
[ConfigKey.MONITOR_SOURCE_TYPE]: null,
Expand All @@ -35,14 +30,14 @@ export const commonFormatters: CommonFormatMap = {
[ConfigKey.ORIGINAL_SPACE]: null,
[ConfigKey.CONFIG_HASH]: null,
[ConfigKey.MONITOR_QUERY_ID]: null,
[ConfigKey.SCHEDULE]: (fields) =>
JSON.stringify(
`@every ${fields[ConfigKey.SCHEDULE]?.number}${fields[ConfigKey.SCHEDULE]?.unit}`
),
[ConfigKey.TAGS]: arrayToJsonFormatter,
[ConfigKey.TIMEOUT]: (fields) => secondsToCronFormatter(fields[ConfigKey.TIMEOUT] || undefined),
[ConfigKey.MONITOR_SOURCE_TYPE]: (fields) =>
fields[ConfigKey.MONITOR_SOURCE_TYPE] || SourceType.UI,
};

export const arrayToJsonFormatter = (value: string[] = []) =>
value.length ? JSON.stringify(value) : null;

export const secondsToCronFormatter = (value: string = '') => (value ? `${value}s` : null);

export const objectToJsonFormatter = (value: Record<string, any> = {}) =>
Object.keys(value).length ? JSON.stringify(value) : null;

export const stringToJsonFormatter = (value: string = '') => (value ? JSON.stringify(value) : null);
Loading