From 98e7748aa55c440946c21612b405b5876c7ba821 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 4 Apr 2023 15:56:32 -0400 Subject: [PATCH 01/27] add mode to http monitors --- .../common/constants/monitor_defaults.ts | 4 +- .../common/constants/monitor_management.ts | 1 + .../monitor_management/monitor_configs.ts | 13 +++- .../monitor_management/monitor_types.ts | 22 ++++--- .../fields/header_field.test.tsx | 4 +- .../monitor_add_edit/fields/header_field.tsx | 14 ++-- .../fields/request_body_field.test.tsx | 2 +- .../fields/request_body_field.tsx | 65 ++++++++++--------- .../monitor_add_edit/form/field_config.tsx | 25 +++++++ .../monitor_add_edit/form/form_config.tsx | 1 + .../components/monitor_add_edit/types.ts | 1 + .../fleet_package/header_field.test.tsx | 6 +- .../components/fleet_package/header_field.tsx | 14 ++-- .../fleet_package/request_body_field.test.tsx | 2 +- .../fleet_package/request_body_field.tsx | 65 ++++++++++--------- .../components/fleet_package/types.tsx | 10 +-- .../monitor_cruds/monitor_validation.test.ts | 4 +- .../normalizers/http_monitor.ts | 4 +- 18 files changed, 155 insertions(+), 102 deletions(-) diff --git a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts index 83aeed3269f3e..180e544dbe27e 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts @@ -5,6 +5,7 @@ * 2.0. */ import { + CodeEditorMode, BrowserAdvancedFields, BrowserSimpleFields, CommonFields, @@ -127,11 +128,12 @@ export const DEFAULT_HTTP_ADVANCED_FIELDS: HTTPAdvancedFields = { [ConfigKey.RESPONSE_STATUS_CHECK]: [], [ConfigKey.REQUEST_BODY_CHECK]: { value: '', - type: Mode.PLAINTEXT, + type: CodeEditorMode.PLAINTEXT, }, [ConfigKey.REQUEST_HEADERS_CHECK]: {}, [ConfigKey.REQUEST_METHOD_CHECK]: HTTPMethod.GET, [ConfigKey.USERNAME]: '', + [ConfigKey.MODE]: Mode.ANY, }; export const DEFAULT_ICMP_SIMPLE_FIELDS: ICMPSimpleFields = { diff --git a/x-pack/plugins/synthetics/common/constants/monitor_management.ts b/x-pack/plugins/synthetics/common/constants/monitor_management.ts index 78e1829356458..d895563629715 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_management.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_management.ts @@ -27,6 +27,7 @@ export enum ConfigKey { JOURNEY_ID = 'journey_id', MAX_REDIRECTS = 'max_redirects', METADATA = '__ui', + MODE = 'mode', MONITOR_TYPE = 'type', NAME = 'name', NAMESPACE = 'namespace', diff --git a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_configs.ts b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_configs.ts index 934c534795301..a08ec3e5914a3 100644 --- a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_configs.ts +++ b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_configs.ts @@ -54,15 +54,15 @@ export const MonacoEditorLangIdCodec = tEnum( ); export type MonacoEditorLangIdType = t.TypeOf; -export enum Mode { +export enum CodeEditorMode { FORM = 'form', JSON = 'json', PLAINTEXT = 'text', XML = 'xml', } -export const ModeCodec = tEnum('Mode', Mode); -export type ModeType = t.TypeOf; +export const CodeEditorModeCodec = tEnum('CodeEditorMode', CodeEditorMode); +export type CodeEditorModeType = t.TypeOf; export enum ContentType { JSON = 'application/json', @@ -136,3 +136,10 @@ export enum FormMonitorType { } export const FormMonitorTypeCodec = tEnum('FormMonitorType', FormMonitorType); + +export enum Mode { + ANY = 'any', + ALL = 'all', +} +export const ModeCodec = tEnum('Mode', Mode); +export type ModeType = t.TypeOf; 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 5cb78f45e1fdd..d44e9936fbe22 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 @@ -11,6 +11,7 @@ import { secretKeys } from '../../constants/monitor_management'; import { ConfigKey } from './config_key'; import { MonitorServiceLocationCodec, ServiceLocationErrors } from './locations'; import { + CodeEditorModeCodec, DataStream, DataStreamCodec, FormMonitorTypeCodec, @@ -169,20 +170,25 @@ export const HTTPSimpleFieldsCodec = t.intersection([ export type HTTPSimpleFields = t.TypeOf; // HTTPAdvancedFields -export const HTTPAdvancedFieldsCodec = t.interface({ - [ConfigKey.PROXY_URL]: t.string, - [ConfigKey.RESPONSE_BODY_INDEX]: ResponseBodyIndexPolicyCodec, - [ConfigKey.RESPONSE_HEADERS_INDEX]: t.boolean, - [ConfigKey.RESPONSE_STATUS_CHECK]: t.array(t.string), - [ConfigKey.REQUEST_METHOD_CHECK]: t.string, -}); +export const HTTPAdvancedFieldsCodec = t.intersection([ + t.interface({ + [ConfigKey.PROXY_URL]: t.string, + [ConfigKey.RESPONSE_BODY_INDEX]: ResponseBodyIndexPolicyCodec, + [ConfigKey.RESPONSE_HEADERS_INDEX]: t.boolean, + [ConfigKey.RESPONSE_STATUS_CHECK]: t.array(t.string), + [ConfigKey.REQUEST_METHOD_CHECK]: t.string, + }), + t.partial({ + [ConfigKey.MODE]: ModeCodec, + }), +]); export const HTTPSensitiveAdvancedFieldsCodec = t.interface({ [ConfigKey.PASSWORD]: t.string, [ConfigKey.RESPONSE_BODY_CHECK_NEGATIVE]: t.array(t.string), [ConfigKey.RESPONSE_BODY_CHECK_POSITIVE]: t.array(t.string), [ConfigKey.RESPONSE_HEADERS_CHECK]: t.record(t.string, t.string), - [ConfigKey.REQUEST_BODY_CHECK]: t.interface({ value: t.string, type: ModeCodec }), + [ConfigKey.REQUEST_BODY_CHECK]: t.interface({ value: t.string, type: CodeEditorModeCodec }), [ConfigKey.REQUEST_HEADERS_CHECK]: t.record(t.string, t.string), [ConfigKey.USERNAME]: t.string, }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.test.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.test.tsx index 6f920bf10d84a..8fec1a509e948 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.test.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.test.tsx @@ -95,14 +95,14 @@ describe('', () => { }); it('handles content mode', async () => { - const contentMode: Mode = Mode.PLAINTEXT; + const contentMode: Mode = CodeEditorMode.PLAINTEXT; render( ); await waitFor(() => { expect(onChange).toBeCalledWith({ - 'Content-Type': contentTypes[Mode.PLAINTEXT], + 'Content-Type': contentTypes[CodeEditorMode.PLAINTEXT], }); }); }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.tsx index a26fe8616d90b..c3159043b9958 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.tsx @@ -7,12 +7,12 @@ import React, { useEffect, useState } from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; -import { ContentType, Mode } from '../types'; +import { ContentType, CodeEditorMode } from '../types'; import { KeyValuePairsField, Pair } from './key_value_field'; export interface HeaderFieldProps { - contentMode?: Mode; + contentMode?: CodeEditorMode; defaultValue: Record; onChange: (value: Record) => void; onBlur?: () => void; @@ -72,9 +72,9 @@ export const HeaderField = ({ ); }; -export const contentTypes: Record = { - [Mode.JSON]: ContentType.JSON, - [Mode.PLAINTEXT]: ContentType.TEXT, - [Mode.XML]: ContentType.XML, - [Mode.FORM]: ContentType.FORM, +export const contentTypes: Record = { + [CodeEditorMode.JSON]: ContentType.JSON, + [CodeEditorMode.PLAINTEXT]: ContentType.TEXT, + [CodeEditorMode.XML]: ContentType.XML, + [CodeEditorMode.FORM]: ContentType.FORM, }; diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/request_body_field.test.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/request_body_field.test.tsx index 90e4d457764c1..f10fa17e40efe 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/request_body_field.test.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/request_body_field.test.tsx @@ -37,7 +37,7 @@ jest.mock('@kbn/kibana-react-plugin/public', () => { }); describe('', () => { - const defaultMode = Mode.PLAINTEXT; + const defaultMode = CodeEditorMode.PLAINTEXT; const defaultValue = 'sample value'; const WrappedComponent = ({ readOnly }: { readOnly?: boolean }) => { const [config, setConfig] = useState({ diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/request_body_field.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/request_body_field.tsx index fe117a4703ffb..e6877942f4f14 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/request_body_field.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/request_body_field.tsx @@ -9,15 +9,15 @@ import { stringify, parse } from 'query-string'; import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; import { EuiTabbedContent } from '@elastic/eui'; -import { Mode, MonacoEditorLangId } from '../types'; +import { CodeEditorMode, MonacoEditorLangId } from '../types'; import { KeyValuePairsField, Pair } from './key_value_field'; import { CodeEditor } from './code_editor'; export interface RequestBodyFieldProps { - onChange: (requestBody: { type: Mode; value: string }) => void; + onChange: (requestBody: { type: CodeEditorMode; value: string }) => void; onBlur?: () => void; value: { - type: Mode; + type: CodeEditorMode; value: string; }; readOnly?: boolean; @@ -36,22 +36,27 @@ export const RequestBodyField = ({ readOnly, }: RequestBodyFieldProps) => { const [values, setValues] = useState>({ - [ResponseBodyType.FORM]: type === Mode.FORM ? value : '', - [ResponseBodyType.CODE]: type !== Mode.FORM ? value : '', + [ResponseBodyType.FORM]: type === CodeEditorMode.FORM ? value : '', + [ResponseBodyType.CODE]: type !== CodeEditorMode.FORM ? value : '', }); useEffect(() => { onChange({ type, - value: type === Mode.FORM ? values[ResponseBodyType.FORM] : values[ResponseBodyType.CODE], + value: + type === CodeEditorMode.FORM + ? values[ResponseBodyType.FORM] + : values[ResponseBodyType.CODE], }); }, [onChange, type, values]); const handleSetMode = useCallback( - (currentMode: Mode) => { + (currentMode: CodeEditorMode) => { onChange({ type: currentMode, value: - currentMode === Mode.FORM ? values[ResponseBodyType.FORM] : values[ResponseBodyType.CODE], + currentMode === CodeEditorMode.FORM + ? values[ResponseBodyType.FORM] + : values[ResponseBodyType.CODE], }); }, [onChange, values] @@ -71,14 +76,14 @@ export const RequestBodyField = ({ }, {}); return setValues((prevValues) => ({ ...prevValues, - [Mode.FORM]: stringify(formattedPairs), + [CodeEditorMode.FORM]: stringify(formattedPairs), })); }, [setValues] ); const defaultFormPairs: Pair[] = useMemo(() => { - const pairs = parse(values[Mode.FORM]); + const pairs = parse(values[CodeEditorMode.FORM]); const keys = Object.keys(pairs); const formattedPairs: Pair[] = keys.map((key: string) => { // key, value, checked; @@ -89,9 +94,9 @@ export const RequestBodyField = ({ const tabs = [ { - id: Mode.PLAINTEXT, - name: modeLabels[Mode.PLAINTEXT], - 'data-test-subj': `syntheticsRequestBodyTab__${Mode.PLAINTEXT}`, + id: CodeEditorMode.PLAINTEXT, + name: modeLabels[CodeEditorMode.PLAINTEXT], + 'data-test-subj': `syntheticsRequestBodyTab__${CodeEditorMode.PLAINTEXT}`, content: ( { setValues((prevValues) => ({ ...prevValues, [ResponseBodyType.CODE]: code })); @@ -112,9 +117,9 @@ export const RequestBodyField = ({ ), }, { - id: Mode.JSON, - name: modeLabels[Mode.JSON], - 'data-test-subj': `syntheticsRequestBodyTab__${Mode.JSON}`, + id: CodeEditorMode.JSON, + name: modeLabels[CodeEditorMode.JSON], + 'data-test-subj': `syntheticsRequestBodyTab__${CodeEditorMode.JSON}`, content: ( { setValues((prevValues) => ({ ...prevValues, [ResponseBodyType.CODE]: code })); @@ -135,9 +140,9 @@ export const RequestBodyField = ({ ), }, { - id: Mode.XML, - name: modeLabels[Mode.XML], - 'data-test-subj': `syntheticsRequestBodyTab__${Mode.XML}`, + id: CodeEditorMode.XML, + name: modeLabels[CodeEditorMode.XML], + 'data-test-subj': `syntheticsRequestBodyTab__${CodeEditorMode.XML}`, content: ( { setValues((prevValues) => ({ ...prevValues, [ResponseBodyType.CODE]: code })); @@ -158,9 +163,9 @@ export const RequestBodyField = ({ ), }, { - id: Mode.FORM, - name: modeLabels[Mode.FORM], - 'data-test-subj': `syntheticsRequestBodyTab__${Mode.FORM}`, + id: CodeEditorMode.FORM, + name: modeLabels[CodeEditorMode.FORM], + 'data-test-subj': `syntheticsRequestBodyTab__${CodeEditorMode.FORM}`, content: ( tab.id === type)} autoFocus="selected" onTabClick={(tab) => { - handleSetMode(tab.id as Mode); + handleSetMode(tab.id as CodeEditorMode); }} /> @@ -195,25 +200,25 @@ export const RequestBodyField = ({ }; const modeLabels = { - [Mode.FORM]: i18n.translate( + [CodeEditorMode.FORM]: i18n.translate( 'xpack.synthetics.createPackagePolicy.stepConfigure.requestBodyType.form', { defaultMessage: 'Form', } ), - [Mode.PLAINTEXT]: i18n.translate( + [CodeEditorMode.PLAINTEXT]: i18n.translate( 'xpack.synthetics.createPackagePolicy.stepConfigure.requestBodyType.text', { defaultMessage: 'Text', } ), - [Mode.JSON]: i18n.translate( + [CodeEditorMode.JSON]: i18n.translate( 'xpack.synthetics.createPackagePolicy.stepConfigure.requestBodyType.JSON', { defaultMessage: 'JSON', } ), - [Mode.XML]: i18n.translate( + [CodeEditorMode.XML]: i18n.translate( 'xpack.synthetics.createPackagePolicy.stepConfigure.requestBodyType.XML', { defaultMessage: 'XML', diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 110ac698e22f7..67022c856e9b3 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -62,6 +62,7 @@ import { FormMonitorType, HTTPMethod, ScreenshotOption, + Mode, MonitorFields, TLSVersion, VerificationMode, @@ -1255,4 +1256,28 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ isDisabled: readOnly, }), }, + [ConfigKey.MODE]: { + fieldKey: ConfigKey.MODE, + component: Select, + label: i18n.translate('xpack.synthetics.monitorConfig.mode.label', { + defaultMessage: 'Mode', + }), + helpText: ( + all, + any: any, + }} + /> + ), + props: (): EuiSelectProps => ({ + options: Object.values(Mode).map((value) => ({ + value, + text: value, + })), + disabled: readOnly, + }), + }, }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx index a33f0e14b7777..6329678a0436d 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx @@ -43,6 +43,7 @@ const HTTP_ADVANCED = (readOnly: boolean) => ({ FIELD(readOnly)[ConfigKey.REQUEST_METHOD_CHECK], FIELD(readOnly)[ConfigKey.REQUEST_HEADERS_CHECK], FIELD(readOnly)[ConfigKey.REQUEST_BODY_CHECK], + FIELD(readOnly)[ConfigKey.MODE], ], }, responseConfig: { diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts index b3b86eef542fe..c0f5abc4d02ef 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts @@ -142,4 +142,5 @@ export interface FieldMap { [ConfigKey.PLAYWRIGHT_OPTIONS]: FieldMeta; [ConfigKey.SYNTHETICS_ARGS]: FieldMeta; [ConfigKey.IGNORE_HTTPS_ERRORS]: FieldMeta; + [ConfigKey.MODE]: FieldMeta; } diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/header_field.test.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/header_field.test.tsx index 668669dab6a26..0342493f7f34e 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/header_field.test.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/header_field.test.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { fireEvent, waitFor } from '@testing-library/react'; import { render } from '../../lib/helper/rtl_helpers'; import { HeaderField, contentTypes } from './header_field'; -import { Mode } from './types'; +import { CodeEditorMode } from './types'; describe('', () => { const onChange = jest.fn(); @@ -95,14 +95,14 @@ describe('', () => { }); it('handles content mode', async () => { - const contentMode: Mode = Mode.PLAINTEXT; + const contentMode: CodeEditorMode = CodeEditorMode.PLAINTEXT; render( ); await waitFor(() => { expect(onChange).toBeCalledWith({ - 'Content-Type': contentTypes[Mode.PLAINTEXT], + 'Content-Type': contentTypes[CodeEditorMode.PLAINTEXT], }); }); }); diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/header_field.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/header_field.tsx index 112a0879d404d..2ff19a17c1a3e 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/header_field.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/header_field.tsx @@ -7,12 +7,12 @@ import React, { useEffect, useState } from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; -import { ContentType, Mode } from './types'; +import { ContentType, CodeEditorMode } from './types'; import { KeyValuePairsField, Pair } from './key_value_field'; interface Props { - contentMode?: Mode; + contentMode?: CodeEditorMode; defaultValue: Record; onChange: (value: Record) => void; onBlur?: () => void; @@ -69,9 +69,9 @@ export const HeaderField = ({ ); }; -export const contentTypes: Record = { - [Mode.JSON]: ContentType.JSON, - [Mode.PLAINTEXT]: ContentType.TEXT, - [Mode.XML]: ContentType.XML, - [Mode.FORM]: ContentType.FORM, +export const contentTypes: Record = { + [CodeEditorMode.JSON]: ContentType.JSON, + [CodeEditorMode.PLAINTEXT]: ContentType.TEXT, + [CodeEditorMode.XML]: ContentType.XML, + [CodeEditorMode.FORM]: ContentType.FORM, }; diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/request_body_field.test.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/request_body_field.test.tsx index 6dad2b9b6efd9..8f64a95f05e7c 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/request_body_field.test.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/request_body_field.test.tsx @@ -35,7 +35,7 @@ jest.mock('@kbn/kibana-react-plugin/public', () => { }); describe('', () => { - const defaultMode = Mode.PLAINTEXT; + const defaultMode = CodeEditorMode.PLAINTEXT; const defaultValue = 'sample value'; const WrappedComponent = () => { const [config, setConfig] = useState({ diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/request_body_field.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/request_body_field.tsx index 19cb8cda978f8..236a11eba15f0 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/request_body_field.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/request_body_field.tsx @@ -9,14 +9,14 @@ import { stringify, parse } from 'query-string'; import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; import { EuiTabbedContent } from '@elastic/eui'; -import { Mode, MonacoEditorLangId } from './types'; +import { CodeEditorMode, MonacoEditorLangId } from './types'; import { KeyValuePairsField, Pair } from './key_value_field'; import { CodeEditor } from './code_editor'; interface Props { - onChange: (requestBody: { type: Mode; value: string }) => void; + onChange: (requestBody: { type: CodeEditorMode; value: string }) => void; onBlur?: () => void; - type: Mode; + type: CodeEditorMode; value: string; } @@ -28,22 +28,27 @@ enum ResponseBodyType { // TO DO: Look into whether or not code editor reports errors, in order to prevent form submission on an error export const RequestBodyField = ({ onChange, onBlur, type, value }: Props) => { const [values, setValues] = useState>({ - [ResponseBodyType.FORM]: type === Mode.FORM ? value : '', - [ResponseBodyType.CODE]: type !== Mode.FORM ? value : '', + [ResponseBodyType.FORM]: type === CodeEditorMode.FORM ? value : '', + [ResponseBodyType.CODE]: type !== CodeEditorMode.FORM ? value : '', }); useEffect(() => { onChange({ type, - value: type === Mode.FORM ? values[ResponseBodyType.FORM] : values[ResponseBodyType.CODE], + value: + type === CodeEditorMode.FORM + ? values[ResponseBodyType.FORM] + : values[ResponseBodyType.CODE], }); }, [onChange, type, values]); const handleSetMode = useCallback( - (currentMode: Mode) => { + (currentMode: CodeEditorMode) => { onChange({ type: currentMode, value: - currentMode === Mode.FORM ? values[ResponseBodyType.FORM] : values[ResponseBodyType.CODE], + currentMode === CodeEditorMode.FORM + ? values[ResponseBodyType.FORM] + : values[ResponseBodyType.CODE], }); }, [onChange, values] @@ -63,14 +68,14 @@ export const RequestBodyField = ({ onChange, onBlur, type, value }: Props) => { }, {}); return setValues((prevValues) => ({ ...prevValues, - [Mode.FORM]: stringify(formattedPairs), + [CodeEditorMode.FORM]: stringify(formattedPairs), })); }, [setValues] ); const defaultFormPairs: Pair[] = useMemo(() => { - const pairs = parse(values[Mode.FORM]); + const pairs = parse(values[CodeEditorMode.FORM]); const keys = Object.keys(pairs); const formattedPairs: Pair[] = keys.map((key: string) => { // key, value, checked; @@ -81,9 +86,9 @@ export const RequestBodyField = ({ onChange, onBlur, type, value }: Props) => { const tabs = [ { - id: Mode.PLAINTEXT, - name: modeLabels[Mode.PLAINTEXT], - 'data-test-subj': `syntheticsRequestBodyTab__${Mode.PLAINTEXT}`, + id: CodeEditorMode.PLAINTEXT, + name: modeLabels[CodeEditorMode.PLAINTEXT], + 'data-test-subj': `syntheticsRequestBodyTab__${CodeEditorMode.PLAINTEXT}`, content: ( { defaultMessage: 'Text code editor', } )} - id={Mode.PLAINTEXT} + id={CodeEditorMode.PLAINTEXT} languageId={MonacoEditorLangId.PLAINTEXT} onChange={(code) => { setValues((prevValues) => ({ ...prevValues, [ResponseBodyType.CODE]: code })); @@ -103,9 +108,9 @@ export const RequestBodyField = ({ onChange, onBlur, type, value }: Props) => { ), }, { - id: Mode.JSON, - name: modeLabels[Mode.JSON], - 'data-test-subj': `syntheticsRequestBodyTab__${Mode.JSON}`, + id: CodeEditorMode.JSON, + name: modeLabels[CodeEditorMode.JSON], + 'data-test-subj': `syntheticsRequestBodyTab__${CodeEditorMode.JSON}`, content: ( { defaultMessage: 'JSON code editor', } )} - id={Mode.JSON} + id={CodeEditorMode.JSON} languageId={MonacoEditorLangId.JSON} onChange={(code) => { setValues((prevValues) => ({ ...prevValues, [ResponseBodyType.CODE]: code })); @@ -125,9 +130,9 @@ export const RequestBodyField = ({ onChange, onBlur, type, value }: Props) => { ), }, { - id: Mode.XML, - name: modeLabels[Mode.XML], - 'data-test-subj': `syntheticsRequestBodyTab__${Mode.XML}`, + id: CodeEditorMode.XML, + name: modeLabels[CodeEditorMode.XML], + 'data-test-subj': `syntheticsRequestBodyTab__${CodeEditorMode.XML}`, content: ( { defaultMessage: 'XML code editor', } )} - id={Mode.XML} + id={CodeEditorMode.XML} languageId={MonacoEditorLangId.XML} onChange={(code) => { setValues((prevValues) => ({ ...prevValues, [ResponseBodyType.CODE]: code })); @@ -147,9 +152,9 @@ export const RequestBodyField = ({ onChange, onBlur, type, value }: Props) => { ), }, { - id: Mode.FORM, - name: modeLabels[Mode.FORM], - 'data-test-subj': `syntheticsRequestBodyTab__${Mode.FORM}`, + id: CodeEditorMode.FORM, + name: modeLabels[CodeEditorMode.FORM], + 'data-test-subj': `syntheticsRequestBodyTab__${CodeEditorMode.FORM}`, content: ( { initialSelectedTab={tabs.find((tab) => tab.id === type)} autoFocus="selected" onTabClick={(tab) => { - handleSetMode(tab.id as Mode); + handleSetMode(tab.id as CodeEditorMode); }} /> ); }; const modeLabels = { - [Mode.FORM]: i18n.translate( + [CodeEditorMode.FORM]: i18n.translate( 'xpack.synthetics.createPackagePolicy.stepConfigure.requestBodyType.form', { defaultMessage: 'Form', } ), - [Mode.PLAINTEXT]: i18n.translate( + [CodeEditorMode.PLAINTEXT]: i18n.translate( 'xpack.synthetics.createPackagePolicy.stepConfigure.requestBodyType.text', { defaultMessage: 'Text', } ), - [Mode.JSON]: i18n.translate( + [CodeEditorMode.JSON]: i18n.translate( 'xpack.synthetics.createPackagePolicy.stepConfigure.requestBodyType.JSON', { defaultMessage: 'JSON', } ), - [Mode.XML]: i18n.translate( + [CodeEditorMode.XML]: i18n.translate( 'xpack.synthetics.createPackagePolicy.stepConfigure.requestBodyType.XML', { defaultMessage: 'XML', diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/types.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/types.tsx index 0a5de311c5cb3..0a5ed2c07d90d 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/types.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/types.tsx @@ -5,6 +5,7 @@ * 2.0. */ import { + CodeEditorMode, HTTPFields, TCPFields, ICMPFields, @@ -12,7 +13,6 @@ import { ConfigKey, ContentType, DataStream, - Mode, ThrottlingConfigKey, ThrottlingSuffix, ThrottlingSuffixType, @@ -28,10 +28,10 @@ export interface PolicyConfig { } export const contentTypesToMode = { - [ContentType.FORM]: Mode.FORM, - [ContentType.JSON]: Mode.JSON, - [ContentType.TEXT]: Mode.PLAINTEXT, - [ContentType.XML]: Mode.XML, + [ContentType.FORM]: CodeEditorMode.FORM, + [ContentType.JSON]: CodeEditorMode.JSON, + [ContentType.TEXT]: CodeEditorMode.PLAINTEXT, + [ContentType.XML]: CodeEditorMode.XML, }; export const configKeyToThrottlingSuffix: Record = { 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 b927e1a37e21a..6764c430d3aa5 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 @@ -9,6 +9,7 @@ import { BrowserAdvancedFields, BrowserFields, BrowserSimpleFields, + CodeEditorMode, CommonFields, ConfigKey, DataStream, @@ -18,7 +19,6 @@ import { HTTPSimpleFields, ICMPSimpleFields, Metadata, - Mode, MonitorFields, ResponseBodyIndexPolicy, ScheduleUnit, @@ -145,7 +145,7 @@ describe('validateMonitor', () => { [ConfigKey.RESPONSE_HEADERS_CHECK]: {}, [ConfigKey.RESPONSE_HEADERS_INDEX]: true, [ConfigKey.RESPONSE_STATUS_CHECK]: ['200', '201'], - [ConfigKey.REQUEST_BODY_CHECK]: { value: 'testValue', type: Mode.JSON }, + [ConfigKey.REQUEST_BODY_CHECK]: { value: 'testValue', type: CodeEditorMode.JSON }, [ConfigKey.REQUEST_HEADERS_CHECK]: {}, [ConfigKey.REQUEST_METHOD_CHECK]: '', [ConfigKey.USERNAME]: 'test-username', diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts index cd7ac7a26f6dd..4fae592cdce5c 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts @@ -98,10 +98,10 @@ export const getRequestBodyField = ( if (typeof value === 'object') { parsedValue = JSON.stringify(value); - type = Mode.JSON; + type = CodeEditorMode.JSON; } else { parsedValue = value; - type = Mode.PLAINTEXT; + type = CodeEditorMode.PLAINTEXT; } return { type, From 58b481774d4c1d737a4aab0d47443fdbda1b8af7 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 4 Apr 2023 16:50:06 -0400 Subject: [PATCH 02/27] adjust tests --- .../components/monitor_add_edit/fields/header_field.test.tsx | 2 +- .../project_monitor/normalizers/http_monitor.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.test.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.test.tsx index 8fec1a509e948..9a0481d6c66ea 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.test.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.test.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { fireEvent, waitFor } from '@testing-library/react'; import { render } from '../../../utils/testing/rtl_helpers'; import { HeaderField, contentTypes } from './header_field'; -import { Mode } from '../types'; +import { CodeEditorMode } from '../types'; describe('', () => { const onChange = jest.fn(); diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts index 4fae592cdce5c..c2b5f86737a8a 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts @@ -7,11 +7,11 @@ import { get } from 'lodash'; import { DEFAULT_FIELDS } from '../../../../common/constants/monitor_defaults'; import { + CodeEditorMode, ConfigKey, DataStream, FormMonitorType, HTTPFields, - Mode, TLSVersion, } from '../../../../common/runtime_types/monitor_management'; import { @@ -94,7 +94,7 @@ export const getRequestBodyField = ( defaultValue: HTTPFields[ConfigKey.REQUEST_BODY_CHECK] ): HTTPFields[ConfigKey.REQUEST_BODY_CHECK] => { let parsedValue: string; - let type: Mode; + let type: CodeEditorMode; if (typeof value === 'object') { parsedValue = JSON.stringify(value); From 229076e7f3e146015355bc98a8f12ef81dfee6e2 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 4 Apr 2023 17:06:26 -0400 Subject: [PATCH 03/27] add mode to icmp and tcp monitors --- .../common/constants/monitor_defaults.ts | 6 +++++ .../monitor_management/monitor_types.ts | 24 +++++++++++++++---- .../monitor_add_edit/form/form_config.tsx | 18 +++++++++++++- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts index 180e544dbe27e..1b5ccc2ba8150 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts @@ -161,6 +161,11 @@ export const DEFAULT_TCP_ADVANCED_FIELDS: TCPAdvancedFields = { [ConfigKey.PROXY_USE_LOCAL_RESOLVER]: false, [ConfigKey.RESPONSE_RECEIVE_CHECK]: '', [ConfigKey.REQUEST_SEND_CHECK]: '', + [ConfigKey.MODE]: Mode.ANY, +}; + +export const DEFAULT_ICMP_ADVANCED_FIELDS = { + [ConfigKey.MODE]: Mode.ANY, }; export const DEFAULT_TLS_FIELDS: TLSFields = { @@ -185,6 +190,7 @@ export const DEFAULT_FIELDS: MonitorDefaults = { }, [DataStream.ICMP]: { ...DEFAULT_ICMP_SIMPLE_FIELDS, + ...DEFAULT_ICMP_ADVANCED_FIELDS, }, [DataStream.BROWSER]: { ...DEFAULT_BROWSER_SIMPLE_FIELDS, 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 d44e9936fbe22..25eb08c276fc4 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 @@ -112,10 +112,15 @@ export const TCPSimpleFieldsCodec = t.intersection([ export type TCPSimpleFields = t.TypeOf; // TCPAdvancedFields -export const TCPAdvancedFieldsCodec = t.interface({ - [ConfigKey.PROXY_URL]: t.string, - [ConfigKey.PROXY_USE_LOCAL_RESOLVER]: t.boolean, -}); +export const TCPAdvancedFieldsCodec = t.intersection([ + t.interface({ + [ConfigKey.PROXY_URL]: t.string, + [ConfigKey.PROXY_USE_LOCAL_RESOLVER]: t.boolean, + }), + t.partial({ + [ConfigKey.MODE]: ModeCodec, + }), +]); export const TCPSensitiveAdvancedFieldsCodec = t.interface({ [ConfigKey.RESPONSE_RECEIVE_CHECK]: t.string, @@ -154,7 +159,16 @@ export const ICMPSimpleFieldsCodec = t.intersection([ ]); export type ICMPSimpleFields = t.TypeOf; -export type ICMPFields = t.TypeOf; + +// ICMPAdvancedFields +export const ICMPAdvancedFieldsCodec = t.partial({ + [ConfigKey.MODE]: ModeCodec, +}); + +// ICMPFields +export const ICMPFieldsCodec = t.intersection([ICMPSimpleFieldsCodec, ICMPAdvancedFieldsCodec]); + +export type ICMPFields = t.TypeOf; // HTTPSimpleFields export const HTTPSimpleFieldsCodec = t.intersection([ diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx index 6329678a0436d..ee65cf1301f9d 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx @@ -94,6 +94,7 @@ export const TCP_ADVANCED = (readOnly: boolean) => ({ components: [ FIELD(readOnly)[`${ConfigKey.PROXY_URL}__tcp`], FIELD(readOnly)[ConfigKey.REQUEST_SEND_CHECK], + FIELD(readOnly)[ConfigKey.MODE], ], }, responseChecks: { @@ -110,6 +111,21 @@ export const TCP_ADVANCED = (readOnly: boolean) => ({ }, }); +export const ICMP_ADVANCED = (readOnly: boolean) => ({ + requestConfig: { + title: i18n.translate('xpack.synthetics.monitorConfig.section.requestConfigICMP.title', { + defaultMessage: 'Request configuration', + }), + description: i18n.translate( + 'xpack.synthetics.monitorConfig.section.requestConfigICMP.description', + { + defaultMessage: 'Configure the payload sent to the remote host.', + } + ), + components: [FIELD(readOnly)[ConfigKey.MODE]], + }, +}); + export const BROWSER_ADVANCED = (readOnly: boolean) => [ { title: i18n.translate('xpack.synthetics.monitorConfig.section.syntAgentOptions.title', { @@ -266,6 +282,6 @@ export const FORM_CONFIG = (readOnly: boolean): FieldConfig => ({ FIELD(readOnly)[ConfigKey.ENABLED], FIELD(readOnly)[AlertConfigKey.STATUS_ENABLED], ], - advanced: [DEFAULT_DATA_OPTIONS(readOnly)], + advanced: [DEFAULT_DATA_OPTIONS(readOnly), ICMP_ADVANCED(readOnly).requestConfig], }, }); From cb41e215f23b427404ee07a5fa640c623fd82f6d Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 4 Apr 2023 17:58:12 -0400 Subject: [PATCH 04/27] add response.include_body_max_bytes to http monitors --- .../common/constants/monitor_defaults.ts | 1 + .../common/constants/monitor_management.ts | 1 + .../monitor_management/monitor_types.ts | 1 + .../components/monitor_add_edit/form/field.tsx | 2 ++ .../monitor_add_edit/form/field_config.tsx | 17 +++++++++++++++++ .../monitor_add_edit/form/form_config.tsx | 1 + .../components/monitor_add_edit/types.ts | 2 ++ 7 files changed, 25 insertions(+) diff --git a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts index 1b5ccc2ba8150..c1939a5a97e6d 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts @@ -134,6 +134,7 @@ export const DEFAULT_HTTP_ADVANCED_FIELDS: HTTPAdvancedFields = { [ConfigKey.REQUEST_METHOD_CHECK]: HTTPMethod.GET, [ConfigKey.USERNAME]: '', [ConfigKey.MODE]: Mode.ANY, + [ConfigKey.RESPONSE_BODY_MAX_BYTES]: '1024', }; export const DEFAULT_ICMP_SIMPLE_FIELDS: ICMPSimpleFields = { diff --git a/x-pack/plugins/synthetics/common/constants/monitor_management.ts b/x-pack/plugins/synthetics/common/constants/monitor_management.ts index d895563629715..4f4f9484c1f64 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_management.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_management.ts @@ -44,6 +44,7 @@ export enum ConfigKey { RESPONSE_BODY_INDEX = 'response.include_body', RESPONSE_HEADERS_CHECK = 'check.response.headers', RESPONSE_HEADERS_INDEX = 'response.include_headers', + RESPONSE_BODY_MAX_BYTES = 'response.include_body_max_bytes', RESPONSE_RECEIVE_CHECK = 'check.receive', RESPONSE_STATUS_CHECK = 'check.response.status', REQUEST_BODY_CHECK = 'check.request.body', 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 25eb08c276fc4..6e60cb32b5d4c 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 @@ -194,6 +194,7 @@ export const HTTPAdvancedFieldsCodec = t.intersection([ }), t.partial({ [ConfigKey.MODE]: ModeCodec, + [ConfigKey.RESPONSE_BODY_MAX_BYTES]: t.string, }), ]); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field.tsx index 7aed077680d4b..9861b5eb238ab 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field.tsx @@ -32,6 +32,7 @@ export const Field = memo( fieldError, dependencies, customHook, + hidden, }: Props) => { const { register, watch, control, setValue, reset, getFieldState, formState } = useFormContext(); @@ -73,6 +74,7 @@ export const Field = memo( 'aria-label': ariaLabel, helpText, fullWidth: true, + style: hidden && hidden(dependenciesValues) ? { display: 'none' } : undefined, }; return controlled ? ( diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 67022c856e9b3..fc1d0e8f701c2 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -68,6 +68,7 @@ import { VerificationMode, FieldMap, FormLocation, + ResponseBodyIndexPolicy, } from '../types'; import { AlertConfigKey, DEFAULT_BROWSER_ADVANCED_FIELDS } from '../constants'; import { getDefaultFormFields } from './defaults'; @@ -1280,4 +1281,20 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ disabled: readOnly, }), }, + [ConfigKey.RESPONSE_BODY_MAX_BYTES]: { + fieldKey: ConfigKey.RESPONSE_BODY_MAX_BYTES, + component: FieldNumber, + label: i18n.translate('xpack.synthetics.monitorConfig.responseBodyMaxBytes.label', { + defaultMessage: 'Response body max bytes', + }), + helpText: i18n.translate('xpack.synthetics.monitorConfig.responseBodyMaxBytes.helpText', { + defaultMessage: 'Control the maximum size of the stored body contents.', + }), + hidden: (dependencies) => { + const [responseBodyIndex] = dependencies || []; + return responseBodyIndex === ResponseBodyIndexPolicy.NEVER; + }, + props: (): EuiFieldNumberProps => ({ min: 1, step: 'any', readOnly }), + dependencies: [ConfigKey.RESPONSE_BODY_INDEX], + }, }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx index ee65cf1301f9d..e3aa6ca18308a 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx @@ -59,6 +59,7 @@ const HTTP_ADVANCED = (readOnly: boolean) => ({ components: [ FIELD(readOnly)[ConfigKey.RESPONSE_HEADERS_INDEX], FIELD(readOnly)[ConfigKey.RESPONSE_BODY_INDEX], + FIELD(readOnly)[ConfigKey.RESPONSE_BODY_MAX_BYTES], ], }, responseChecks: { diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts index c0f5abc4d02ef..0fde75530fedf 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts @@ -63,6 +63,7 @@ export interface FieldMeta { label?: string; ariaLabel?: string; helpText?: string | React.ReactNode; + hidden?: (depenencies?: unknown[]) => boolean; props?: (params: { field?: ControllerRenderProps; formState: FormState; @@ -129,6 +130,7 @@ export interface FieldMap { [ConfigKey.REQUEST_BODY_CHECK]: FieldMeta; [ConfigKey.RESPONSE_HEADERS_INDEX]: FieldMeta; [ConfigKey.RESPONSE_BODY_INDEX]: FieldMeta; + [ConfigKey.RESPONSE_BODY_MAX_BYTES]: FieldMeta; [ConfigKey.RESPONSE_STATUS_CHECK]: FieldMeta; [ConfigKey.RESPONSE_HEADERS_CHECK]: FieldMeta; [ConfigKey.RESPONSE_BODY_CHECK_POSITIVE]: FieldMeta; From 54789cc18751f6870ab4f715e7156b7feee76897 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 4 Apr 2023 18:03:59 -0400 Subject: [PATCH 05/27] adjust types --- .../plugins/synthetics/common/formatters/http/formatters.ts | 2 ++ .../plugins/synthetics/common/formatters/icmp/formatters.ts | 1 + x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts | 1 + .../components/monitor_add_edit/fields/header_field.test.tsx | 2 +- .../monitor_add_edit/fields/request_body_field.test.tsx | 4 ++-- .../synthetics_service/formatters/format_configs.test.ts | 4 ++-- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/synthetics/common/formatters/http/formatters.ts b/x-pack/plugins/synthetics/common/formatters/http/formatters.ts index 300e4f9fdb9ff..04e097c9494b8 100644 --- a/x-pack/plugins/synthetics/common/formatters/http/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/http/formatters.ts @@ -33,6 +33,8 @@ export const httpFormatters: HTTPFormatMap = { fields[ConfigKey.REQUEST_BODY_CHECK]?.value ? JSON.stringify(fields[ConfigKey.REQUEST_BODY_CHECK]?.value) : null, + [ConfigKey.RESPONSE_BODY_MAX_BYTES]: null, + [ConfigKey.MODE]: null, ...tlsFormatters, ...commonFormatters, }; diff --git a/x-pack/plugins/synthetics/common/formatters/icmp/formatters.ts b/x-pack/plugins/synthetics/common/formatters/icmp/formatters.ts index 0ebf69db5b408..be5b3d7f0f1de 100644 --- a/x-pack/plugins/synthetics/common/formatters/icmp/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/icmp/formatters.ts @@ -15,5 +15,6 @@ export type ICMPFormatMap = Record; export const icmpFormatters: ICMPFormatMap = { [ConfigKey.HOSTS]: null, [ConfigKey.WAIT]: secondsToCronFormatter, + [ConfigKey.MODE]: null, ...commonFormatters, }; diff --git a/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts b/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts index 6acb9abe21877..9cb05fa6c7787 100644 --- a/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts @@ -23,6 +23,7 @@ export const tcpFormatters: TCPFormatMap = { [ConfigKey.PROXY_URL]: null, [ConfigKey.PORT]: null, [ConfigKey.URLS]: null, + [ConfigKey.MODE]: null, ...tlsFormatters, ...commonFormatters, }; diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.test.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.test.tsx index 9a0481d6c66ea..c08434460aab5 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.test.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/header_field.test.tsx @@ -95,7 +95,7 @@ describe('', () => { }); it('handles content mode', async () => { - const contentMode: Mode = CodeEditorMode.PLAINTEXT; + const contentMode: CodeEditorMode = CodeEditorMode.PLAINTEXT; render( ); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/request_body_field.test.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/request_body_field.test.tsx index f10fa17e40efe..dad0e35f3fc9c 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/request_body_field.test.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/request_body_field.test.tsx @@ -12,7 +12,7 @@ import userEvent from '@testing-library/user-event'; import { fireEvent, waitFor } from '@testing-library/react'; import { render } from '../../../utils/testing/rtl_helpers'; import { RequestBodyField } from './request_body_field'; -import { Mode } from '../types'; +import { CodeEditorMode } from '../types'; jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => ({ htmlIdGenerator: () => () => `id-${Math.random()}`, @@ -52,7 +52,7 @@ describe('', () => { type: config.type, }} onChange={useCallback( - (code) => setConfig({ type: code.type as Mode, value: code.value }), + (code) => setConfig({ type: code.type as CodeEditorMode, value: code.value }), [setConfig] )} readOnly={readOnly} 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 139c9faa91854..e83ead539010e 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 @@ -14,7 +14,7 @@ import { import { ConfigKey, DataStream, - Mode, + CodeEditorMode, MonitorFields, ResponseBodyIndexPolicy, ScheduleUnit, @@ -43,7 +43,7 @@ const testHTTPConfig: Partial = { 'check.response.headers': {}, 'response.include_headers': true, 'check.response.status': [], - 'check.request.body': { type: 'text' as Mode, value: '' }, + 'check.request.body': { type: 'text' as CodeEditorMode, value: '' }, 'check.request.headers': {}, 'check.request.method': 'GET', 'ssl.verification_mode': VerificationMode.NONE, From 871995f76d62b8d36526119f5a4cd743a9d60879 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 4 Apr 2023 18:34:09 -0400 Subject: [PATCH 06/27] adjust tests --- .../api_integration/apis/synthetics/add_monitor_project.ts | 4 ++++ .../apis/uptime/rest/fixtures/http_monitor.json | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts b/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts index 4bc005c46596c..b0f57fa06f4c7 100644 --- a/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts +++ b/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts @@ -361,6 +361,7 @@ export default function ({ getService }: FtrProviderContext) { proxy_url: '', 'response.include_body': 'always', 'response.include_headers': false, + 'response.include_body_max_bytes': '1024', revision: 1, schedule: { number: '60', @@ -380,6 +381,7 @@ export default function ({ getService }: FtrProviderContext) { 'url.port': null, id: `${journeyId}-${project}-default`, hash: 'ekrjelkjrelkjre', + mode: 'any', }); } } finally { @@ -488,6 +490,7 @@ export default function ({ getService }: FtrProviderContext) { urls: '', id: `${journeyId}-${project}-default`, hash: 'ekrjelkjrelkjre', + mode: 'any', }); } } finally { @@ -592,6 +595,7 @@ export default function ({ getService }: FtrProviderContext) { : `${parseInt(monitor.wait?.slice(0, -1) || '1', 10) * 60}`, id: `${journeyId}-${project}-default`, hash: 'ekrjelkjrelkjre', + mode: 'any', }); } } finally { 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 091f18e6afe57..b6c5ee74714f3 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 @@ -28,6 +28,7 @@ "check.response.body.negative": [], "check.response.body.positive": [], "response.include_body": "never", + "resposne.include_body_max_bytes": "1024", "check.request.headers": { "sampleHeader": "sampleHeaderValue" }, @@ -81,5 +82,6 @@ "form_monitor_type": "http", "journey_id": "", "id": "", - "hash": "" + "hash": "", + "mode": "any" } From 44dd5e240f3a92783bfd315973ae226b24026b2a Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 4 Apr 2023 20:31:20 -0400 Subject: [PATCH 07/27] add ipv4 and ipv6 configs --- .../common/constants/monitor_defaults.ts | 6 ++ .../common/constants/monitor_management.ts | 2 + .../common/formatters/http/formatters.ts | 2 + .../common/formatters/icmp/formatters.ts | 2 + .../common/formatters/tcp/formatters.ts | 2 + .../monitor_management/monitor_types.ts | 6 ++ .../monitor_add_edit/form/field.tsx | 10 +-- .../monitor_add_edit/form/field_config.tsx | 83 +++++++++++++++++-- .../monitor_add_edit/form/form_config.tsx | 4 +- .../components/monitor_add_edit/types.ts | 4 +- 10 files changed, 103 insertions(+), 18 deletions(-) diff --git a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts index c1939a5a97e6d..eb6b4324c5217 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts @@ -135,6 +135,8 @@ export const DEFAULT_HTTP_ADVANCED_FIELDS: HTTPAdvancedFields = { [ConfigKey.USERNAME]: '', [ConfigKey.MODE]: Mode.ANY, [ConfigKey.RESPONSE_BODY_MAX_BYTES]: '1024', + [ConfigKey.IPV4]: true, + [ConfigKey.IPV6]: true, }; export const DEFAULT_ICMP_SIMPLE_FIELDS: ICMPSimpleFields = { @@ -163,10 +165,14 @@ export const DEFAULT_TCP_ADVANCED_FIELDS: TCPAdvancedFields = { [ConfigKey.RESPONSE_RECEIVE_CHECK]: '', [ConfigKey.REQUEST_SEND_CHECK]: '', [ConfigKey.MODE]: Mode.ANY, + [ConfigKey.IPV4]: true, + [ConfigKey.IPV6]: true, }; export const DEFAULT_ICMP_ADVANCED_FIELDS = { [ConfigKey.MODE]: Mode.ANY, + [ConfigKey.IPV4]: true, + [ConfigKey.IPV6]: true, }; export const DEFAULT_TLS_FIELDS: TLSFields = { diff --git a/x-pack/plugins/synthetics/common/constants/monitor_management.ts b/x-pack/plugins/synthetics/common/constants/monitor_management.ts index 4f4f9484c1f64..839ca46600797 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_management.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_management.ts @@ -74,6 +74,8 @@ export enum ConfigKey { TIMEOUT = 'timeout', THROTTLING_CONFIG = 'throttling.config', IS_THROTTLING_ENABLED = 'throttling.is_enabled', + IPV4 = 'ipv4', + IPV6 = 'ipv6', DOWNLOAD_SPEED = 'throttling.download_speed', UPLOAD_SPEED = 'throttling.upload_speed', LATENCY = 'throttling.latency', diff --git a/x-pack/plugins/synthetics/common/formatters/http/formatters.ts b/x-pack/plugins/synthetics/common/formatters/http/formatters.ts index 04e097c9494b8..8c8b2dee6a4b2 100644 --- a/x-pack/plugins/synthetics/common/formatters/http/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/http/formatters.ts @@ -35,6 +35,8 @@ export const httpFormatters: HTTPFormatMap = { : null, [ConfigKey.RESPONSE_BODY_MAX_BYTES]: null, [ConfigKey.MODE]: null, + [ConfigKey.IPV4]: null, + [ConfigKey.IPV6]: null, ...tlsFormatters, ...commonFormatters, }; diff --git a/x-pack/plugins/synthetics/common/formatters/icmp/formatters.ts b/x-pack/plugins/synthetics/common/formatters/icmp/formatters.ts index be5b3d7f0f1de..f58e15c86b3ad 100644 --- a/x-pack/plugins/synthetics/common/formatters/icmp/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/icmp/formatters.ts @@ -16,5 +16,7 @@ export const icmpFormatters: ICMPFormatMap = { [ConfigKey.HOSTS]: null, [ConfigKey.WAIT]: secondsToCronFormatter, [ConfigKey.MODE]: null, + [ConfigKey.IPV4]: null, + [ConfigKey.IPV6]: null, ...commonFormatters, }; diff --git a/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts b/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts index 9cb05fa6c7787..2d850e95ceaf1 100644 --- a/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/tcp/formatters.ts @@ -24,6 +24,8 @@ export const tcpFormatters: TCPFormatMap = { [ConfigKey.PORT]: null, [ConfigKey.URLS]: null, [ConfigKey.MODE]: null, + [ConfigKey.IPV4]: null, + [ConfigKey.IPV6]: 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 6e60cb32b5d4c..a1ab47b7e5e2d 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 @@ -119,6 +119,8 @@ export const TCPAdvancedFieldsCodec = t.intersection([ }), t.partial({ [ConfigKey.MODE]: ModeCodec, + [ConfigKey.IPV4]: t.boolean, + [ConfigKey.IPV6]: t.boolean, }), ]); @@ -163,6 +165,8 @@ export type ICMPSimpleFields = t.TypeOf; // ICMPAdvancedFields export const ICMPAdvancedFieldsCodec = t.partial({ [ConfigKey.MODE]: ModeCodec, + [ConfigKey.IPV4]: t.boolean, + [ConfigKey.IPV6]: t.boolean, }); // ICMPFields @@ -195,6 +199,8 @@ export const HTTPAdvancedFieldsCodec = t.intersection([ t.partial({ [ConfigKey.MODE]: ModeCodec, [ConfigKey.RESPONSE_BODY_MAX_BYTES]: t.string, + [ConfigKey.IPV4]: t.boolean, + [ConfigKey.IPV6]: t.boolean, }), ]); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field.tsx index 9861b5eb238ab..62db4c6434d05 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field.tsx @@ -24,7 +24,6 @@ export const Field = memo( props, fieldKey, controlled, - showWhen, shouldUseSetValue, required, validation, @@ -42,13 +41,7 @@ export const Field = memo( const [dependenciesFieldMeta, setDependenciesFieldMeta] = useState< Record >({}); - let show = true; let dependenciesValues: unknown[] = []; - if (showWhen) { - const [showKey, expectedValue] = showWhen; - const [actualValue] = watch([showKey]); - show = actualValue === expectedValue; - } if (dependencies) { dependenciesValues = watch(dependencies); } @@ -65,7 +58,7 @@ export const Field = memo( // eslint-disable-next-line react-hooks/exhaustive-deps }, [JSON.stringify(dependenciesValues || []), dependencies, getFieldState]); - if (!show) { + if (hidden && !hidden(dependenciesValues)) { return null; } @@ -74,7 +67,6 @@ export const Field = memo( 'aria-label': ariaLabel, helpText, fullWidth: true, - style: hidden && hidden(dependenciesValues) ? { display: 'none' } : undefined, }; return controlled ? ( diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index fc1d0e8f701c2..7865f79713495 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -973,7 +973,11 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ defaultMessage: 'Verifies that the provided certificate is signed by a trusted authority (CA) and also verifies that the server’s hostname (or IP address) matches the names identified within the certificate. If the Subject Alternative Name is empty, it returns an error.', }), - showWhen: ['isTLSEnabled', true], + hidden: (dependencies) => { + const [isTLSEnabled] = dependencies; + return Boolean(isTLSEnabled); + }, + dependencies: ['isTLSEnabled'], props: (): EuiSelectProps => ({ options: Object.values(VerificationMode).map((method) => ({ value: method, @@ -989,7 +993,11 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ defaultMessage: 'Supported TLS protocols', }), controlled: true, - showWhen: ['isTLSEnabled', true], + hidden: (dependencies) => { + const [isTLSEnabled] = dependencies; + return Boolean(isTLSEnabled); + }, + dependencies: ['isTLSEnabled'], props: ({ field, setValue }): EuiComboBoxProps => { return { options: Object.values(TLSVersion).map((version) => ({ @@ -1017,7 +1025,11 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ helpText: i18n.translate('xpack.synthetics.monitorConfig.certificateAuthorities.helpText', { defaultMessage: 'PEM-formatted custom certificate authorities.', }), - showWhen: ['isTLSEnabled', true], + hidden: (dependencies) => { + const [isTLSEnabled] = dependencies; + return Boolean(isTLSEnabled); + }, + dependencies: ['isTLSEnabled'], props: (): EuiTextAreaProps => ({ readOnly, }), @@ -1031,7 +1043,11 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ helpText: i18n.translate('xpack.synthetics.monitorConfig.clientCertificate.helpText', { defaultMessage: 'PEM-formatted certificate for TLS client authentication.', }), - showWhen: ['isTLSEnabled', true], + hidden: (dependencies) => { + const [isTLSEnabled] = dependencies; + return Boolean(isTLSEnabled); + }, + dependencies: ['isTLSEnabled'], props: (): EuiTextAreaProps => ({ readOnly, }), @@ -1045,7 +1061,11 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ helpText: i18n.translate('xpack.synthetics.monitorConfig.clientKey.helpText', { defaultMessage: 'PEM-formatted certificate key for TLS client authentication.', }), - showWhen: ['isTLSEnabled', true], + hidden: (dependencies) => { + const [isTLSEnabled] = dependencies; + return Boolean(isTLSEnabled); + }, + dependencies: ['isTLSEnabled'], props: (): EuiTextAreaProps => ({ readOnly, }), @@ -1059,7 +1079,11 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ helpText: i18n.translate('xpack.synthetics.monitorConfig.clientKeyPassphrase.helpText', { defaultMessage: 'Certificate key passphrase for TLS client authentication.', }), - showWhen: ['isTLSEnabled', true], + hidden: (dependencies) => { + const [isTLSEnabled] = dependencies; + return Boolean(isTLSEnabled); + }, + dependencies: ['isTLSEnabled'], props: (): EuiFieldPasswordProps => ({ readOnly, }), @@ -1297,4 +1321,51 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ props: (): EuiFieldNumberProps => ({ min: 1, step: 'any', readOnly }), dependencies: [ConfigKey.RESPONSE_BODY_INDEX], }, + [ConfigKey.IPV4]: { + fieldKey: ConfigKey.IPV4, // also controls ipv6 + component: ComboBox, + label: i18n.translate('xpack.synthetics.monitorConfig.ipv4.label', { + defaultMessage: 'IP protocols', + }), + helpText: i18n.translate('xpack.synthetics.monitorConfig.ipv4.helpText', { + defaultMessage: 'Specifies which IP procols to use when pinging the remote host.', + }), + controlled: true, + dependencies: [ConfigKey.IPV6], + props: ({ field, setValue, dependencies }): EuiComboBoxProps => { + const [ipv6] = dependencies; + const ipv4 = field?.value; + const values: string[] = []; + if (ipv4) { + values.push('IPv4'); + } + if (ipv6) { + values.push('IPv6'); + } + return { + options: [ + { + label: 'IPv4', + }, + { + label: 'IPv6', + }, + ], + selectedOptions: values.map((version) => ({ + label: version, + })), + onChange: (updatedValues: Array>) => { + setValue( + ConfigKey.IPV4, + updatedValues.some((value) => value.label === 'IPv4') + ); + setValue( + ConfigKey.IPV6, + updatedValues.some((value) => value.label === 'IPv6') + ); + }, + isDisabled: readOnly, + }; + }, + }, }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx index e3aa6ca18308a..ce03dce4768e6 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx @@ -44,6 +44,7 @@ const HTTP_ADVANCED = (readOnly: boolean) => ({ FIELD(readOnly)[ConfigKey.REQUEST_HEADERS_CHECK], FIELD(readOnly)[ConfigKey.REQUEST_BODY_CHECK], FIELD(readOnly)[ConfigKey.MODE], + FIELD(readOnly)[ConfigKey.IPV4], ], }, responseConfig: { @@ -96,6 +97,7 @@ export const TCP_ADVANCED = (readOnly: boolean) => ({ FIELD(readOnly)[`${ConfigKey.PROXY_URL}__tcp`], FIELD(readOnly)[ConfigKey.REQUEST_SEND_CHECK], FIELD(readOnly)[ConfigKey.MODE], + FIELD(readOnly)[ConfigKey.IPV4], ], }, responseChecks: { @@ -123,7 +125,7 @@ export const ICMP_ADVANCED = (readOnly: boolean) => ({ defaultMessage: 'Configure the payload sent to the remote host.', } ), - components: [FIELD(readOnly)[ConfigKey.MODE]], + components: [FIELD(readOnly)[ConfigKey.MODE], FIELD(readOnly)[ConfigKey.IPV4]], }, }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts index 0fde75530fedf..335f956615cad 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts @@ -63,7 +63,7 @@ export interface FieldMeta { label?: string; ariaLabel?: string; helpText?: string | React.ReactNode; - hidden?: (depenencies?: unknown[]) => boolean; + hidden?: (depenencies: unknown[]) => boolean; props?: (params: { field?: ControllerRenderProps; formState: FormState; @@ -89,7 +89,6 @@ export interface FieldMeta { event: React.ChangeEvent, formOnChange: (event: React.ChangeEvent) => void ) => void; - showWhen?: [keyof FormConfig, any]; // show field when another field equals an arbitrary value validation?: (dependencies: unknown[]) => Parameters[1]; error?: React.ReactNode; dependencies?: Array; // fields that another field may depend for or validation. Values are passed to the validation function @@ -145,4 +144,5 @@ export interface FieldMap { [ConfigKey.SYNTHETICS_ARGS]: FieldMeta; [ConfigKey.IGNORE_HTTPS_ERRORS]: FieldMeta; [ConfigKey.MODE]: FieldMeta; + [ConfigKey.IPV4]: FieldMeta; } From 9144a910ce6276e46c93a23c968d087ea9e7ea8f Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 4 Apr 2023 21:14:34 -0400 Subject: [PATCH 08/27] adjust tests --- .../apis/synthetics/add_monitor_project.ts | 6 ++++++ .../apis/synthetics/add_monitor_project_legacy.ts | 10 ++++++++++ .../apis/uptime/rest/fixtures/http_monitor.json | 6 ++++-- .../apis/uptime/rest/fixtures/icmp_monitor.json | 5 ++++- .../apis/uptime/rest/fixtures/tcp_monitor.json | 5 ++++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts b/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts index b0f57fa06f4c7..41ef3e85b3e53 100644 --- a/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts +++ b/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts @@ -382,6 +382,8 @@ export default function ({ getService }: FtrProviderContext) { id: `${journeyId}-${project}-default`, hash: 'ekrjelkjrelkjre', mode: 'any', + ipv6: true, + ipv4: true, }); } } finally { @@ -491,6 +493,8 @@ export default function ({ getService }: FtrProviderContext) { id: `${journeyId}-${project}-default`, hash: 'ekrjelkjrelkjre', mode: 'any', + ipv6: true, + ipv4: true, }); } } finally { @@ -596,6 +600,8 @@ export default function ({ getService }: FtrProviderContext) { id: `${journeyId}-${project}-default`, hash: 'ekrjelkjrelkjre', mode: 'any', + ipv4: true, + ipv6: true, }); } } finally { diff --git a/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts b/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts index ff0c1bbf0f9a1..1ed05a6c56d49 100644 --- a/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts +++ b/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts @@ -300,6 +300,7 @@ export default function ({ getService }: FtrProviderContext) { proxy_url: '', 'response.include_body': 'always', 'response.include_headers': false, + 'response.include_body_max_bytes': '1024', revision: 1, schedule: { number: '60', @@ -319,6 +320,9 @@ export default function ({ getService }: FtrProviderContext) { 'url.port': null, id: `${journeyId}-test-suite-default`, hash: 'ekrjelkjrelkjre', + ipv6: true, + ipv4: true, + mode: 'any', }); } } finally { @@ -424,6 +428,9 @@ export default function ({ getService }: FtrProviderContext) { urls: '', id: `${journeyId}-test-suite-default`, hash: 'ekrjelkjrelkjre', + ipv6: true, + ipv4: true, + mode: 'any', }); } } finally { @@ -526,6 +533,9 @@ export default function ({ getService }: FtrProviderContext) { : `${parseInt(monitor.wait?.slice(0, -1) || '1', 10) * 60}`, id: `${journeyId}-test-suite-default`, hash: 'ekrjelkjrelkjre', + ipv6: true, + ipv4: true, + mode: 'any', }); } } finally { 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 b6c5ee74714f3..c1a9830182b75 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 @@ -28,7 +28,7 @@ "check.response.body.negative": [], "check.response.body.positive": [], "response.include_body": "never", - "resposne.include_body_max_bytes": "1024", + "response.include_body_max_bytes": "1024", "check.request.headers": { "sampleHeader": "sampleHeaderValue" }, @@ -83,5 +83,7 @@ "journey_id": "", "id": "", "hash": "", - "mode": "any" + "mode": "any", + "ipv4": true, + "ipv6": true } 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 ab172c3fe8ca5..ef94fcc067a98 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 @@ -26,5 +26,8 @@ "origin": "ui", "form_monitor_type": "icmp", "id": "", - "hash": "" + "hash": "", + "mode": "any", + "ipv4": true, + "ipv6": true } 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 209ef89373736..172778d7855af 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 @@ -35,5 +35,8 @@ "origin": "ui", "form_monitor_type": "tcp", "id": "", - "hash": "" + "hash": "", + "mode": "any", + "ipv4": true, + "ipv6": true } From 431a4c2d69502687fb07b7ddb8936cb949a1e09a Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 4 Apr 2023 23:47:24 -0400 Subject: [PATCH 09/27] add monitor proxy headers --- .../common/constants/monitor_defaults.ts | 1 + .../common/constants/monitor_management.ts | 2 ++ .../common/formatters/http/formatters.ts | 1 + .../monitor_management/monitor_types.ts | 23 +++++++++++-------- .../monitor_add_edit/form/field_config.tsx | 20 ++++++++++++++++ .../monitor_add_edit/form/form_config.tsx | 3 ++- .../components/monitor_add_edit/types.ts | 1 + .../fleet_package/request_body_field.test.tsx | 4 ++-- .../apis/synthetics/add_monitor_project.ts | 4 +++- .../synthetics/add_monitor_project_legacy.ts | 3 ++- .../uptime/rest/fixtures/http_monitor.json | 1 + .../rest/fixtures/project_http_monitor.json | 3 ++- 12 files changed, 51 insertions(+), 15 deletions(-) diff --git a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts index eb6b4324c5217..00efd0f90ec80 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts @@ -120,6 +120,7 @@ export const DEFAULT_HTTP_SIMPLE_FIELDS: HTTPSimpleFields = { export const DEFAULT_HTTP_ADVANCED_FIELDS: HTTPAdvancedFields = { [ConfigKey.PASSWORD]: '', [ConfigKey.PROXY_URL]: '', + [ConfigKey.PROXY_HEADERS]: {}, [ConfigKey.RESPONSE_BODY_CHECK_NEGATIVE]: [], [ConfigKey.RESPONSE_BODY_CHECK_POSITIVE]: [], [ConfigKey.RESPONSE_BODY_INDEX]: ResponseBodyIndexPolicy.ON_ERROR, diff --git a/x-pack/plugins/synthetics/common/constants/monitor_management.ts b/x-pack/plugins/synthetics/common/constants/monitor_management.ts index 839ca46600797..50283e916cc7e 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_management.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_management.ts @@ -38,6 +38,7 @@ export enum ConfigKey { ORIGINAL_SPACE = 'original_space', // the original space the montior was saved in. Used by push monitors to ensure uniqueness of monitor id sent to heartbeat and prevent data collisions PORT = 'url.port', PROXY_URL = 'proxy_url', + PROXY_HEADERS = 'proxy_headers', PROXY_USE_LOCAL_RESOLVER = 'proxy_use_local_resolver', RESPONSE_BODY_CHECK_NEGATIVE = 'check.response.body.negative', RESPONSE_BODY_CHECK_POSITIVE = 'check.response.body.positive', @@ -92,6 +93,7 @@ export enum ConfigKey { } export const secretKeys = [ + ConfigKey.PROXY_HEADERS, ConfigKey.PARAMS, ConfigKey.PASSWORD, ConfigKey.REQUEST_BODY_CHECK, diff --git a/x-pack/plugins/synthetics/common/formatters/http/formatters.ts b/x-pack/plugins/synthetics/common/formatters/http/formatters.ts index 8c8b2dee6a4b2..7f6b98dc3a36e 100644 --- a/x-pack/plugins/synthetics/common/formatters/http/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/http/formatters.ts @@ -23,6 +23,7 @@ export const httpFormatters: HTTPFormatMap = { [ConfigKey.USERNAME]: null, [ConfigKey.PASSWORD]: null, [ConfigKey.PROXY_URL]: null, + [ConfigKey.PROXY_HEADERS]: objectToJsonFormatter, [ConfigKey.PORT]: null, [ConfigKey.RESPONSE_BODY_CHECK_NEGATIVE]: arrayToJsonFormatter, [ConfigKey.RESPONSE_BODY_CHECK_POSITIVE]: arrayToJsonFormatter, 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 a1ab47b7e5e2d..e3ab5c60354ab 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 @@ -204,15 +204,20 @@ export const HTTPAdvancedFieldsCodec = t.intersection([ }), ]); -export const HTTPSensitiveAdvancedFieldsCodec = t.interface({ - [ConfigKey.PASSWORD]: t.string, - [ConfigKey.RESPONSE_BODY_CHECK_NEGATIVE]: t.array(t.string), - [ConfigKey.RESPONSE_BODY_CHECK_POSITIVE]: t.array(t.string), - [ConfigKey.RESPONSE_HEADERS_CHECK]: t.record(t.string, t.string), - [ConfigKey.REQUEST_BODY_CHECK]: t.interface({ value: t.string, type: CodeEditorModeCodec }), - [ConfigKey.REQUEST_HEADERS_CHECK]: t.record(t.string, t.string), - [ConfigKey.USERNAME]: t.string, -}); +export const HTTPSensitiveAdvancedFieldsCodec = t.intersection([ + t.interface({ + [ConfigKey.PASSWORD]: t.string, + [ConfigKey.RESPONSE_BODY_CHECK_NEGATIVE]: t.array(t.string), + [ConfigKey.RESPONSE_BODY_CHECK_POSITIVE]: t.array(t.string), + [ConfigKey.RESPONSE_HEADERS_CHECK]: t.record(t.string, t.string), + [ConfigKey.REQUEST_BODY_CHECK]: t.interface({ value: t.string, type: CodeEditorModeCodec }), + [ConfigKey.REQUEST_HEADERS_CHECK]: t.record(t.string, t.string), + [ConfigKey.USERNAME]: t.string, + }), + t.partial({ + [ConfigKey.PROXY_HEADERS]: t.record(t.string, t.string), + }), +]); export const HTTPAdvancedCodec = t.intersection([ HTTPAdvancedFieldsCodec, diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 7865f79713495..96ee70395d583 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -1368,4 +1368,24 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ }; }, }, + [ConfigKey.PROXY_HEADERS]: { + fieldKey: ConfigKey.PROXY_HEADERS, + component: HeaderField, + label: i18n.translate('xpack.synthetics.monitorConfig.proxyHeaders.label', { + defaultMessage: 'Proxy headers', + }), + helpText: i18n.translate('xpack.synthetics.monitorConfig.proxyHeaders.helpText', { + defaultMessage: 'Additional headers to send to proxies during CONNECT requests.', + }), + controlled: true, + validation: () => ({ + validate: (headers) => !validateHeaders(headers), + }), + error: i18n.translate('xpack.synthetics.monitorConfig.proxyHeaders.error', { + defaultMessage: 'Header key must be a valid HTTP token.', + }), + props: (): HeaderFieldProps => ({ + readOnly, + }), + }, }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx index ce03dce4768e6..3276cafb1abba 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx @@ -39,10 +39,11 @@ const HTTP_ADVANCED = (readOnly: boolean) => ({ components: [ FIELD(readOnly)[ConfigKey.USERNAME], FIELD(readOnly)[ConfigKey.PASSWORD], - FIELD(readOnly)[ConfigKey.PROXY_URL], FIELD(readOnly)[ConfigKey.REQUEST_METHOD_CHECK], FIELD(readOnly)[ConfigKey.REQUEST_HEADERS_CHECK], FIELD(readOnly)[ConfigKey.REQUEST_BODY_CHECK], + FIELD(readOnly)[ConfigKey.PROXY_URL], + FIELD(readOnly)[ConfigKey.PROXY_HEADERS], FIELD(readOnly)[ConfigKey.MODE], FIELD(readOnly)[ConfigKey.IPV4], ], diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts index 335f956615cad..ec3ac02c134b8 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts @@ -123,6 +123,7 @@ export interface FieldMap { [ConfigKey.USERNAME]: FieldMeta; [ConfigKey.PASSWORD]: FieldMeta; [ConfigKey.PROXY_URL]: FieldMeta; + [ConfigKey.PROXY_HEADERS]: FieldMeta; ['proxy_url__tcp']: FieldMeta; [ConfigKey.REQUEST_METHOD_CHECK]: FieldMeta; [ConfigKey.REQUEST_HEADERS_CHECK]: FieldMeta; diff --git a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/request_body_field.test.tsx b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/request_body_field.test.tsx index 8f64a95f05e7c..649f813d3eb89 100644 --- a/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/request_body_field.test.tsx +++ b/x-pack/plugins/synthetics/public/legacy_uptime/components/fleet_package/request_body_field.test.tsx @@ -11,7 +11,7 @@ import React, { useState, useCallback } from 'react'; import { fireEvent, waitFor } from '@testing-library/react'; import { render } from '../../lib/helper/rtl_helpers'; import { RequestBodyField } from './request_body_field'; -import { Mode } from './types'; +import { CodeEditorMode } from './types'; jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => ({ htmlIdGenerator: () => () => `id-${Math.random()}`, @@ -48,7 +48,7 @@ describe('', () => { type={config.type} value={config.value} onChange={useCallback( - (code) => setConfig({ type: code.type as Mode, value: code.value }), + (code) => setConfig({ type: code.type as CodeEditorMode, value: code.value }), [setConfig] )} /> diff --git a/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts b/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts index 41ef3e85b3e53..54e7e5ce0e6a3 100644 --- a/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts +++ b/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts @@ -359,9 +359,10 @@ export default function ({ getService }: FtrProviderContext) { username: '', password: '', proxy_url: '', + proxy_headers: {}, 'response.include_body': 'always', 'response.include_headers': false, - 'response.include_body_max_bytes': '1024', + 'response.include_body_max_bytes': '900', revision: 1, schedule: { number: '60', @@ -1804,6 +1805,7 @@ export default function ({ getService }: FtrProviderContext) { name: 'My Monitor 3', response: { include_body: 'always', + include_body_max_bytes: '900', }, 'response.include_headers': false, schedule: 60, diff --git a/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts b/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts index 1ed05a6c56d49..16d59e6d3868b 100644 --- a/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts +++ b/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts @@ -298,9 +298,10 @@ export default function ({ getService }: FtrProviderContext) { username: '', password: '', proxy_url: '', + proxy_headers: {}, 'response.include_body': 'always', 'response.include_headers': false, - 'response.include_body_max_bytes': '1024', + 'response.include_body_max_bytes': '900', revision: 1, schedule: { number: '60', 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 c1a9830182b75..dfabe0721d005 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 @@ -25,6 +25,7 @@ "urls": "https://nextjs-test-synthetics.vercel.app/api/users", "url.port": null, "proxy_url": "http://proxy.com", + "proxy_headers": {}, "check.response.body.negative": [], "check.response.body.positive": [], "response.include_body": "never", diff --git a/x-pack/test/api_integration/apis/uptime/rest/fixtures/project_http_monitor.json b/x-pack/test/api_integration/apis/uptime/rest/fixtures/project_http_monitor.json index c8c2c27ce0f17..3479e85b817d7 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/fixtures/project_http_monitor.json +++ b/x-pack/test/api_integration/apis/uptime/rest/fixtures/project_http_monitor.json @@ -56,7 +56,8 @@ } }, "response": { - "include_body": "always" + "include_body": "always", + "include_body_max_bytes": "900" }, "tags": "tag2,tag2", "response.include_headers": false, From 4f41b0c9285ded75a314eac42577aae5ee6d4350 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Tue, 4 Apr 2023 23:58:41 -0400 Subject: [PATCH 10/27] handle converting response_body_max_bytes to a string --- .../project_monitor/normalizers/http_monitor.ts | 1 + .../apis/uptime/rest/fixtures/project_http_monitor.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts index c2b5f86737a8a..a683e328ef580 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts @@ -70,6 +70,7 @@ export const getNormalizeHTTPFields = ({ (yamlConfig as Record)[ConfigKey.REQUEST_BODY_CHECK] as string, defaultFields[ConfigKey.REQUEST_BODY_CHECK] ), + [ConfigKey.RESPONSE_BODY_MAX_BYTES]: `${get(yamlConfig, ConfigKey.RESPONSE_BODY_MAX_BYTES)}`, [ConfigKey.TLS_VERSION]: get(monitor, ConfigKey.TLS_VERSION) ? (getOptionalListField(get(monitor, ConfigKey.TLS_VERSION)) as TLSVersion[]) : defaultFields[ConfigKey.TLS_VERSION], diff --git a/x-pack/test/api_integration/apis/uptime/rest/fixtures/project_http_monitor.json b/x-pack/test/api_integration/apis/uptime/rest/fixtures/project_http_monitor.json index 3479e85b817d7..f5f496c27141e 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/fixtures/project_http_monitor.json +++ b/x-pack/test/api_integration/apis/uptime/rest/fixtures/project_http_monitor.json @@ -57,7 +57,7 @@ }, "response": { "include_body": "always", - "include_body_max_bytes": "900" + "include_body_max_bytes": 900 }, "tags": "tag2,tag2", "response.include_headers": false, From 6d2c7344d9a0af23b10423ac1f3b4ddaf8d9ad04 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 5 Apr 2023 13:25:45 -0400 Subject: [PATCH 11/27] add response check json to http monitor --- .../common/constants/monitor_defaults.ts | 1 + .../common/constants/monitor_management.ts | 2 + .../monitor_management/monitor_configs.ts | 6 ++ .../monitor_management/monitor_types.ts | 2 + .../fields/key_value_field.tsx | 16 +++-- .../monitor_add_edit/form/field_config.tsx | 61 +++++++++++++++++++ .../monitor_add_edit/form/field_wrappers.tsx | 8 +++ .../monitor_add_edit/form/form_config.tsx | 1 + .../components/monitor_add_edit/types.ts | 7 +++ .../uptime/rest/fixtures/http_monitor.json | 1 + 10 files changed, 99 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts index cdf99595fcf05..b5d87824064af 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_defaults.ts @@ -122,6 +122,7 @@ export const DEFAULT_HTTP_ADVANCED_FIELDS: HTTPAdvancedFields = { [ConfigKey.PROXY_HEADERS]: {}, [ConfigKey.RESPONSE_BODY_CHECK_NEGATIVE]: [], [ConfigKey.RESPONSE_BODY_CHECK_POSITIVE]: [], + [ConfigKey.RESPONSE_JSON_CHECK]: [], [ConfigKey.RESPONSE_BODY_INDEX]: ResponseBodyIndexPolicy.ON_ERROR, [ConfigKey.RESPONSE_HEADERS_CHECK]: {}, [ConfigKey.RESPONSE_HEADERS_INDEX]: true, diff --git a/x-pack/plugins/synthetics/common/constants/monitor_management.ts b/x-pack/plugins/synthetics/common/constants/monitor_management.ts index 17ccbdf655fb3..4bd22f8f8ba23 100644 --- a/x-pack/plugins/synthetics/common/constants/monitor_management.ts +++ b/x-pack/plugins/synthetics/common/constants/monitor_management.ts @@ -42,6 +42,7 @@ export enum ConfigKey { PROXY_USE_LOCAL_RESOLVER = 'proxy_use_local_resolver', RESPONSE_BODY_CHECK_NEGATIVE = 'check.response.body.negative', RESPONSE_BODY_CHECK_POSITIVE = 'check.response.body.positive', + RESPONSE_JSON_CHECK = 'check.response.json', RESPONSE_BODY_INDEX = 'response.include_body', RESPONSE_HEADERS_CHECK = 'check.response.headers', RESPONSE_HEADERS_INDEX = 'response.include_headers', @@ -90,6 +91,7 @@ export const secretKeys = [ ConfigKey.REQUEST_SEND_CHECK, ConfigKey.RESPONSE_BODY_CHECK_NEGATIVE, ConfigKey.RESPONSE_BODY_CHECK_POSITIVE, + ConfigKey.RESPONSE_JSON_CHECK, ConfigKey.RESPONSE_HEADERS_CHECK, ConfigKey.RESPONSE_RECEIVE_CHECK, ConfigKey.SOURCE_INLINE, diff --git a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_configs.ts b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_configs.ts index a08ec3e5914a3..941adaa4e518e 100644 --- a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_configs.ts +++ b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_configs.ts @@ -143,3 +143,9 @@ export enum Mode { } export const ModeCodec = tEnum('Mode', Mode); export type ModeType = t.TypeOf; + +export const ResponseCheckJSONCodec = t.interface({ + label: t.string, + expression: t.string, +}); +export type ResponseCheckJSON = t.TypeOf; 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 1c1f54d8c1d02..19a6fe0c25b74 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 @@ -17,6 +17,7 @@ import { FormMonitorTypeCodec, ModeCodec, ResponseBodyIndexPolicyCodec, + ResponseCheckJSONCodec, ScheduleUnitCodec, SourceTypeCodec, TLSVersionCodec, @@ -199,6 +200,7 @@ export const HTTPSensitiveAdvancedFieldsCodec = t.intersection([ }), t.partial({ [ConfigKey.PROXY_HEADERS]: t.record(t.string, t.string), + [ConfigKey.RESPONSE_JSON_CHECK]: t.array(ResponseCheckJSONCodec), }), ]); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/key_value_field.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/key_value_field.tsx index 95b2348fd0219..7d062fbde7548 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/key_value_field.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/fields/key_value_field.tsx @@ -46,13 +46,15 @@ export type Pair = [ string // value ]; -interface Props { +export interface KeyValuePairsFieldProps { addPairControlLabel: string | React.ReactElement; defaultPairs: Pair[]; onChange: (pairs: Pair[]) => void; onBlur?: () => void; 'data-test-subj'?: string; readOnly?: boolean; + keyLabel?: string | React.ReactElement; + valueLabel?: string | React.ReactElement; } export const KeyValuePairsField = ({ @@ -62,7 +64,9 @@ export const KeyValuePairsField = ({ onBlur, 'data-test-subj': dataTestSubj, readOnly, -}: Props) => { + keyLabel, + valueLabel, +}: KeyValuePairsFieldProps) => { const [pairs, setPairs] = useState(defaultPairs); const handleOnChange = useCallback( @@ -121,20 +125,20 @@ export const KeyValuePairsField = ({ children: ( - { + {keyLabel || ( - } + )} - { + {valueLabel || ( - } + )} ), diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 495984d9a9b7c..c0b5589ad6729 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -6,6 +6,7 @@ */ import React from 'react'; +import { isEqual } from 'lodash'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { isValidNamespace } from '@kbn/fleet-plugin/common'; @@ -53,6 +54,7 @@ import { ResponseBodyIndexField, ResponseBodyIndexFieldProps, ControlledFieldProp, + KeyValuePairsField, } from './field_wrappers'; import { getDocLinks } from '../../../../../kibana_services'; import { useMonitorName } from '../hooks/use_monitor_name'; @@ -69,6 +71,7 @@ import { FieldMap, FormLocation, ResponseBodyIndexPolicy, + ResponseCheckJSON, } from '../types'; import { AlertConfigKey, @@ -77,6 +80,7 @@ import { } from '../constants'; import { getDefaultFormFields } from './defaults'; import { validate, validateHeaders, WHOLE_NUMBERS_ONLY, FLOATS_ONLY } from './validation'; +import { KeyValuePairsFieldProps } from '../fields/key_value_field'; const getScheduleContent = (value: number) => { if (value > 60) { @@ -1384,4 +1388,61 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ readOnly, }), }, + ['check.response.json']: { + fieldKey: ConfigKey.RESPONSE_JSON_CHECK, + component: KeyValuePairsField, + label: i18n.translate('xpack.synthetics.monitorConfig.responseJSON.label', { + defaultMessage: 'Check response body contains JSON', + }), + helpText: i18n.translate('xpack.synthetics.monitorConfig.responseJSON.helpText', { + defaultMessage: + 'A list of expressions executed against the body when parsed as JSON. Body sizes must be less than or equal to 100 MiB', + }), + controlled: true, + error: i18n.translate('xpack.synthetics.monitorConfig.proxyHeaders.error', { + defaultMessage: 'Header key must be a valid HTTP token.', + }), + props: ({ field, setValue }): KeyValuePairsFieldProps => ({ + readOnly, + keyLabel: i18n.translate('xpack.synthetics.monitorConfig.responseJSON.key.label', { + defaultMessage: 'Label', + }), + valueLabel: i18n.translate('xpack.synthetics.monitorConfig.responseJSON.value.label', { + defaultMessage: 'Expression', + }), + addPairControlLabel: i18n.translate( + 'xpack.synthetics.monitorConfig.responseJSON.addPair.label', + { + defaultMessage: 'Add expression', + } + ), + onChange: (pairs) => { + const value: ResponseCheckJSON[] = pairs + .map((pair) => { + const [label, expression] = pair; + return { + label, + expression, + }; + }) + .filter((pair) => pair.label || pair.expression); + if (!isEqual(value, field?.value)) { + setValue(ConfigKey.RESPONSE_JSON_CHECK, value); + } + }, + defaultPairs: field?.value.map((check) => [check.label, check.expression]) || [], + }), + validation: () => { + return { + validate: (value: ResponseCheckJSON[]) => { + if (value.some((check) => !check.expression || !check.label)) { + return i18n.translate('xpack.synthetics.monitorConfig.responseJSON.error', { + defaultMessage: + 'Invalid JSON expression. Please ensure both the label and expression are defined.', + }); + } + }, + }; + }, + }, }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_wrappers.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_wrappers.tsx index 80455d8dd4e4d..8fda195ba1c01 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_wrappers.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_wrappers.tsx @@ -43,6 +43,10 @@ import { HeaderField as DefaultHeaderField, HeaderFieldProps as DefaultHeaderFieldProps, } from '../fields/header_field'; +import { + KeyValuePairsField as DefaultKeyValuePairsField, + KeyValuePairsFieldProps as DefaultKeyValuePairsFieldProps, +} from '../fields/key_value_field'; import { RequestBodyField as DefaultRequestBodyField, RequestBodyFieldProps as DefaultRequestBodyFieldProps, @@ -125,6 +129,10 @@ export const HeaderField = React.forwardRef((p )); +export const KeyValuePairsField = React.forwardRef( + (props, _ref) => +); + export const RequestBodyField = React.forwardRef( (props, _ref) => ); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx index 3276cafb1abba..87577ca3beb04 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/form_config.tsx @@ -79,6 +79,7 @@ const HTTP_ADVANCED = (readOnly: boolean) => ({ FIELD(readOnly)[ConfigKey.RESPONSE_HEADERS_CHECK], FIELD(readOnly)[ConfigKey.RESPONSE_BODY_CHECK_POSITIVE], FIELD(readOnly)[ConfigKey.RESPONSE_BODY_CHECK_NEGATIVE], + FIELD(readOnly)[ConfigKey.RESPONSE_JSON_CHECK], ], }, }); diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts index ec3ac02c134b8..6abe63786563e 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/types.ts @@ -17,6 +17,7 @@ import { ServiceLocation, FormMonitorType, MonitorFields, + ResponseCheckJSON, } from '../../../../../common/runtime_types/monitor_management'; import { AlertConfigKey } from './constants'; @@ -55,6 +56,11 @@ export type FormConfig = MonitorFields & { ssl: { supported_protocols: MonitorFields[ConfigKey.TLS_VERSION]; }; + check: { + response: { + json: ResponseCheckJSON[]; + }; + }; }; export interface FieldMeta { @@ -135,6 +141,7 @@ export interface FieldMap { [ConfigKey.RESPONSE_HEADERS_CHECK]: FieldMeta; [ConfigKey.RESPONSE_BODY_CHECK_POSITIVE]: FieldMeta; [ConfigKey.RESPONSE_BODY_CHECK_NEGATIVE]: FieldMeta; + [ConfigKey.RESPONSE_JSON_CHECK]: FieldMeta; [ConfigKey.RESPONSE_RECEIVE_CHECK]: FieldMeta; [ConfigKey.REQUEST_SEND_CHECK]: FieldMeta; ['source.inline']: FieldMeta; 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 dfabe0721d005..b2961eb0660d6 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 @@ -28,6 +28,7 @@ "proxy_headers": {}, "check.response.body.negative": [], "check.response.body.positive": [], + "check.response.json": [], "response.include_body": "never", "response.include_body_max_bytes": "1024", "check.request.headers": { From 3e165ad9c793db9b6903db29a645d39ce09529a0 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 5 Apr 2023 18:11:56 -0400 Subject: [PATCH 12/27] adjust tests --- .../synthetics/common/formatters/http/formatters.ts | 1 + .../monitor_management/monitor_configs.ts | 2 +- .../monitor_add_edit/form/field_config.tsx | 12 ++++++------ .../project_monitor/normalizers/http_monitor.ts | 6 +++++- .../apis/synthetics/add_monitor_project.ts | 6 +++++- .../apis/synthetics/add_monitor_project_legacy.ts | 3 +++ .../uptime/rest/fixtures/project_http_monitor.json | 3 ++- 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/synthetics/common/formatters/http/formatters.ts b/x-pack/plugins/synthetics/common/formatters/http/formatters.ts index 7f6b98dc3a36e..437112939f283 100644 --- a/x-pack/plugins/synthetics/common/formatters/http/formatters.ts +++ b/x-pack/plugins/synthetics/common/formatters/http/formatters.ts @@ -27,6 +27,7 @@ export const httpFormatters: HTTPFormatMap = { [ConfigKey.PORT]: null, [ConfigKey.RESPONSE_BODY_CHECK_NEGATIVE]: arrayToJsonFormatter, [ConfigKey.RESPONSE_BODY_CHECK_POSITIVE]: arrayToJsonFormatter, + [ConfigKey.RESPONSE_JSON_CHECK]: arrayToJsonFormatter, [ConfigKey.RESPONSE_HEADERS_CHECK]: objectToJsonFormatter, [ConfigKey.RESPONSE_STATUS_CHECK]: arrayToJsonFormatter, [ConfigKey.REQUEST_HEADERS_CHECK]: objectToJsonFormatter, diff --git a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_configs.ts b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_configs.ts index 941adaa4e518e..a88494f57449c 100644 --- a/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_configs.ts +++ b/x-pack/plugins/synthetics/common/runtime_types/monitor_management/monitor_configs.ts @@ -145,7 +145,7 @@ export const ModeCodec = tEnum('Mode', Mode); export type ModeType = t.TypeOf; export const ResponseCheckJSONCodec = t.interface({ - label: t.string, + description: t.string, expression: t.string, }); export type ResponseCheckJSON = t.TypeOf; diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index c0b5589ad6729..0125c7a92732a 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -1405,7 +1405,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ props: ({ field, setValue }): KeyValuePairsFieldProps => ({ readOnly, keyLabel: i18n.translate('xpack.synthetics.monitorConfig.responseJSON.key.label', { - defaultMessage: 'Label', + defaultMessage: 'Description', }), valueLabel: i18n.translate('xpack.synthetics.monitorConfig.responseJSON.value.label', { defaultMessage: 'Expression', @@ -1419,23 +1419,23 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ onChange: (pairs) => { const value: ResponseCheckJSON[] = pairs .map((pair) => { - const [label, expression] = pair; + const [description, expression] = pair; return { - label, + description, expression, }; }) - .filter((pair) => pair.label || pair.expression); + .filter((pair) => pair.description || pair.expression); if (!isEqual(value, field?.value)) { setValue(ConfigKey.RESPONSE_JSON_CHECK, value); } }, - defaultPairs: field?.value.map((check) => [check.label, check.expression]) || [], + defaultPairs: field?.value.map((check) => [check.description, check.expression]) || [], }), validation: () => { return { validate: (value: ResponseCheckJSON[]) => { - if (value.some((check) => !check.expression || !check.label)) { + if (value.some((check) => !check.expression || !check.description)) { return i18n.translate('xpack.synthetics.monitorConfig.responseJSON.error', { defaultMessage: 'Invalid JSON expression. Please ensure both the label and expression are defined.', diff --git a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts index a683e328ef580..0045cc711f9bc 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/project_monitor/normalizers/http_monitor.ts @@ -70,7 +70,11 @@ export const getNormalizeHTTPFields = ({ (yamlConfig as Record)[ConfigKey.REQUEST_BODY_CHECK] as string, defaultFields[ConfigKey.REQUEST_BODY_CHECK] ), - [ConfigKey.RESPONSE_BODY_MAX_BYTES]: `${get(yamlConfig, ConfigKey.RESPONSE_BODY_MAX_BYTES)}`, + [ConfigKey.RESPONSE_BODY_MAX_BYTES]: `${get( + yamlConfig, + ConfigKey.RESPONSE_BODY_MAX_BYTES, + defaultFields[ConfigKey.RESPONSE_BODY_MAX_BYTES] + )}`, [ConfigKey.TLS_VERSION]: get(monitor, ConfigKey.TLS_VERSION) ? (getOptionalListField(get(monitor, ConfigKey.TLS_VERSION)) as TLSVersion[]) : defaultFields[ConfigKey.TLS_VERSION], diff --git a/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts b/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts index e349ae954bbdf..3f96bdce4483f 100644 --- a/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts +++ b/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts @@ -317,6 +317,9 @@ export default function ({ getService }: FtrProviderContext) { custom_heartbeat_id: `${journeyId}-${project}-default`, 'check.response.body.negative': [], 'check.response.body.positive': ['Saved', 'saved'], + 'check.response.json': [ + { description: 'check status', expression: 'foo.bar == "myValue"' }, + ], 'check.response.headers': {}, 'check.request.body': { type: 'text', @@ -1791,6 +1794,7 @@ export default function ({ getService }: FtrProviderContext) { positive: ['Saved', 'saved'], }, status: [200], + json: [{ description: 'check status', expression: 'foo.bar == "myValue"' }], }, enabled: false, hash: 'ekrjelkjrelkjre', @@ -1799,7 +1803,7 @@ export default function ({ getService }: FtrProviderContext) { name: 'My Monitor 3', response: { include_body: 'always', - include_body_max_bytes: '900', + include_body_max_bytes: 900, }, 'response.include_headers': false, schedule: 60, diff --git a/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts b/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts index 86a7256e16fca..0f4c62d830bd0 100644 --- a/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts +++ b/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts @@ -256,6 +256,9 @@ export default function ({ getService }: FtrProviderContext) { custom_heartbeat_id: `${journeyId}-test-suite-default`, 'check.response.body.negative': [], 'check.response.body.positive': ['Saved', 'saved'], + 'check.response.json': [ + { description: 'check status', expression: 'foo.bar == "myValue"' }, + ], 'check.response.headers': {}, 'check.request.body': { type: 'text', diff --git a/x-pack/test/api_integration/apis/uptime/rest/fixtures/project_http_monitor.json b/x-pack/test/api_integration/apis/uptime/rest/fixtures/project_http_monitor.json index f5f496c27141e..dd6d6eefecfcd 100644 --- a/x-pack/test/api_integration/apis/uptime/rest/fixtures/project_http_monitor.json +++ b/x-pack/test/api_integration/apis/uptime/rest/fixtures/project_http_monitor.json @@ -70,7 +70,8 @@ "Saved", "saved" ] - } + }, + "json": [{"description":"check status","expression":"foo.bar == \"myValue\""}] }, "hash": "ekrjelkjrelkjre", "ssl.verification_mode": "strict" From 26a53ede1a66a2035822cb3f46ccbba4ccf9d0e2 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 5 Apr 2023 18:22:11 -0400 Subject: [PATCH 13/27] add test --- .../formatters/format_configs.test.ts | 28 ++++++++++++++++++- .../synthetics_service/formatters/http.ts | 2 ++ 2 files changed, 29 insertions(+), 1 deletion(-) 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 3c7f7cc437d0c..8424573cf6b84 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 @@ -39,8 +39,16 @@ const testHTTPConfig: Partial = { proxy_url: '${proxyUrl}', 'check.response.body.negative': [], 'check.response.body.positive': [], + 'check.response.json': [ + { + description: 'test description', + expression: 'foo.bar == "myValue"', + }, + ], 'response.include_body': 'on_error' as ResponseBodyIndexPolicy, - 'check.response.headers': {}, + 'check.response.headers': { + 'test-header': 'test-value', + }, 'response.include_headers': true, 'check.response.status': [], 'check.request.body': { type: 'text' as CodeEditorMode, value: '' }, @@ -95,6 +103,15 @@ describe('formatMonitorConfig', () => { expect(yamlConfig).toEqual({ 'check.request.method': 'GET', + 'check.response.headers': { + 'test-header': 'test-value', + }, + 'check.response.json': [ + { + description: 'test description', + expression: 'foo.bar == "myValue"', + }, + ], enabled: true, locations: [], max_redirects: '0', @@ -125,6 +142,15 @@ describe('formatMonitorConfig', () => { expect(yamlConfig).toEqual({ 'check.request.method': 'GET', + 'check.response.headers': { + 'test-header': 'test-value', + }, + 'check.response.json': [ + { + description: 'test description', + expression: 'foo.bar == "myValue"', + }, + ], enabled: true, locations: [], max_redirects: '0', diff --git a/x-pack/plugins/synthetics/server/synthetics_service/formatters/http.ts b/x-pack/plugins/synthetics/server/synthetics_service/formatters/http.ts index 43c1a5e76ea70..4f65e7546d966 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/formatters/http.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/formatters/http.ts @@ -17,10 +17,12 @@ export const httpFormatters: HTTPFormatMap = { [ConfigKey.METADATA]: objectFormatter, [ConfigKey.RESPONSE_BODY_CHECK_NEGATIVE]: arrayFormatter, [ConfigKey.RESPONSE_BODY_CHECK_POSITIVE]: arrayFormatter, + [ConfigKey.RESPONSE_JSON_CHECK]: arrayFormatter, [ConfigKey.RESPONSE_HEADERS_CHECK]: objectFormatter, [ConfigKey.RESPONSE_STATUS_CHECK]: arrayFormatter, [ConfigKey.REQUEST_HEADERS_CHECK]: objectFormatter, [ConfigKey.REQUEST_BODY_CHECK]: (fields) => fields[ConfigKey.REQUEST_BODY_CHECK]?.value || null, + [ConfigKey.PROXY_HEADERS]: objectFormatter, ...tlsFormatters, ...commonFormatters, }; From 39cce025a99f965d21ea433c337743f89719048c Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Thu, 6 Apr 2023 09:46:06 -0400 Subject: [PATCH 14/27] adjust test for private locations --- .../saved_objects/migrations/monitors/8.8.0.ts | 2 +- .../apis/synthetics/add_monitor_project.ts | 2 +- .../synthetics/sample_data/test_browser_policy.ts | 10 ++-------- .../apis/synthetics/sample_data/test_policy.ts | 10 ++-------- .../sample_data/test_project_monitor_policy.ts | 15 +++++++-------- 5 files changed, 13 insertions(+), 26 deletions(-) diff --git a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.8.0.ts b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.8.0.ts index bd15dae2d3c2c..0e5c35edb72c8 100644 --- a/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.8.0.ts +++ b/x-pack/plugins/synthetics/server/legacy_uptime/lib/saved_objects/migrations/monitors/8.8.0.ts @@ -90,7 +90,7 @@ const getNearestSupportedSchedule = (currentSchedule: string): string => { return closest; } catch { - return ALLOWED_SCHEDULES_IN_MINUTES[0]; + return '10'; } }; diff --git a/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts b/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts index 3f96bdce4483f..29309921757b0 100644 --- a/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts +++ b/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts @@ -73,7 +73,7 @@ export default function ({ getService }: FtrProviderContext) { await supertest.post(API_URLS.SYNTHETICS_ENABLEMENT).set('kbn-xsrf', 'true').expect(200); await supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200); await supertest - .post('/api/fleet/epm/packages/synthetics/0.11.4') + .post('/api/fleet/epm/packages/synthetics/0.12.0') .set('kbn-xsrf', 'true') .send({ force: true }) .expect(200); diff --git a/x-pack/test/api_integration/apis/synthetics/sample_data/test_browser_policy.ts b/x-pack/test/api_integration/apis/synthetics/sample_data/test_browser_policy.ts index 0cebf231cf787..3484ee3a54df7 100644 --- a/x-pack/test/api_integration/apis/synthetics/sample_data/test_browser_policy.ts +++ b/x-pack/test/api_integration/apis/synthetics/sample_data/test_browser_policy.ts @@ -246,10 +246,7 @@ export const getTestBrowserSyntheticsPolicy = ({ }, id: 'synthetics/browser-browser.network-abf904a4-cb9a-4b29-8c11-4d183cca289b-fe621d20-7b01-11ed-803f-475d82e1f9ca-default', compiled_stream: { - processors: [ - { add_observer_metadata: { geo: { name: 'Fleet managed' } } }, - { add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }, - ], + processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }], }, }, { @@ -261,10 +258,7 @@ export const getTestBrowserSyntheticsPolicy = ({ }, id: 'synthetics/browser-browser.screenshot-abf904a4-cb9a-4b29-8c11-4d183cca289b-fe621d20-7b01-11ed-803f-475d82e1f9ca-default', compiled_stream: { - processors: [ - { add_observer_metadata: { geo: { name: 'Fleet managed' } } }, - { add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }, - ], + processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }], }, }, ], diff --git a/x-pack/test/api_integration/apis/synthetics/sample_data/test_policy.ts b/x-pack/test/api_integration/apis/synthetics/sample_data/test_policy.ts index 82e19948779bb..f57f514f9ee98 100644 --- a/x-pack/test/api_integration/apis/synthetics/sample_data/test_policy.ts +++ b/x-pack/test/api_integration/apis/synthetics/sample_data/test_policy.ts @@ -299,10 +299,7 @@ export const getTestSyntheticsPolicy = ( }, id: 'synthetics/browser-browser.network-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default', compiled_stream: { - processors: [ - { add_observer_metadata: { geo: { name: 'Fleet managed' } } }, - { add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }, - ], + processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }], }, }, { @@ -318,10 +315,7 @@ export const getTestSyntheticsPolicy = ( }, id: 'synthetics/browser-browser.screenshot-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default', compiled_stream: { - processors: [ - { add_observer_metadata: { geo: { name: 'Fleet managed' } } }, - { add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }, - ], + processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }], }, }, ], diff --git a/x-pack/test/api_integration/apis/synthetics/sample_data/test_project_monitor_policy.ts b/x-pack/test/api_integration/apis/synthetics/sample_data/test_project_monitor_policy.ts index cd5ea22451b92..11b0b75817d02 100644 --- a/x-pack/test/api_integration/apis/synthetics/sample_data/test_project_monitor_policy.ts +++ b/x-pack/test/api_integration/apis/synthetics/sample_data/test_project_monitor_policy.ts @@ -60,11 +60,13 @@ export const getTestProjectSyntheticsPolicy = ( timeout: { type: 'text' }, max_redirects: { type: 'integer' }, proxy_url: { type: 'text' }, + proxy_headers: { type: 'yaml' }, tags: { type: 'yaml' }, username: { type: 'text' }, password: { type: 'password' }, 'response.include_headers': { type: 'bool' }, 'response.include_body': { type: 'text' }, + 'response.include_body_max_bytes': { type: 'text' }, 'check.request.method': { type: 'text' }, 'check.request.headers': { type: 'yaml' }, 'check.request.body': { type: 'yaml' }, @@ -85,6 +87,9 @@ export const getTestProjectSyntheticsPolicy = ( origin: { type: 'text' }, 'monitor.project.id': { type: 'text' }, 'monitor.project.name': { type: 'text' }, + ipv4: { type: 'bool' }, + ipv6: { type: 'bool' }, + mode: { type: 'text' }, }, id: `synthetics/http-http-4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-d70a46e0-22ea-11ed-8c6b-09a2d21dfbc3`, }, @@ -284,10 +289,7 @@ export const getTestProjectSyntheticsPolicy = ( }, id: `synthetics/browser-browser.network-4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-d70a46e0-22ea-11ed-8c6b-09a2d21dfbc3`, compiled_stream: { - processors: [ - { add_observer_metadata: { geo: { name: 'Fleet managed' } } }, - { add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }, - ], + processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }], }, }, { @@ -303,10 +305,7 @@ export const getTestProjectSyntheticsPolicy = ( }, id: `synthetics/browser-browser.screenshot-4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-d70a46e0-22ea-11ed-8c6b-09a2d21dfbc3`, compiled_stream: { - processors: [ - { add_observer_metadata: { geo: { name: 'Fleet managed' } } }, - { add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }, - ], + processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }], }, }, ], From 99c5d45554f668d80499f9e068ae612f0c8ef64c Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Thu, 6 Apr 2023 12:17:29 -0400 Subject: [PATCH 15/27] adjust tests to account for private locations --- .../monitor_add_edit/form/field.tsx | 2 +- .../monitor_add_edit/form/field_config.tsx | 12 +++++------ .../add_monitor_private_location.ts | 6 +++--- .../synthetics/add_monitor_project_legacy.ts | 20 ++++++++++++++++++- .../apis/synthetics/delete_monitor.ts | 2 +- .../apis/synthetics/delete_monitor_project.ts | 2 +- .../apis/synthetics/get_monitor_project.ts | 2 +- .../sample_data/test_browser_policy.ts | 14 ++++++++++++- .../synthetics/sample_data/test_policy.ts | 17 +++++++++++++++- .../test_project_monitor_policy.ts | 13 +++++++++--- .../apis/synthetics/sync_global_params.ts | 2 +- 11 files changed, 72 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field.tsx index 62db4c6434d05..cd39245c1c7ec 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field.tsx @@ -58,7 +58,7 @@ export const Field = memo( // eslint-disable-next-line react-hooks/exhaustive-deps }, [JSON.stringify(dependenciesValues || []), dependencies, getFieldState]); - if (hidden && !hidden(dependenciesValues)) { + if (hidden && hidden(dependenciesValues)) { return null; } diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 0125c7a92732a..5d0cedf41ca06 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -975,7 +975,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ }), hidden: (dependencies) => { const [isTLSEnabled] = dependencies; - return Boolean(isTLSEnabled); + return !Boolean(isTLSEnabled); }, dependencies: ['isTLSEnabled'], props: (): EuiSelectProps => ({ @@ -995,7 +995,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ controlled: true, hidden: (dependencies) => { const [isTLSEnabled] = dependencies; - return Boolean(isTLSEnabled); + return !Boolean(isTLSEnabled); }, dependencies: ['isTLSEnabled'], props: ({ field, setValue }): EuiComboBoxProps => { @@ -1027,7 +1027,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ }), hidden: (dependencies) => { const [isTLSEnabled] = dependencies; - return Boolean(isTLSEnabled); + return !Boolean(isTLSEnabled); }, dependencies: ['isTLSEnabled'], props: (): EuiTextAreaProps => ({ @@ -1045,7 +1045,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ }), hidden: (dependencies) => { const [isTLSEnabled] = dependencies; - return Boolean(isTLSEnabled); + return !Boolean(isTLSEnabled); }, dependencies: ['isTLSEnabled'], props: (): EuiTextAreaProps => ({ @@ -1063,7 +1063,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ }), hidden: (dependencies) => { const [isTLSEnabled] = dependencies; - return Boolean(isTLSEnabled); + return !Boolean(isTLSEnabled); }, dependencies: ['isTLSEnabled'], props: (): EuiTextAreaProps => ({ @@ -1081,7 +1081,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ }), hidden: (dependencies) => { const [isTLSEnabled] = dependencies; - return Boolean(isTLSEnabled); + return !Boolean(isTLSEnabled); }, dependencies: ['isTLSEnabled'], props: (): EuiFieldPasswordProps => ({ diff --git a/x-pack/test/api_integration/apis/synthetics/add_monitor_private_location.ts b/x-pack/test/api_integration/apis/synthetics/add_monitor_private_location.ts index d680e99d13405..b48cf2c9a56ca 100644 --- a/x-pack/test/api_integration/apis/synthetics/add_monitor_private_location.ts +++ b/x-pack/test/api_integration/apis/synthetics/add_monitor_private_location.ts @@ -36,7 +36,7 @@ export default function ({ getService }: FtrProviderContext) { before(async () => { await supertestAPI.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200); await supertestAPI - .post('/api/fleet/epm/packages/synthetics/0.11.4') + .post('/api/fleet/epm/packages/synthetics/0.12.0') .set('kbn-xsrf', 'true') .send({ force: true }) .expect(200); @@ -455,7 +455,7 @@ export default function ({ getService }: FtrProviderContext) { pkgPolicy.id === monitorId + '-' + testFleetPolicyID + `-default` ); - expect(packagePolicy.package.version).eql('0.11.4'); + expect(packagePolicy.package.version).eql('0.12.0'); await supertestAPI.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200); const policyResponseAfterUpgrade = await supertestAPI.get( @@ -465,7 +465,7 @@ export default function ({ getService }: FtrProviderContext) { (pkgPolicy: PackagePolicy) => pkgPolicy.id === monitorId + '-' + testFleetPolicyID + `-default` ); - expect(semver.gte(packagePolicyAfterUpgrade.package.version, '0.11.4')).eql(true); + expect(semver.gte(packagePolicyAfterUpgrade.package.version, '0.12.0')).eql(true); } finally { await supertestAPI .delete(API_URLS.SYNTHETICS_MONITORS + '/' + monitorId) diff --git a/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts b/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts index 0f4c62d830bd0..a26ce9f9fd2d2 100644 --- a/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts +++ b/x-pack/test/api_integration/apis/synthetics/add_monitor_project_legacy.ts @@ -82,7 +82,7 @@ export default function ({ getService }: FtrProviderContext) { before(async () => { await supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200); await supertest - .post('/api/fleet/epm/packages/synthetics/0.11.4') + .post('/api/fleet/epm/packages/synthetics/0.12.0') .set('kbn-xsrf', 'true') .send({ force: true }) .expect(200); @@ -1816,11 +1816,13 @@ export default function ({ getService }: FtrProviderContext) { timeout: { value: '80s', type: 'text' }, max_redirects: { value: '0', type: 'integer' }, proxy_url: { value: '', type: 'text' }, + proxy_headers: { value: null, type: 'yaml' }, tags: { value: '["tag2","tag2"]', type: 'yaml' }, username: { value: '', type: 'text' }, password: { value: '', type: 'password' }, 'response.include_headers': { value: false, type: 'bool' }, 'response.include_body': { value: 'always', type: 'text' }, + 'response.include_body_max_bytes': { value: '900', type: 'text' }, 'check.request.method': { value: 'POST', type: 'text' }, 'check.request.headers': { value: '{"Content-Type":"application/x-www-form-urlencoded"}', @@ -1831,6 +1833,10 @@ export default function ({ getService }: FtrProviderContext) { 'check.response.headers': { value: null, type: 'yaml' }, 'check.response.body.positive': { value: '["Saved","saved"]', type: 'yaml' }, 'check.response.body.negative': { value: null, type: 'yaml' }, + 'check.response.json': { + value: '[{"description":"check status","expression":"foo.bar == \\"myValue\\""}]', + type: 'yaml', + }, 'ssl.certificate_authorities': { value: null, type: 'yaml' }, 'ssl.certificate': { value: null, type: 'yaml' }, 'ssl.key': { value: null, type: 'yaml' }, @@ -1856,6 +1862,9 @@ export default function ({ getService }: FtrProviderContext) { type: 'text', value: 'test-suite', }, + ipv4: { type: 'bool', value: true }, + ipv6: { type: 'bool', value: true }, + mode: { type: 'text', value: 'any' }, }, id: `synthetics/http-http-${id}-${testPolicyId}`, compiled_stream: { @@ -1880,6 +1889,15 @@ export default function ({ getService }: FtrProviderContext) { 'ssl.supported_protocols': ['TLSv1.1', 'TLSv1.2', 'TLSv1.3'], 'run_from.geo.name': 'Test private location 0', 'run_from.id': 'Test private location 0', + 'check.response.json': [ + { + description: 'check status', + expression: 'foo.bar == "myValue"', + }, + ], + ipv4: true, + ipv6: true, + mode: 'any', processors: [ { add_fields: { diff --git a/x-pack/test/api_integration/apis/synthetics/delete_monitor.ts b/x-pack/test/api_integration/apis/synthetics/delete_monitor.ts index 87d033be74743..9ab6063775844 100644 --- a/x-pack/test/api_integration/apis/synthetics/delete_monitor.ts +++ b/x-pack/test/api_integration/apis/synthetics/delete_monitor.ts @@ -41,7 +41,7 @@ export default function ({ getService }: FtrProviderContext) { _httpMonitorJson = getFixtureJson('http_monitor'); await supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200); await supertest - .post('/api/fleet/epm/packages/synthetics/0.11.4') + .post('/api/fleet/epm/packages/synthetics/0.12.0') .set('kbn-xsrf', 'true') .send({ force: true }) .expect(200); diff --git a/x-pack/test/api_integration/apis/synthetics/delete_monitor_project.ts b/x-pack/test/api_integration/apis/synthetics/delete_monitor_project.ts index 8ba507beb7e4c..13bcab980d248 100644 --- a/x-pack/test/api_integration/apis/synthetics/delete_monitor_project.ts +++ b/x-pack/test/api_integration/apis/synthetics/delete_monitor_project.ts @@ -45,7 +45,7 @@ export default function ({ getService }: FtrProviderContext) { before(async () => { await supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200); await supertest - .post('/api/fleet/epm/packages/synthetics/0.11.4') + .post('/api/fleet/epm/packages/synthetics/0.12.0') .set('kbn-xsrf', 'true') .send({ force: true }) .expect(200); diff --git a/x-pack/test/api_integration/apis/synthetics/get_monitor_project.ts b/x-pack/test/api_integration/apis/synthetics/get_monitor_project.ts index d24a3775bbf44..beefd6c561829 100644 --- a/x-pack/test/api_integration/apis/synthetics/get_monitor_project.ts +++ b/x-pack/test/api_integration/apis/synthetics/get_monitor_project.ts @@ -46,7 +46,7 @@ export default function ({ getService }: FtrProviderContext) { before(async () => { await supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200); await supertest - .post('/api/fleet/epm/packages/synthetics/0.11.4') + .post('/api/fleet/epm/packages/synthetics/0.12.0') .set('kbn-xsrf', 'true') .send({ force: true }) .expect(200); diff --git a/x-pack/test/api_integration/apis/synthetics/sample_data/test_browser_policy.ts b/x-pack/test/api_integration/apis/synthetics/sample_data/test_browser_policy.ts index 3484ee3a54df7..d9ee72a9d326c 100644 --- a/x-pack/test/api_integration/apis/synthetics/sample_data/test_browser_policy.ts +++ b/x-pack/test/api_integration/apis/synthetics/sample_data/test_browser_policy.ts @@ -21,7 +21,7 @@ export const getTestBrowserSyntheticsPolicy = ({ version: 'WzEzNzYsMV0=', name: 'Test HTTP Monitor 03-Test private location 0-default', namespace: 'testnamespace', - package: { name: 'synthetics', title: 'Elastic Synthetics', version: '0.11.4' }, + package: { name: 'synthetics', title: 'Elastic Synthetics', version: '0.12.0' }, enabled: true, policy_id: 'fe621d20-7b01-11ed-803f-475d82e1f9ca', inputs: [ @@ -44,11 +44,13 @@ export const getTestBrowserSyntheticsPolicy = ({ timeout: { type: 'text' }, max_redirects: { type: 'integer' }, proxy_url: { type: 'text' }, + proxy_headers: { type: 'yaml' }, tags: { type: 'yaml' }, username: { type: 'text' }, password: { type: 'password' }, 'response.include_headers': { type: 'bool' }, 'response.include_body': { type: 'text' }, + 'response.include_body_max_bytes': { type: 'text' }, 'check.request.method': { type: 'text' }, 'check.request.headers': { type: 'yaml' }, 'check.request.body': { type: 'yaml' }, @@ -56,6 +58,7 @@ export const getTestBrowserSyntheticsPolicy = ({ 'check.response.headers': { type: 'yaml' }, 'check.response.body.positive': { type: 'yaml' }, 'check.response.body.negative': { type: 'yaml' }, + 'check.response.json': { type: 'yaml' }, 'ssl.certificate_authorities': { type: 'yaml' }, 'ssl.certificate': { type: 'yaml' }, 'ssl.key': { type: 'yaml' }, @@ -69,6 +72,9 @@ export const getTestBrowserSyntheticsPolicy = ({ origin: { type: 'text' }, 'monitor.project.id': { type: 'text' }, 'monitor.project.name': { type: 'text' }, + ipv4: { type: 'bool', value: true }, + ipv6: { type: 'bool', value: true }, + mode: { type: 'text' }, }, id: 'synthetics/http-http-abf904a4-cb9a-4b29-8c11-4d183cca289b-fe621d20-7b01-11ed-803f-475d82e1f9ca-default', }, @@ -109,6 +115,9 @@ export const getTestBrowserSyntheticsPolicy = ({ origin: { type: 'text' }, 'monitor.project.id': { type: 'text' }, 'monitor.project.name': { type: 'text' }, + ipv4: { type: 'bool', value: true }, + ipv6: { type: 'bool', value: true }, + mode: { type: 'text' }, }, id: 'synthetics/tcp-tcp-abf904a4-cb9a-4b29-8c11-4d183cca289b-fe621d20-7b01-11ed-803f-475d82e1f9ca-default', }, @@ -140,6 +149,9 @@ export const getTestBrowserSyntheticsPolicy = ({ origin: { type: 'text' }, 'monitor.project.id': { type: 'text' }, 'monitor.project.name': { type: 'text' }, + ipv4: { type: 'bool', value: true }, + ipv6: { type: 'bool', value: true }, + mode: { type: 'text' }, }, id: 'synthetics/icmp-icmp-abf904a4-cb9a-4b29-8c11-4d183cca289b-fe621d20-7b01-11ed-803f-475d82e1f9ca-default', }, diff --git a/x-pack/test/api_integration/apis/synthetics/sample_data/test_policy.ts b/x-pack/test/api_integration/apis/synthetics/sample_data/test_policy.ts index f57f514f9ee98..b0962e4d285e6 100644 --- a/x-pack/test/api_integration/apis/synthetics/sample_data/test_policy.ts +++ b/x-pack/test/api_integration/apis/synthetics/sample_data/test_policy.ts @@ -21,7 +21,7 @@ export const getTestSyntheticsPolicy = ( version: 'WzE2MjYsMV0=', name: 'test-monitor-name-Test private location 0-default', namespace: namespace || 'testnamespace', - package: { name: 'synthetics', title: 'Elastic Synthetics', version: '0.11.4' }, + package: { name: 'synthetics', title: 'Elastic Synthetics', version: '0.12.0' }, enabled: true, policy_id: '5347cd10-0368-11ed-8df7-a7424c6f5167', inputs: [ @@ -55,11 +55,13 @@ export const getTestSyntheticsPolicy = ( timeout: { value: '3ms', type: 'text' }, max_redirects: { value: '3', type: 'integer' }, proxy_url: { value: proxyUrl ?? 'http://proxy.com', type: 'text' }, + proxy_headers: { value: null, type: 'yaml' }, tags: { value: '["tag1","tag2"]', type: 'yaml' }, username: { value: 'test-username', type: 'text' }, password: { value: 'test', type: 'password' }, 'response.include_headers': { value: true, type: 'bool' }, 'response.include_body': { value: 'never', type: 'text' }, + 'response.include_body_max_bytes': { value: '1024', type: 'text' }, 'check.request.method': { value: '', type: 'text' }, 'check.request.headers': { value: '{"sampleHeader":"sampleHeaderValue"}', @@ -70,6 +72,7 @@ export const getTestSyntheticsPolicy = ( 'check.response.headers': { value: null, type: 'yaml' }, 'check.response.body.positive': { value: null, type: 'yaml' }, 'check.response.body.negative': { value: null, type: 'yaml' }, + 'check.response.json': { value: null, type: 'yaml' }, 'ssl.certificate_authorities': { value: isTLSEnabled ? '"t.string"' : null, type: 'yaml', @@ -89,6 +92,9 @@ export const getTestSyntheticsPolicy = ( origin: { value: 'ui', type: 'text' }, 'monitor.project.id': { type: 'text', value: null }, 'monitor.project.name': { type: 'text', value: null }, + ipv4: { type: 'bool', value: true }, + ipv6: { type: 'bool', value: true }, + mode: { type: 'text', value: 'any' }, }, id: 'synthetics/http-http-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default', compiled_stream: { @@ -116,6 +122,9 @@ export const getTestSyntheticsPolicy = ( 'check.request.headers': { sampleHeader: 'sampleHeaderValue' }, 'check.request.body': 'testValue', 'check.response.status': ['200', '201'], + ipv4: true, + ipv6: true, + mode: 'any', ...(isTLSEnabled ? { 'ssl.certificate': 't.string', @@ -179,6 +188,9 @@ export const getTestSyntheticsPolicy = ( origin: { type: 'text' }, 'monitor.project.id': { type: 'text' }, 'monitor.project.name': { type: 'text' }, + ipv4: { type: 'bool', value: true }, + ipv6: { type: 'bool', value: true }, + mode: { type: 'text' }, }, id: 'synthetics/tcp-tcp-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default', }, @@ -213,6 +225,9 @@ export const getTestSyntheticsPolicy = ( origin: { type: 'text' }, 'monitor.project.id': { type: 'text' }, 'monitor.project.name': { type: 'text' }, + ipv4: { type: 'bool', value: true }, + ipv6: { type: 'bool', value: true }, + mode: { type: 'text' }, }, id: 'synthetics/icmp-icmp-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default', }, diff --git a/x-pack/test/api_integration/apis/synthetics/sample_data/test_project_monitor_policy.ts b/x-pack/test/api_integration/apis/synthetics/sample_data/test_project_monitor_policy.ts index 11b0b75817d02..e7dfb0f6bde97 100644 --- a/x-pack/test/api_integration/apis/synthetics/sample_data/test_project_monitor_policy.ts +++ b/x-pack/test/api_integration/apis/synthetics/sample_data/test_project_monitor_policy.ts @@ -34,7 +34,7 @@ export const getTestProjectSyntheticsPolicy = ( version: 'WzEzMDksMV0=', name: `4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-Test private location 0`, namespace: 'default', - package: { name: 'synthetics', title: 'Elastic Synthetics', version: '0.11.4' }, + package: { name: 'synthetics', title: 'Elastic Synthetics', version: '0.12.0' }, enabled: true, policy_id: '46034710-0ba6-11ed-ba04-5f123b9faa8b', inputs: [ @@ -74,6 +74,7 @@ export const getTestProjectSyntheticsPolicy = ( 'check.response.headers': { type: 'yaml' }, 'check.response.body.positive': { type: 'yaml' }, 'check.response.body.negative': { type: 'yaml' }, + 'check.response.json': { type: 'yaml' }, 'ssl.certificate_authorities': { type: 'yaml' }, 'ssl.certificate': { type: 'yaml' }, 'ssl.key': { type: 'yaml' }, @@ -87,8 +88,8 @@ export const getTestProjectSyntheticsPolicy = ( origin: { type: 'text' }, 'monitor.project.id': { type: 'text' }, 'monitor.project.name': { type: 'text' }, - ipv4: { type: 'bool' }, - ipv6: { type: 'bool' }, + ipv4: { type: 'bool', value: true }, + ipv6: { type: 'bool', value: true }, mode: { type: 'text' }, }, id: `synthetics/http-http-4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-d70a46e0-22ea-11ed-8c6b-09a2d21dfbc3`, @@ -133,6 +134,9 @@ export const getTestProjectSyntheticsPolicy = ( origin: { type: 'text' }, 'monitor.project.id': { type: 'text' }, 'monitor.project.name': { type: 'text' }, + ipv4: { type: 'bool', value: true }, + ipv6: { type: 'bool', value: true }, + mode: { type: 'text' }, }, id: `synthetics/tcp-tcp-4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-d70a46e0-22ea-11ed-8c6b-09a2d21dfbc3`, }, @@ -167,6 +171,9 @@ export const getTestProjectSyntheticsPolicy = ( origin: { type: 'text' }, 'monitor.project.id': { type: 'text' }, 'monitor.project.name': { type: 'text' }, + ipv4: { type: 'bool', value: true }, + ipv6: { type: 'bool', value: true }, + mode: { type: 'text' }, }, id: `synthetics/icmp-icmp-4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-d70a46e0-22ea-11ed-8c6b-09a2d21dfbc3`, }, diff --git a/x-pack/test/api_integration/apis/synthetics/sync_global_params.ts b/x-pack/test/api_integration/apis/synthetics/sync_global_params.ts index acb6b4250628d..f5ff56d2ee506 100644 --- a/x-pack/test/api_integration/apis/synthetics/sync_global_params.ts +++ b/x-pack/test/api_integration/apis/synthetics/sync_global_params.ts @@ -44,7 +44,7 @@ export default function ({ getService }: FtrProviderContext) { before(async () => { await supertestAPI.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200); await supertestAPI - .post('/api/fleet/epm/packages/synthetics/0.11.4') + .post('/api/fleet/epm/packages/synthetics/0.12.0') .set('kbn-xsrf', 'true') .send({ force: true }) .expect(200); From c049e1dd94e05ea5fcc53996d55f7c9054cf8aab Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Thu, 6 Apr 2023 16:04:35 -0400 Subject: [PATCH 16/27] adjust field config --- .../components/monitor_add_edit/form/field_config.tsx | 8 ++++---- .../components/monitor_add_edit/form/field_wrappers.tsx | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 5d0cedf41ca06..4c974f91165cc 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -18,7 +18,6 @@ import { EuiSuperSelect, EuiText, EuiLink, - EuiTextArea, EuiSelectProps, EuiFieldTextProps, EuiSwitchProps, @@ -55,6 +54,7 @@ import { ResponseBodyIndexFieldProps, ControlledFieldProp, KeyValuePairsField, + TextArea, } from './field_wrappers'; import { getDocLinks } from '../../../../../kibana_services'; import { useMonitorName } from '../hooks/use_monitor_name'; @@ -1018,7 +1018,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ }, [ConfigKey.TLS_CERTIFICATE_AUTHORITIES]: { fieldKey: ConfigKey.TLS_CERTIFICATE_AUTHORITIES, - component: EuiTextArea, + component: TextArea, label: i18n.translate('xpack.synthetics.monitorConfig.certificateAuthorities.label', { defaultMessage: 'Certificate authorities', }), @@ -1036,7 +1036,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ }, [ConfigKey.TLS_CERTIFICATE]: { fieldKey: ConfigKey.TLS_CERTIFICATE, - component: EuiTextArea, + component: TextArea, label: i18n.translate('xpack.synthetics.monitorConfig.clientCertificate.label', { defaultMessage: 'Client certificate', }), @@ -1054,7 +1054,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ }, [ConfigKey.TLS_KEY]: { fieldKey: ConfigKey.TLS_KEY, - component: EuiTextArea, + component: TextArea, label: i18n.translate('xpack.synthetics.monitorConfig.clientKey.label', { defaultMessage: 'Client key', }), diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_wrappers.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_wrappers.tsx index 8fda195ba1c01..20764d3e8918b 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_wrappers.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_wrappers.tsx @@ -25,6 +25,8 @@ import { EuiButtonGroupProps, EuiComboBox, EuiComboBoxProps, + EuiTextArea, + EuiTextAreaProps, } from '@elastic/eui'; import { SourceField, SourceFieldProps } from '../fields/source_field'; import { @@ -81,6 +83,10 @@ export const FieldText = React.forwardRef( ) ); +export const TextArea = React.forwardRef((props, ref) => ( + +)); + export const FieldNumber = React.forwardRef((props, ref) => ( )); From b185cb7705a3cbaf05e20a4d7a8a00d42758771c Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 12 Apr 2023 08:02:35 -0400 Subject: [PATCH 17/27] Update x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx Co-authored-by: florent-leborgne --- .../components/monitor_add_edit/form/field_config.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 032aceec52229..9bb38430793af 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -1328,7 +1328,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ defaultMessage: 'IP protocols', }), helpText: i18n.translate('xpack.synthetics.monitorConfig.ipv4.helpText', { - defaultMessage: 'Specifies which IP procols to use when pinging the remote host.', + defaultMessage: 'IP protocols to use when pinging the remote host.', }), controlled: true, dependencies: [ConfigKey.IPV6], From 60a8544efe86917858fe71d1d8ce74b743a10d06 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 12 Apr 2023 08:02:50 -0400 Subject: [PATCH 18/27] Update x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx Co-authored-by: florent-leborgne --- .../components/monitor_add_edit/form/field_config.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 9bb38430793af..3dd5f8bd7ced9 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -1375,7 +1375,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ defaultMessage: 'Proxy headers', }), helpText: i18n.translate('xpack.synthetics.monitorConfig.proxyHeaders.helpText', { - defaultMessage: 'Additional headers to send to proxies during CONNECT requests.', + defaultMessage: 'Additional headers to send to proxies for CONNECT requests.', }), controlled: true, validation: () => ({ From 4d68099fc691664b70f15be60dd46754ba94d312 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 12 Apr 2023 08:04:53 -0400 Subject: [PATCH 19/27] Update x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx Co-authored-by: florent-leborgne --- .../components/monitor_add_edit/form/field_config.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 3dd5f8bd7ced9..2b6cc4d5810a8 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -1382,7 +1382,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ validate: (headers) => !validateHeaders(headers), }), error: i18n.translate('xpack.synthetics.monitorConfig.proxyHeaders.error', { - defaultMessage: 'Header key must be a valid HTTP token.', + defaultMessage: 'The header key must be a valid HTTP token.', }), props: (): HeaderFieldProps => ({ readOnly, From 8f9b1c914decc308759b397b71cd0deb87927d94 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 12 Apr 2023 08:05:34 -0400 Subject: [PATCH 20/27] Update x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx Co-authored-by: florent-leborgne --- .../components/monitor_add_edit/form/field_config.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 2b6cc4d5810a8..354879e76530e 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -1438,7 +1438,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ if (value.some((check) => !check.expression || !check.description)) { return i18n.translate('xpack.synthetics.monitorConfig.responseJSON.error', { defaultMessage: - 'Invalid JSON expression. Please ensure both the label and expression are defined.', + 'This JSON expression isn't valid. Make sure that both the label and expression are defined.', }); } }, From d47a0459781c35084e225cc4bead4d718feac441 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 12 Apr 2023 08:22:25 -0400 Subject: [PATCH 21/27] linting --- .../components/monitor_add_edit/form/field_config.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 354879e76530e..49562acabbde6 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -1438,7 +1438,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ if (value.some((check) => !check.expression || !check.description)) { return i18n.translate('xpack.synthetics.monitorConfig.responseJSON.error', { defaultMessage: - 'This JSON expression isn't valid. Make sure that both the label and expression are defined.', + "This JSON expression isn't valid. Make sure that both the label and expression are defined.", }); } }, From 00681b8fea5c7ae8ccca489faf372552b9b1bcfd Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Wed, 12 Apr 2023 08:43:28 -0400 Subject: [PATCH 22/27] adjust content --- .../components/monitor_add_edit/form/field_config.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 49562acabbde6..54df225858bf7 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -1399,9 +1399,6 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ 'A list of expressions executed against the body when parsed as JSON. Body sizes must be less than or equal to 100 MiB', }), controlled: true, - error: i18n.translate('xpack.synthetics.monitorConfig.proxyHeaders.error', { - defaultMessage: 'Header key must be a valid HTTP token.', - }), props: ({ field, setValue }): KeyValuePairsFieldProps => ({ readOnly, keyLabel: i18n.translate('xpack.synthetics.monitorConfig.responseJSON.key.label', { From 0abea8872e896dc3232b41b310fb8c8da5e70fd8 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Mon, 17 Apr 2023 16:36:02 +0200 Subject: [PATCH 23/27] Update x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx Co-authored-by: florent-leborgne --- .../components/monitor_add_edit/form/field_config.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index 54df225858bf7..12d9a94fdf16a 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -1312,7 +1312,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ defaultMessage: 'Response body max bytes', }), helpText: i18n.translate('xpack.synthetics.monitorConfig.responseBodyMaxBytes.helpText', { - defaultMessage: 'Control the maximum size of the stored body contents.', + defaultMessage: 'Controls the maximum size of the stored body contents.', }), hidden: (dependencies) => { const [responseBodyIndex] = dependencies || []; From 41fb8422300e3a36ac67b604095fe4cf552d766e Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 24 Apr 2023 21:24:07 -0400 Subject: [PATCH 24/27] adjust content --- .../monitor_add_edit/form/field_config.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index ea5de5a1262ec..a465209236225 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -771,7 +771,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ fieldKey: ConfigKey.RESPONSE_STATUS_CHECK, component: FormattedComboBox, label: i18n.translate('xpack.synthetics.monitorConfig.responseStatusCheck.label', { - defaultMessage: 'Check response status equals', + defaultMessage: 'Response status equals', }), helpText: i18n.translate('xpack.synthetics.monitorConfig.responseStatusCheck.helpText', { defaultMessage: @@ -800,7 +800,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ fieldKey: ConfigKey.RESPONSE_HEADERS_CHECK, component: HeaderField, label: i18n.translate('xpack.synthetics.monitorConfig.responseHeadersCheck.label', { - defaultMessage: 'Check response headers contain', + defaultMessage: 'Response headers contain', }), helpText: i18n.translate('xpack.synthetics.monitorConfig.responseHeadersCheck.helpText', { defaultMessage: 'A list of expected response headers.', @@ -820,7 +820,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ fieldKey: ConfigKey.RESPONSE_BODY_CHECK_POSITIVE, component: FormattedComboBox, label: i18n.translate('xpack.synthetics.monitorConfig.responseBodyCheck.label', { - defaultMessage: 'Check response body contains', + defaultMessage: 'Response body contains', }), helpText: i18n.translate('xpack.synthetics.monitorConfig.responseBodyCheck.helpText', { defaultMessage: @@ -836,7 +836,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ fieldKey: ConfigKey.RESPONSE_BODY_CHECK_NEGATIVE, component: FormattedComboBox, label: i18n.translate('xpack.synthetics.monitorConfig.responseBodyCheckNegative.label', { - defaultMessage: 'Check response body does not contain', + defaultMessage: 'Response body does not contain', }), helpText: i18n.translate('xpack.synthetics.monitorConfig.responseBodyCheckNegative.helpText', { defaultMessage: @@ -852,7 +852,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ fieldKey: ConfigKey.RESPONSE_RECEIVE_CHECK, component: FieldText, label: i18n.translate('xpack.synthetics.monitorConfig.responseReceiveCheck.label', { - defaultMessage: 'Check response contains', + defaultMessage: 'Response contains', }), helpText: i18n.translate('xpack.synthetics.monitorConfig.responseReceiveCheck.helpText', { defaultMessage: 'The expected remote host response.', @@ -1393,7 +1393,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ fieldKey: ConfigKey.RESPONSE_JSON_CHECK, component: KeyValuePairsField, label: i18n.translate('xpack.synthetics.monitorConfig.responseJSON.label', { - defaultMessage: 'Check response body contains JSON', + defaultMessage: 'Response body contains JSON', }), helpText: i18n.translate('xpack.synthetics.monitorConfig.responseJSON.helpText', { defaultMessage: From 2846868a890076ca041a9980bb33141d1fddad26 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 24 Apr 2023 21:36:19 -0400 Subject: [PATCH 25/27] Update x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx Co-authored-by: florent-leborgne --- .../components/monitor_add_edit/form/field_config.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index a4ab6ab44c812..e5a6d34747fa9 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -1397,7 +1397,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ }), helpText: i18n.translate('xpack.synthetics.monitorConfig.responseJSON.helpText', { defaultMessage: - 'A list of expressions executed against the body when parsed as JSON. Body sizes must be less than or equal to 100 MiB', + 'A list of expressions executed against the body when parsed as JSON. The body size must be less than or equal to 100 MiB.', }), controlled: true, props: ({ field, setValue }): KeyValuePairsFieldProps => ({ From 23fb4949fbe94bc9459d3d3beb162c046caa9a01 Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 24 Apr 2023 21:36:27 -0400 Subject: [PATCH 26/27] Update x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx Co-authored-by: florent-leborgne --- .../components/monitor_add_edit/form/field_config.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx index e5a6d34747fa9..9653c415e171a 100644 --- a/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx +++ b/x-pack/plugins/synthetics/public/apps/synthetics/components/monitor_add_edit/form/field_config.tsx @@ -1291,7 +1291,7 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({ helpText: ( all, any: any, From a7935688e6edd60d4d62c30e069a014e913e241f Mon Sep 17 00:00:00 2001 From: Dominique Clarke Date: Mon, 24 Apr 2023 21:58:49 -0400 Subject: [PATCH 27/27] adjust tests --- .../apis/synthetics/add_monitor_project.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts b/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts index 8cfafd20e8a9a..7674d2fbc534f 100644 --- a/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts +++ b/x-pack/test/api_integration/apis/synthetics/add_monitor_project.ts @@ -1901,6 +1901,12 @@ export default function ({ getService }: FtrProviderContext) { positive: ['Saved', 'saved'], }, status: [200], + json: [ + { + description: 'check status', + expression: 'foo.bar == "myValue"', + }, + ], }, enabled: false, hash: 'ekrjelkjrelkjre', @@ -1909,6 +1915,7 @@ export default function ({ getService }: FtrProviderContext) { name: 'My Monitor 3', response: { include_body: 'always', + include_body_max_bytes: 900, }, 'response.include_headers': false, schedule: 60, @@ -1962,6 +1969,12 @@ export default function ({ getService }: FtrProviderContext) { positive: ['Saved', 'saved'], }, status: [200], + json: [ + { + description: 'check status', + expression: 'foo.bar == "myValue"', + }, + ], }, enabled: false, hash: 'ekrjelkjrelkjre', @@ -1970,6 +1983,7 @@ export default function ({ getService }: FtrProviderContext) { name: 'My Monitor 3', response: { include_body: 'always', + include_body_max_bytes: 900, }, 'response.include_headers': false, schedule: 60, @@ -2024,6 +2038,12 @@ export default function ({ getService }: FtrProviderContext) { positive: ['Saved', 'saved'], }, status: [200], + json: [ + { + description: 'check status', + expression: 'foo.bar == "myValue"', + }, + ], }, enabled: false, hash: 'ekrjelkjrelkjre', @@ -2032,6 +2052,7 @@ export default function ({ getService }: FtrProviderContext) { name: 'My Monitor 3', response: { include_body: 'always', + include_body_max_bytes: 900, }, 'response.include_headers': false, schedule: 60,