mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Synthetics Integration] add enabled toggle (#119994)
* add enabled toggle * adjust types * adjust types * add wrapper for simple fields * adjust icmp simple fields * Update x-pack/plugins/uptime/public/components/fleet_package/custom_fields.test.tsx Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
966cfb4623
commit
136ab726d5
18 changed files with 137 additions and 17 deletions
|
@ -11,6 +11,7 @@ import { tEnum } from '../../utils/t_enum';
|
|||
// values must match keys in the integration package
|
||||
export enum ConfigKey {
|
||||
APM_SERVICE_NAME = 'service.name',
|
||||
ENABLED = 'enabled',
|
||||
HOSTS = 'hosts',
|
||||
IGNORE_HTTPS_ERRORS = 'ignore_https_errors',
|
||||
JOURNEY_FILTERS_MATCH = 'filter_journeys.match',
|
||||
|
|
|
@ -48,6 +48,7 @@ export type ZipUrlTLSFields = t.TypeOf<typeof ZipUrlTLSFieldsCodec>;
|
|||
// CommonFields
|
||||
export const CommonFieldsCodec = t.interface({
|
||||
[ConfigKey.MONITOR_TYPE]: DataStreamCodec,
|
||||
[ConfigKey.ENABLED]: t.boolean,
|
||||
[ConfigKey.SCHEDULE]: Schedule,
|
||||
[ConfigKey.APM_SERVICE_NAME]: t.string,
|
||||
[ConfigKey.TIMEOUT]: t.string,
|
||||
|
|
|
@ -13,7 +13,7 @@ import { ConfigKey } from '../types';
|
|||
import { useBrowserSimpleFieldsContext } from '../contexts';
|
||||
import { ScheduleField } from '../schedule_field';
|
||||
import { SourceField } from './source_field';
|
||||
import { CommonFields } from '../common/common_fields';
|
||||
import { SimpleFieldsWrapper } from '../common/simple_fields_wrapper';
|
||||
|
||||
interface Props {
|
||||
validate: Validation;
|
||||
|
@ -58,7 +58,7 @@ export const BrowserSimpleFields = memo<Props>(({ validate }) => {
|
|||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<SimpleFieldsWrapper fields={fields} validate={validate} onInputChange={handleInputChange}>
|
||||
<EuiFormRow
|
||||
id="syntheticsFleetScheduleField--number syntheticsFleetScheduleField--unit"
|
||||
label={
|
||||
|
@ -113,7 +113,6 @@ export const BrowserSimpleFields = memo<Props>(({ validate }) => {
|
|||
)}
|
||||
/>
|
||||
</EuiFormRow>
|
||||
<CommonFields fields={fields} onChange={handleInputChange} validate={validate} />
|
||||
</>
|
||||
</SimpleFieldsWrapper>
|
||||
);
|
||||
});
|
||||
|
|
|
@ -17,6 +17,12 @@ jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => ({
|
|||
htmlIdGenerator: () => () => `id-${Math.random()}`,
|
||||
}));
|
||||
|
||||
// ensures that fields appropriately match to their label
|
||||
jest.mock('@elastic/eui/lib/services/accessibility', () => ({
|
||||
...jest.requireActual('@elastic/eui/lib/services/accessibility'),
|
||||
useGeneratedHtmlId: () => `id-${Math.random()}`,
|
||||
}));
|
||||
|
||||
jest.mock('../../../../../../../src/plugins/kibana_react/public', () => {
|
||||
const original = jest.requireActual('../../../../../../../src/plugins/kibana_react/public');
|
||||
return {
|
||||
|
|
|
@ -9,6 +9,7 @@ import { CommonFields, ConfigKey, ScheduleUnit, DataStream } from '../types';
|
|||
|
||||
export const defaultValues: CommonFields = {
|
||||
[ConfigKey.MONITOR_TYPE]: DataStream.HTTP,
|
||||
[ConfigKey.ENABLED]: true,
|
||||
[ConfigKey.SCHEDULE]: {
|
||||
number: '3',
|
||||
unit: ScheduleUnit.MINUTES,
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { FormattedMessage } from '@kbn/i18n-react';
|
||||
import { EuiFormRow, EuiSwitch } from '@elastic/eui';
|
||||
import { ConfigKey, CommonFields } from '../types';
|
||||
|
||||
interface Props {
|
||||
fields: CommonFields;
|
||||
onChange: ({ value, configKey }: { value: boolean; configKey: ConfigKey }) => void;
|
||||
}
|
||||
|
||||
export function Enabled({ fields, onChange }: Props) {
|
||||
return (
|
||||
<>
|
||||
<EuiFormRow
|
||||
helpText={
|
||||
<FormattedMessage
|
||||
id="xpack.uptime.createPackagePolicy.stepConfigure.monitorIntegrationSettingsSection.enabled.helpText"
|
||||
defaultMessage="Switch this configuration off to disable the monitor."
|
||||
/>
|
||||
}
|
||||
>
|
||||
<EuiSwitch
|
||||
label={
|
||||
<FormattedMessage
|
||||
id="xpack.uptime.createPackagePolicy.stepConfigure.monitorIntegrationSettingsSection.enabled.label"
|
||||
defaultMessage="Enabled"
|
||||
/>
|
||||
}
|
||||
data-test-subj="syntheticsEnabled"
|
||||
checked={fields[ConfigKey.ENABLED]}
|
||||
onChange={(event) =>
|
||||
onChange({
|
||||
value: event.target.checked,
|
||||
configKey: ConfigKey.ENABLED,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</EuiFormRow>
|
||||
</>
|
||||
);
|
||||
}
|
|
@ -14,6 +14,7 @@ export type CommonFormatMap = Record<keyof CommonFields | ConfigKey.NAME, Format
|
|||
export const commonFormatters: CommonFormatMap = {
|
||||
[ConfigKey.NAME]: null,
|
||||
[ConfigKey.MONITOR_TYPE]: null,
|
||||
[ConfigKey.ENABLED]: null,
|
||||
[ConfigKey.SCHEDULE]: (fields) =>
|
||||
JSON.stringify(
|
||||
`@every ${fields[ConfigKey.SCHEDULE]?.number}${fields[ConfigKey.SCHEDULE]?.unit}`
|
||||
|
|
|
@ -57,6 +57,7 @@ export const getCommonCronToSecondsNormalizer = (key: ConfigKey) => {
|
|||
|
||||
export const commonNormalizers: CommonNormalizerMap = {
|
||||
[ConfigKey.NAME]: (fields) => fields?.[ConfigKey.NAME]?.value ?? '',
|
||||
[ConfigKey.ENABLED]: getCommonNormalizer(ConfigKey.ENABLED),
|
||||
[ConfigKey.MONITOR_TYPE]: getCommonNormalizer(ConfigKey.MONITOR_TYPE),
|
||||
[ConfigKey.SCHEDULE]: (fields) => {
|
||||
const value = fields?.[ConfigKey.SCHEDULE]?.value;
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { ConfigKey, Validation, CommonFields as CommonFieldsType } from '../types';
|
||||
import { CommonFields } from '../common/common_fields';
|
||||
import { Enabled } from '../common/enabled';
|
||||
|
||||
interface Props {
|
||||
validate: Validation;
|
||||
onInputChange: ({ value, configKey }: { value: unknown; configKey: ConfigKey }) => void;
|
||||
children: React.ReactNode;
|
||||
fields: CommonFieldsType;
|
||||
}
|
||||
|
||||
export const SimpleFieldsWrapper = ({ validate, onInputChange, children, fields }: Props) => {
|
||||
return (
|
||||
<>
|
||||
<Enabled fields={fields} onChange={onInputChange} />
|
||||
{children}
|
||||
<CommonFields fields={fields} onChange={onInputChange} validate={validate} />
|
||||
</>
|
||||
);
|
||||
};
|
|
@ -28,6 +28,12 @@ jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => ({
|
|||
htmlIdGenerator: () => () => `id-${Math.random()}`,
|
||||
}));
|
||||
|
||||
// ensures that fields appropriately match to their label
|
||||
jest.mock('@elastic/eui/lib/services/accessibility', () => ({
|
||||
...jest.requireActual('@elastic/eui/lib/services/accessibility'),
|
||||
useGeneratedHtmlId: () => `id-${Math.random()}`,
|
||||
}));
|
||||
|
||||
jest.mock('../../../../../../src/plugins/kibana_react/public', () => {
|
||||
const original = jest.requireActual('../../../../../../src/plugins/kibana_react/public');
|
||||
return {
|
||||
|
@ -323,4 +329,19 @@ describe('<CustomFields />', () => {
|
|||
expect(queryByText('Browser (Beta)')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('allows monitors to be disabled', async () => {
|
||||
const { queryByLabelText } = render(
|
||||
<WrappedComponent dataStreams={[DataStream.HTTP, DataStream.TCP, DataStream.ICMP]} />
|
||||
);
|
||||
|
||||
const enabled = queryByLabelText('Enabled') as HTMLInputElement;
|
||||
expect(enabled).toBeChecked();
|
||||
|
||||
fireEvent.click(enabled);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(enabled).not.toBeChecked();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -176,9 +176,10 @@ export const CustomFields = memo<Props>(({ validate, dataStreams = [], children
|
|||
defaultMessage="Configure TLS options, including verification mode, certificate authorities, and client certificates."
|
||||
/>
|
||||
}
|
||||
id="uptimeFleetIsTLSEnabled"
|
||||
>
|
||||
<EuiSwitch
|
||||
id={'uptimeFleetIsTLSEnabled'}
|
||||
id="uptimeFleetIsTLSEnabled"
|
||||
data-test-subj="syntheticsIsTLSEnabled"
|
||||
checked={!!isTLSEnabled}
|
||||
label={
|
||||
|
|
|
@ -12,7 +12,7 @@ import { ConfigKey, Validation } from '../types';
|
|||
import { useHTTPSimpleFieldsContext } from '../contexts';
|
||||
import { OptionalLabel } from '../optional_label';
|
||||
import { ScheduleField } from '../schedule_field';
|
||||
import { CommonFields } from '../common/common_fields';
|
||||
import { SimpleFieldsWrapper } from '../common/simple_fields_wrapper';
|
||||
|
||||
interface Props {
|
||||
validate: Validation;
|
||||
|
@ -25,7 +25,7 @@ export const HTTPSimpleFields = memo<Props>(({ validate }) => {
|
|||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<SimpleFieldsWrapper fields={fields} validate={validate} onInputChange={handleInputChange}>
|
||||
<EuiFormRow
|
||||
label={
|
||||
<FormattedMessage
|
||||
|
@ -109,7 +109,6 @@ export const HTTPSimpleFields = memo<Props>(({ validate }) => {
|
|||
}
|
||||
/>
|
||||
</EuiFormRow>
|
||||
<CommonFields fields={fields} onChange={handleInputChange} validate={validate} />
|
||||
</>
|
||||
</SimpleFieldsWrapper>
|
||||
);
|
||||
});
|
||||
|
|
|
@ -12,7 +12,7 @@ import { ConfigKey, Validation } from '../types';
|
|||
import { useICMPSimpleFieldsContext } from '../contexts';
|
||||
import { OptionalLabel } from '../optional_label';
|
||||
import { ScheduleField } from '../schedule_field';
|
||||
import { CommonFields } from '../common/common_fields';
|
||||
import { SimpleFieldsWrapper } from '../common/simple_fields_wrapper';
|
||||
|
||||
interface Props {
|
||||
validate: Validation;
|
||||
|
@ -25,7 +25,7 @@ export const ICMPSimpleFields = memo<Props>(({ validate }) => {
|
|||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<SimpleFieldsWrapper fields={fields} validate={validate} onInputChange={handleInputChange}>
|
||||
<EuiFormRow
|
||||
label={
|
||||
<FormattedMessage
|
||||
|
@ -113,7 +113,6 @@ export const ICMPSimpleFields = memo<Props>(({ validate }) => {
|
|||
step={'any'}
|
||||
/>
|
||||
</EuiFormRow>
|
||||
<CommonFields fields={fields} onChange={handleInputChange} validate={validate} />
|
||||
</>
|
||||
</SimpleFieldsWrapper>
|
||||
);
|
||||
});
|
||||
|
|
|
@ -21,6 +21,12 @@ jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => ({
|
|||
htmlIdGenerator: () => () => `id-${Math.random()}`,
|
||||
}));
|
||||
|
||||
// ensures that fields appropriately match to their label
|
||||
jest.mock('@elastic/eui/lib/services/accessibility', () => ({
|
||||
...jest.requireActual('@elastic/eui/lib/services/accessibility'),
|
||||
useGeneratedHtmlId: () => `id-${Math.random()}`,
|
||||
}));
|
||||
|
||||
jest.mock('../../../../../../src/plugins/kibana_react/public', () => {
|
||||
const original = jest.requireActual('../../../../../../src/plugins/kibana_react/public');
|
||||
return {
|
||||
|
|
|
@ -21,6 +21,12 @@ jest.mock('@elastic/eui/lib/services/accessibility/html_id_generator', () => ({
|
|||
htmlIdGenerator: () => () => `id-${Math.random()}`,
|
||||
}));
|
||||
|
||||
// ensures that fields appropriately match to their label
|
||||
jest.mock('@elastic/eui/lib/services/accessibility', () => ({
|
||||
...jest.requireActual('@elastic/eui/lib/services/accessibility'),
|
||||
useGeneratedHtmlId: () => `id-${Math.random()}`,
|
||||
}));
|
||||
|
||||
jest.mock('../../../../../../src/plugins/kibana_react/public', () => {
|
||||
const original = jest.requireActual('../../../../../../src/plugins/kibana_react/public');
|
||||
return {
|
||||
|
@ -1174,6 +1180,7 @@ describe('<SyntheticsPolicyEditExtension />', () => {
|
|||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
const verificationMode = queryByLabelText('Verification mode');
|
||||
const enableTLSConfig = getByLabelText('Enable TLS configuration') as HTMLInputElement;
|
||||
expect(enableTLSConfig.getAttribute('aria-checked')).toEqual('false');
|
||||
|
|
|
@ -11,7 +11,7 @@ import { EuiFormRow, EuiFieldText } from '@elastic/eui';
|
|||
import { ConfigKey, Validation } from '../types';
|
||||
import { useTCPSimpleFieldsContext } from '../contexts';
|
||||
import { ScheduleField } from '../schedule_field';
|
||||
import { CommonFields } from '../common/common_fields';
|
||||
import { SimpleFieldsWrapper } from '../common/simple_fields_wrapper';
|
||||
|
||||
interface Props {
|
||||
validate: Validation;
|
||||
|
@ -24,7 +24,7 @@ export const TCPSimpleFields = memo<Props>(({ validate }) => {
|
|||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<SimpleFieldsWrapper fields={fields} validate={validate} onInputChange={handleInputChange}>
|
||||
<EuiFormRow
|
||||
label={
|
||||
<FormattedMessage
|
||||
|
@ -79,7 +79,6 @@ export const TCPSimpleFields = memo<Props>(({ validate }) => {
|
|||
unit={fields[ConfigKey.SCHEDULE].unit}
|
||||
/>
|
||||
</EuiFormRow>
|
||||
<CommonFields fields={fields} onChange={handleInputChange} validate={validate} />
|
||||
</>
|
||||
</SimpleFieldsWrapper>
|
||||
);
|
||||
});
|
||||
|
|
|
@ -15,6 +15,7 @@ export type CommonFormatMap = Record<keyof CommonFields | ConfigKey.NAME, Format
|
|||
|
||||
export const commonFormatters: CommonFormatMap = {
|
||||
[ConfigKey.NAME]: null,
|
||||
[ConfigKey.ENABLED]: null,
|
||||
[ConfigKey.MONITOR_TYPE]: null,
|
||||
[ConfigKey.SCHEDULE]: (fields) =>
|
||||
`@every ${fields[ConfigKey.SCHEDULE]?.number}${fields[ConfigKey.SCHEDULE]?.unit}`,
|
||||
|
|
|
@ -53,6 +53,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
|
|||
id: `${getSyntheticsPolicy(agentFullPolicy)?.streams?.[0]?.id}`,
|
||||
name,
|
||||
type: monitorType,
|
||||
enabled: true,
|
||||
processors: [
|
||||
{
|
||||
add_observer_metadata: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue