mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Synthetics] Clean up uptime common directory (#162945)
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
e0f29252dd
commit
68529573cf
57 changed files with 30 additions and 2624 deletions
|
@ -31,4 +31,3 @@ export const config: PluginConfigDescriptor = {
|
|||
};
|
||||
|
||||
export type UptimeConfig = TypeOf<typeof uptimeConfig>;
|
||||
export type ServiceConfig = TypeOf<typeof serviceConfig>;
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export const syntheticsTestSubjects = {
|
||||
urlsInput: 'urls-input',
|
||||
};
|
|
@ -13,4 +13,3 @@ export * from './settings_defaults';
|
|||
export { QUERY } from './query';
|
||||
export * from './ui';
|
||||
export * from './rest_api';
|
||||
export * from './synthetics';
|
||||
|
|
|
@ -1,288 +0,0 @@
|
|||
/*
|
||||
* 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 { i18n } from '@kbn/i18n';
|
||||
import {
|
||||
CodeEditorMode,
|
||||
BrowserAdvancedFields,
|
||||
BrowserSimpleFields,
|
||||
CommonFields,
|
||||
DataStream,
|
||||
FormMonitorType,
|
||||
HTTPAdvancedFields,
|
||||
HTTPMethod,
|
||||
HTTPSimpleFields,
|
||||
ICMPSimpleFields,
|
||||
Mode,
|
||||
MonitorDefaults,
|
||||
ResponseBodyIndexPolicy,
|
||||
ScheduleUnit,
|
||||
ScreenshotOption,
|
||||
SourceType,
|
||||
TCPAdvancedFields,
|
||||
TCPSimpleFields,
|
||||
ThrottlingConfig,
|
||||
TLSFields,
|
||||
TLSVersion,
|
||||
VerificationMode,
|
||||
} from '../runtime_types/monitor_management';
|
||||
import { ConfigKey } from './monitor_management';
|
||||
|
||||
export const DEFAULT_NAMESPACE_STRING = 'default';
|
||||
|
||||
export enum PROFILE_VALUES_ENUM {
|
||||
DEFAULT = 'default',
|
||||
CABLE = 'cable',
|
||||
DSL = 'dsl',
|
||||
THREE_G = '3g',
|
||||
FOUR_G = '4g',
|
||||
LTE = 'lte',
|
||||
FIBRE = 'fibre',
|
||||
NO_THROTTLING = 'no-throttling',
|
||||
CUSTOM = 'custom',
|
||||
}
|
||||
|
||||
export const CUSTOM_LABEL = i18n.translate('xpack.uptime.connectionProfile.custom', {
|
||||
defaultMessage: 'Custom',
|
||||
});
|
||||
|
||||
export const DEFAULT_THROTTLING_VALUE = { download: '5', upload: '3', latency: '20' };
|
||||
|
||||
export const PROFILE_VALUES: ThrottlingConfig[] = [
|
||||
{
|
||||
value: DEFAULT_THROTTLING_VALUE,
|
||||
id: PROFILE_VALUES_ENUM.DEFAULT,
|
||||
label: i18n.translate('xpack.uptime.connectionProfile.default', {
|
||||
defaultMessage: 'Default',
|
||||
}),
|
||||
},
|
||||
{
|
||||
value: { download: '5', upload: '1', latency: '28' },
|
||||
id: PROFILE_VALUES_ENUM.CABLE,
|
||||
label: i18n.translate('xpack.uptime.connectionProfile.cable', {
|
||||
defaultMessage: 'Cable',
|
||||
}),
|
||||
},
|
||||
{
|
||||
value: { download: '1.5', upload: '0.384', latency: '50' },
|
||||
id: PROFILE_VALUES_ENUM.DSL,
|
||||
label: i18n.translate('xpack.uptime.connectionProfile.dsl', {
|
||||
defaultMessage: 'DSL',
|
||||
}),
|
||||
},
|
||||
{
|
||||
value: { download: '1.6', upload: '0.768', latency: '300' },
|
||||
id: PROFILE_VALUES_ENUM.THREE_G,
|
||||
label: i18n.translate('xpack.uptime.connectionProfile.threeG', {
|
||||
defaultMessage: '3G',
|
||||
}),
|
||||
},
|
||||
{
|
||||
value: { download: '9', upload: '0.75', latency: '170' },
|
||||
id: PROFILE_VALUES_ENUM.FOUR_G,
|
||||
label: i18n.translate('xpack.uptime.connectionProfile.fourG', {
|
||||
defaultMessage: '4G',
|
||||
}),
|
||||
},
|
||||
{
|
||||
value: { download: '12', upload: '0.75', latency: '70' },
|
||||
id: PROFILE_VALUES_ENUM.LTE,
|
||||
label: i18n.translate('xpack.uptime.connectionProfile.lte', {
|
||||
defaultMessage: 'LTE',
|
||||
}),
|
||||
},
|
||||
{
|
||||
value: { download: '20', upload: '5', latency: '4' },
|
||||
id: PROFILE_VALUES_ENUM.FIBRE,
|
||||
label: i18n.translate('xpack.uptime.connectionProfile.fibre', {
|
||||
defaultMessage: 'Fibre',
|
||||
}),
|
||||
},
|
||||
{
|
||||
value: null,
|
||||
id: PROFILE_VALUES_ENUM.NO_THROTTLING,
|
||||
label: i18n.translate('xpack.uptime.connectionProfile.noThrottling', {
|
||||
defaultMessage: 'No throttling',
|
||||
}),
|
||||
},
|
||||
];
|
||||
|
||||
export const PROFILES_MAP = PROFILE_VALUES.reduce((acc, profile) => {
|
||||
acc[profile.id] = profile;
|
||||
return acc;
|
||||
}, {} as { [key: string]: ThrottlingConfig });
|
||||
|
||||
export const ALLOWED_SCHEDULES_IN_MINUTES = [
|
||||
'1',
|
||||
'3',
|
||||
'5',
|
||||
'10',
|
||||
'15',
|
||||
'20',
|
||||
'30',
|
||||
'60',
|
||||
'120',
|
||||
'240',
|
||||
];
|
||||
|
||||
export const DEFAULT_COMMON_FIELDS: CommonFields = {
|
||||
[ConfigKey.MONITOR_TYPE]: DataStream.HTTP,
|
||||
[ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.MULTISTEP,
|
||||
[ConfigKey.ENABLED]: true,
|
||||
[ConfigKey.ALERT_CONFIG]: { status: { enabled: true }, tls: { enabled: true } },
|
||||
[ConfigKey.SCHEDULE]: {
|
||||
number: '3',
|
||||
unit: ScheduleUnit.MINUTES,
|
||||
},
|
||||
[ConfigKey.APM_SERVICE_NAME]: '',
|
||||
[ConfigKey.CONFIG_ID]: '',
|
||||
[ConfigKey.TAGS]: [],
|
||||
[ConfigKey.TIMEOUT]: '16',
|
||||
[ConfigKey.NAME]: '',
|
||||
[ConfigKey.LOCATIONS]: [],
|
||||
[ConfigKey.NAMESPACE]: DEFAULT_NAMESPACE_STRING,
|
||||
[ConfigKey.MONITOR_SOURCE_TYPE]: SourceType.UI,
|
||||
[ConfigKey.JOURNEY_ID]: '',
|
||||
[ConfigKey.CONFIG_HASH]: '',
|
||||
[ConfigKey.MONITOR_QUERY_ID]: '',
|
||||
[ConfigKey.PARAMS]: '',
|
||||
};
|
||||
|
||||
export const DEFAULT_BROWSER_ADVANCED_FIELDS: BrowserAdvancedFields = {
|
||||
[ConfigKey.SCREENSHOTS]: ScreenshotOption.ON,
|
||||
[ConfigKey.SYNTHETICS_ARGS]: [],
|
||||
[ConfigKey.JOURNEY_FILTERS_MATCH]: '',
|
||||
[ConfigKey.JOURNEY_FILTERS_TAGS]: [],
|
||||
[ConfigKey.IGNORE_HTTPS_ERRORS]: false,
|
||||
[ConfigKey.THROTTLING_CONFIG]: PROFILES_MAP[PROFILE_VALUES_ENUM.DEFAULT],
|
||||
};
|
||||
|
||||
export const DEFAULT_BROWSER_SIMPLE_FIELDS: BrowserSimpleFields = {
|
||||
...DEFAULT_COMMON_FIELDS,
|
||||
[ConfigKey.PROJECT_ID]: '',
|
||||
[ConfigKey.PLAYWRIGHT_OPTIONS]: '',
|
||||
[ConfigKey.METADATA]: {
|
||||
script_source: {
|
||||
is_generated_script: false,
|
||||
file_name: '',
|
||||
},
|
||||
},
|
||||
[ConfigKey.MONITOR_TYPE]: DataStream.BROWSER,
|
||||
[ConfigKey.PORT]: null,
|
||||
[ConfigKey.SCHEDULE]: {
|
||||
unit: ScheduleUnit.MINUTES,
|
||||
number: '10',
|
||||
},
|
||||
[ConfigKey.SOURCE_INLINE]: '',
|
||||
[ConfigKey.SOURCE_PROJECT_CONTENT]: '',
|
||||
[ConfigKey.TEXT_ASSERTION]: '',
|
||||
[ConfigKey.URLS]: '',
|
||||
[ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.MULTISTEP,
|
||||
[ConfigKey.TIMEOUT]: null,
|
||||
};
|
||||
|
||||
export const DEFAULT_HTTP_SIMPLE_FIELDS: HTTPSimpleFields = {
|
||||
...DEFAULT_COMMON_FIELDS,
|
||||
[ConfigKey.METADATA]: {
|
||||
is_tls_enabled: false,
|
||||
},
|
||||
[ConfigKey.URLS]: '',
|
||||
[ConfigKey.MAX_REDIRECTS]: '0',
|
||||
[ConfigKey.MONITOR_TYPE]: DataStream.HTTP,
|
||||
[ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.HTTP,
|
||||
[ConfigKey.PORT]: null,
|
||||
};
|
||||
|
||||
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_JSON_CHECK]: [],
|
||||
[ConfigKey.RESPONSE_BODY_INDEX]: ResponseBodyIndexPolicy.ON_ERROR,
|
||||
[ConfigKey.RESPONSE_HEADERS_CHECK]: {},
|
||||
[ConfigKey.RESPONSE_HEADERS_INDEX]: true,
|
||||
[ConfigKey.RESPONSE_STATUS_CHECK]: [],
|
||||
[ConfigKey.REQUEST_BODY_CHECK]: {
|
||||
value: '',
|
||||
type: CodeEditorMode.PLAINTEXT,
|
||||
},
|
||||
[ConfigKey.REQUEST_HEADERS_CHECK]: {},
|
||||
[ConfigKey.REQUEST_METHOD_CHECK]: HTTPMethod.GET,
|
||||
[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 = {
|
||||
...DEFAULT_COMMON_FIELDS,
|
||||
[ConfigKey.HOSTS]: '',
|
||||
[ConfigKey.MONITOR_TYPE]: DataStream.ICMP,
|
||||
[ConfigKey.WAIT]: '1',
|
||||
[ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.ICMP,
|
||||
};
|
||||
|
||||
export const DEFAULT_TCP_SIMPLE_FIELDS: TCPSimpleFields = {
|
||||
...DEFAULT_COMMON_FIELDS,
|
||||
[ConfigKey.METADATA]: {
|
||||
is_tls_enabled: false,
|
||||
},
|
||||
[ConfigKey.HOSTS]: '',
|
||||
[ConfigKey.URLS]: '',
|
||||
[ConfigKey.MONITOR_TYPE]: DataStream.TCP,
|
||||
[ConfigKey.FORM_MONITOR_TYPE]: FormMonitorType.TCP,
|
||||
[ConfigKey.PORT]: null,
|
||||
};
|
||||
|
||||
export const DEFAULT_TCP_ADVANCED_FIELDS: TCPAdvancedFields = {
|
||||
[ConfigKey.PROXY_URL]: '',
|
||||
[ConfigKey.PROXY_USE_LOCAL_RESOLVER]: false,
|
||||
[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 = {
|
||||
[ConfigKey.TLS_CERTIFICATE_AUTHORITIES]: '',
|
||||
[ConfigKey.TLS_CERTIFICATE]: '',
|
||||
[ConfigKey.TLS_KEY]: '',
|
||||
[ConfigKey.TLS_KEY_PASSPHRASE]: '',
|
||||
[ConfigKey.TLS_VERIFICATION_MODE]: VerificationMode.FULL,
|
||||
[ConfigKey.TLS_VERSION]: [TLSVersion.ONE_ONE, TLSVersion.ONE_TWO, TLSVersion.ONE_THREE],
|
||||
};
|
||||
|
||||
export const DEFAULT_FIELDS: MonitorDefaults = {
|
||||
[DataStream.HTTP]: {
|
||||
...DEFAULT_HTTP_SIMPLE_FIELDS,
|
||||
...DEFAULT_HTTP_ADVANCED_FIELDS,
|
||||
...DEFAULT_TLS_FIELDS,
|
||||
},
|
||||
[DataStream.TCP]: {
|
||||
...DEFAULT_TCP_SIMPLE_FIELDS,
|
||||
...DEFAULT_TCP_ADVANCED_FIELDS,
|
||||
...DEFAULT_TLS_FIELDS,
|
||||
},
|
||||
[DataStream.ICMP]: {
|
||||
...DEFAULT_ICMP_SIMPLE_FIELDS,
|
||||
...DEFAULT_ICMP_ADVANCED_FIELDS,
|
||||
},
|
||||
[DataStream.BROWSER]: {
|
||||
...DEFAULT_BROWSER_SIMPLE_FIELDS,
|
||||
...DEFAULT_BROWSER_ADVANCED_FIELDS,
|
||||
...DEFAULT_TLS_FIELDS,
|
||||
},
|
||||
};
|
|
@ -1,119 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export enum AlertConfigKey {
|
||||
STATUS_ENABLED = 'alert.status.enabled',
|
||||
TLS_ENABLED = 'alert.tls.enabled',
|
||||
}
|
||||
|
||||
// values must match keys in the integration package
|
||||
export enum ConfigKey {
|
||||
ALERT_CONFIG = 'alert',
|
||||
APM_SERVICE_NAME = 'service.name',
|
||||
CUSTOM_HEARTBEAT_ID = 'custom_heartbeat_id',
|
||||
CONFIG_ID = 'config_id',
|
||||
CONFIG_HASH = 'hash',
|
||||
ENABLED = 'enabled',
|
||||
FORM_MONITOR_TYPE = 'form_monitor_type',
|
||||
HOSTS = 'hosts',
|
||||
IGNORE_HTTPS_ERRORS = 'ignore_https_errors',
|
||||
MONITOR_SOURCE_TYPE = 'origin',
|
||||
JOURNEY_FILTERS_MATCH = 'filter_journeys.match',
|
||||
JOURNEY_FILTERS_TAGS = 'filter_journeys.tags',
|
||||
JOURNEY_ID = 'journey_id',
|
||||
MAX_REDIRECTS = 'max_redirects',
|
||||
METADATA = '__ui',
|
||||
MODE = 'mode',
|
||||
MONITOR_TYPE = 'type',
|
||||
NAME = 'name',
|
||||
NAMESPACE = 'namespace',
|
||||
LOCATIONS = 'locations',
|
||||
PARAMS = 'params',
|
||||
PASSWORD = 'password',
|
||||
PLAYWRIGHT_OPTIONS = 'playwright_options',
|
||||
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',
|
||||
RESPONSE_JSON_CHECK = 'check.response.json',
|
||||
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',
|
||||
REQUEST_HEADERS_CHECK = 'check.request.headers',
|
||||
REQUEST_METHOD_CHECK = 'check.request.method',
|
||||
REQUEST_SEND_CHECK = 'check.send',
|
||||
REVISION = 'revision',
|
||||
SCHEDULE = 'schedule',
|
||||
SCREENSHOTS = 'screenshots',
|
||||
SOURCE_PROJECT_CONTENT = 'source.project.content',
|
||||
SOURCE_INLINE = 'source.inline.script',
|
||||
IPV4 = 'ipv4',
|
||||
IPV6 = 'ipv6',
|
||||
PROJECT_ID = 'project_id',
|
||||
SYNTHETICS_ARGS = 'synthetics_args',
|
||||
TEXT_ASSERTION = 'playwright_text_assertion',
|
||||
TLS_CERTIFICATE_AUTHORITIES = 'ssl.certificate_authorities',
|
||||
TLS_CERTIFICATE = 'ssl.certificate',
|
||||
TLS_KEY = 'ssl.key',
|
||||
TLS_KEY_PASSPHRASE = 'ssl.key_passphrase',
|
||||
TLS_VERIFICATION_MODE = 'ssl.verification_mode',
|
||||
TLS_VERSION = 'ssl.supported_protocols',
|
||||
TAGS = 'tags',
|
||||
TIMEOUT = 'timeout',
|
||||
THROTTLING_CONFIG = 'throttling',
|
||||
URLS = 'urls',
|
||||
USERNAME = 'username',
|
||||
WAIT = 'wait',
|
||||
MONITOR_QUERY_ID = 'id',
|
||||
}
|
||||
|
||||
export const secretKeys = [
|
||||
ConfigKey.PROXY_HEADERS,
|
||||
ConfigKey.PARAMS,
|
||||
ConfigKey.PASSWORD,
|
||||
ConfigKey.REQUEST_BODY_CHECK,
|
||||
ConfigKey.REQUEST_HEADERS_CHECK,
|
||||
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,
|
||||
ConfigKey.SOURCE_PROJECT_CONTENT,
|
||||
ConfigKey.SYNTHETICS_ARGS,
|
||||
ConfigKey.TLS_KEY,
|
||||
ConfigKey.TLS_KEY_PASSPHRASE,
|
||||
ConfigKey.USERNAME,
|
||||
] as const;
|
||||
|
||||
export enum LegacyConfigKey {
|
||||
SOURCE_ZIP_URL = 'source.zip_url.url',
|
||||
SOURCE_ZIP_USERNAME = 'source.zip_url.username',
|
||||
SOURCE_ZIP_PASSWORD = 'source.zip_url.password',
|
||||
SOURCE_ZIP_FOLDER = 'source.zip_url.folder',
|
||||
SOURCE_ZIP_PROXY_URL = 'source.zip_url.proxy_url',
|
||||
ZIP_URL_TLS_CERTIFICATE_AUTHORITIES = 'source.zip_url.ssl.certificate_authorities',
|
||||
ZIP_URL_TLS_CERTIFICATE = 'source.zip_url.ssl.certificate',
|
||||
ZIP_URL_TLS_KEY = 'source.zip_url.ssl.key',
|
||||
ZIP_URL_TLS_KEY_PASSPHRASE = 'source.zip_url.ssl.key_passphrase',
|
||||
ZIP_URL_TLS_VERIFICATION_MODE = 'source.zip_url.ssl.verification_mode',
|
||||
ZIP_URL_TLS_VERSION = 'source.zip_url.ssl.supported_protocols',
|
||||
|
||||
THROTTLING_CONFIG = 'throttling.config',
|
||||
IS_THROTTLING_ENABLED = 'throttling.is_enabled',
|
||||
DOWNLOAD_SPEED = 'throttling.download_speed',
|
||||
UPLOAD_SPEED = 'throttling.upload_speed',
|
||||
LATENCY = 'throttling.latency',
|
||||
}
|
|
@ -34,4 +34,6 @@ export enum API_URLS {
|
|||
DELETE_RULE = '/api/alerting/rule/',
|
||||
RULES_FIND = '/api/alerting/rules/_find',
|
||||
CONNECTOR_TYPES = '/api/actions/connector_types',
|
||||
|
||||
SYNTHETICS_HAS_INTEGRATION_MONITORS = '/internal/synthetics/fleet/has_integration_monitors',
|
||||
}
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export const CLIENT_DEFAULTS_SYNTHETICS = {
|
||||
/**
|
||||
* The beginning of the default date range is 15m ago.
|
||||
*/
|
||||
DATE_RANGE_START: 'now-24h',
|
||||
/**
|
||||
* The end of the default date range is now.
|
||||
*/
|
||||
DATE_RANGE_END: 'now',
|
||||
|
||||
/**
|
||||
* The application auto refreshes every 30s by default.
|
||||
*/
|
||||
AUTOREFRESH_INTERVAL_SECONDS: 60,
|
||||
/**
|
||||
* The application's autorefresh feature is enabled.
|
||||
*/
|
||||
AUTOREFRESH_IS_PAUSED: false,
|
||||
};
|
|
@ -1,8 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export * from './rest_api';
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export enum SYNTHETICS_API_URLS {
|
||||
// Service end points
|
||||
INDEX_TEMPLATES = '/internal/synthetics/service/index_templates',
|
||||
SERVICE_LOCATIONS = '/internal/uptime/service/locations',
|
||||
SYNTHETICS_MONITORS = '/internal/synthetics/service/monitors',
|
||||
SYNTHETICS_MONITOR_INSPECT = '/internal/synthetics/service/monitor/inspect',
|
||||
GET_SYNTHETICS_MONITOR = '/internal/synthetics/service/monitor/{monitorId}',
|
||||
SYNTHETICS_ENABLEMENT = '/internal/synthetics/service/enablement',
|
||||
RUN_ONCE_MONITOR = '/internal/synthetics/service/monitors/run_once',
|
||||
TRIGGER_MONITOR = '/internal/synthetics/service/monitors/trigger',
|
||||
SERVICE_ALLOWED = '/internal/synthetics/service/allowed',
|
||||
SYNTHETICS_APIKEY = '/internal/synthetics/service/api_key',
|
||||
SYNTHETICS_HAS_INTEGRATION_MONITORS = '/internal/synthetics/fleet/has_integration_monitors',
|
||||
|
||||
SYNTHETICS_OVERVIEW = '/internal/synthetics/overview',
|
||||
PINGS = '/internal/synthetics/pings',
|
||||
PING_STATUSES = '/internal/synthetics/ping_statuses',
|
||||
OVERVIEW_STATUS = `/internal/synthetics/overview_status`,
|
||||
INDEX_SIZE = `/internal/synthetics/index_size`,
|
||||
PARAMS = `/internal/synthetics/params`,
|
||||
AGENT_POLICIES = `/internal/synthetics/agent_policies`,
|
||||
PRIVATE_LOCATIONS = `/internal/synthetics/private_locations`,
|
||||
PRIVATE_LOCATIONS_MONITORS = `/internal/synthetics/private_locations/monitors`,
|
||||
SYNC_GLOBAL_PARAMS = `/internal/synthetics/sync_global_params`,
|
||||
ENABLE_DEFAULT_ALERTING = `/internal/synthetics/enable_default_alerting`,
|
||||
JOURNEY = `/internal/synthetics/journey/{checkGroup}`,
|
||||
SYNTHETICS_SUCCESSFUL_CHECK = `/internal/synthetics/synthetics/check/success`,
|
||||
JOURNEY_SCREENSHOT_BLOCKS = `/internal/synthetics/journey/screenshot/block`,
|
||||
JOURNEY_FAILED_STEPS = `/internal/synthetics/journeys/failed_steps`,
|
||||
NETWORK_EVENTS = `/internal/synthetics/network_events`,
|
||||
JOURNEY_SCREENSHOT = `/internal/synthetics/journey/screenshot/{checkGroup}/{stepIndex}`,
|
||||
DELETE_PACKAGE_POLICY = `/internal/synthetics/monitor/policy/{packagePolicyId}`,
|
||||
FILTERS = '/internal/synthetics/monitor/filters',
|
||||
|
||||
// Project monitor public endpoint
|
||||
SYNTHETICS_MONITORS_PROJECT = '/api/synthetics/project/{projectName}/monitors',
|
||||
SYNTHETICS_MONITORS_PROJECT_UPDATE = '/api/synthetics/project/{projectName}/monitors/_bulk_update',
|
||||
SYNTHETICS_MONITORS_PROJECT_DELETE = '/api/synthetics/project/{projectName}/monitors/_bulk_delete',
|
||||
SYNTHETICS_MONITORS_PROJECT_LEGACY = '/api/synthetics/service/project/monitors',
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* 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 { ScheduleUnit, SyntheticsMonitorSchedule } from '../runtime_types';
|
||||
import { scheduleToMilli } from './schedule_to_time';
|
||||
|
||||
describe('schedule_to_time', () => {
|
||||
describe('scheduleToMilli', () => {
|
||||
it('converts seconds schedule to millis', () => {
|
||||
const schedule: SyntheticsMonitorSchedule = { unit: ScheduleUnit.SECONDS, number: '10' };
|
||||
expect(scheduleToMilli(schedule)).toEqual(10 * 1000);
|
||||
});
|
||||
|
||||
it('converts minutes schedule to millis', () => {
|
||||
const schedule: SyntheticsMonitorSchedule = { unit: ScheduleUnit.MINUTES, number: '6' };
|
||||
expect(scheduleToMilli(schedule)).toEqual(6 * 60 * 1000);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* 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 { ScheduleUnit, SyntheticsMonitorSchedule } from '../runtime_types';
|
||||
|
||||
export function scheduleToMilli(schedule: SyntheticsMonitorSchedule): number {
|
||||
const timeValue = parseInt(schedule.number, 10);
|
||||
return timeValue * getMilliFactorForScheduleUnit(schedule.unit);
|
||||
}
|
||||
|
||||
export function scheduleToMinutes(schedule: SyntheticsMonitorSchedule): number {
|
||||
return Math.floor(scheduleToMilli(schedule) / (60 * 1000));
|
||||
}
|
||||
|
||||
function getMilliFactorForScheduleUnit(scheduleUnit: ScheduleUnit): number {
|
||||
switch (scheduleUnit) {
|
||||
case ScheduleUnit.SECONDS:
|
||||
return 1000;
|
||||
case ScheduleUnit.MINUTES:
|
||||
return 60 * 1000;
|
||||
default:
|
||||
throw new Error(`Unit ${scheduleUnit} is not supported`);
|
||||
}
|
||||
}
|
|
@ -33,7 +33,6 @@ describe('Legacy Alert Actions factory', () => {
|
|||
defaultSubjectMessage: MonitorStatusTranslations.defaultSubjectMessage,
|
||||
defaultRecoverySubjectMessage: MonitorStatusTranslations.defaultRecoverySubjectMessage,
|
||||
},
|
||||
isLegacy: true,
|
||||
});
|
||||
expect(resp).toEqual([
|
||||
{
|
||||
|
@ -81,7 +80,6 @@ describe('Legacy Alert Actions factory', () => {
|
|||
defaultSubjectMessage: MonitorStatusTranslations.defaultSubjectMessage,
|
||||
defaultRecoverySubjectMessage: MonitorStatusTranslations.defaultRecoverySubjectMessage,
|
||||
},
|
||||
isLegacy: true,
|
||||
defaultEmail: {
|
||||
to: ['test@email.com'],
|
||||
},
|
||||
|
@ -147,7 +145,6 @@ describe('Legacy Alert Actions factory', () => {
|
|||
defaultSubjectMessage: MonitorStatusTranslations.defaultSubjectMessage,
|
||||
defaultRecoverySubjectMessage: MonitorStatusTranslations.defaultRecoverySubjectMessage,
|
||||
},
|
||||
isLegacy: true,
|
||||
});
|
||||
expect(resp).toEqual([
|
||||
{
|
||||
|
@ -209,7 +206,6 @@ describe('Legacy Alert Actions factory', () => {
|
|||
defaultSubjectMessage: MonitorStatusTranslations.defaultSubjectMessage,
|
||||
defaultRecoverySubjectMessage: MonitorStatusTranslations.defaultRecoverySubjectMessage,
|
||||
},
|
||||
isLegacy: true,
|
||||
});
|
||||
expect(resp).toEqual([
|
||||
{
|
||||
|
|
|
@ -44,13 +44,11 @@ export function populateAlertActions({
|
|||
defaultEmail,
|
||||
groupId,
|
||||
translations,
|
||||
isLegacy = false,
|
||||
}: {
|
||||
groupId: string;
|
||||
defaultActions: ActionConnector[];
|
||||
defaultEmail?: DefaultEmail;
|
||||
translations: Translations;
|
||||
isLegacy?: boolean;
|
||||
}) {
|
||||
const actions: RuleAction[] = [];
|
||||
defaultActions.forEach((aId) => {
|
||||
|
@ -58,13 +56,7 @@ export function populateAlertActions({
|
|||
id: aId.id,
|
||||
group: groupId,
|
||||
params: {},
|
||||
frequency: !isLegacy
|
||||
? {
|
||||
notifyWhen: 'onActionGroupChange',
|
||||
throttle: null,
|
||||
summary: false,
|
||||
}
|
||||
: undefined,
|
||||
frequency: undefined,
|
||||
};
|
||||
|
||||
const recoveredAction: RuleAction = {
|
||||
|
@ -73,13 +65,7 @@ export function populateAlertActions({
|
|||
params: {
|
||||
message: translations.defaultRecoveryMessage,
|
||||
},
|
||||
frequency: !isLegacy
|
||||
? {
|
||||
notifyWhen: 'onActionGroupChange',
|
||||
throttle: null,
|
||||
summary: false,
|
||||
}
|
||||
: undefined,
|
||||
frequency: undefined,
|
||||
};
|
||||
|
||||
switch (aId.actionTypeId) {
|
||||
|
@ -95,8 +81,8 @@ export function populateAlertActions({
|
|||
actions.push(recoveredAction);
|
||||
break;
|
||||
case INDEX_ACTION_ID:
|
||||
action.params = getIndexActionParams(translations, false, isLegacy);
|
||||
recoveredAction.params = getIndexActionParams(translations, true, isLegacy);
|
||||
action.params = getIndexActionParams(translations, false);
|
||||
recoveredAction.params = getIndexActionParams(translations, true);
|
||||
actions.push(recoveredAction);
|
||||
break;
|
||||
case SERVICE_NOW_ACTION_ID:
|
||||
|
@ -138,12 +124,8 @@ export function populateAlertActions({
|
|||
return actions;
|
||||
}
|
||||
|
||||
function getIndexActionParams(
|
||||
translations: Translations,
|
||||
recovery = false,
|
||||
isLegacy = false
|
||||
): IndexActionParams {
|
||||
if (isLegacy && recovery) {
|
||||
function getIndexActionParams(translations: Translations, recovery = false): IndexActionParams {
|
||||
if (recovery) {
|
||||
return {
|
||||
documents: [
|
||||
{
|
||||
|
@ -158,44 +140,14 @@ function getIndexActionParams(
|
|||
};
|
||||
}
|
||||
|
||||
if (isLegacy) {
|
||||
return {
|
||||
documents: [
|
||||
{
|
||||
monitorName: '{{context.monitorName}}',
|
||||
monitorUrl: '{{{context.monitorUrl}}}',
|
||||
statusMessage: '{{{context.statusMessage}}}',
|
||||
latestErrorMessage: '{{{context.latestErrorMessage}}}',
|
||||
observerLocation: '{{context.observerLocation}}',
|
||||
},
|
||||
],
|
||||
indexOverride: null,
|
||||
};
|
||||
}
|
||||
|
||||
if (recovery) {
|
||||
return {
|
||||
documents: [
|
||||
{
|
||||
monitorName: '{{context.monitorName}}',
|
||||
monitorUrl: '{{{context.monitorUrl}}}',
|
||||
statusMessage: '{{{context.status}}}',
|
||||
latestErrorMessage: '{{{context.latestErrorMessage}}}',
|
||||
observerLocation: '{{context.locationName}}',
|
||||
recoveryReason: '{{context.recoveryReason}}',
|
||||
},
|
||||
],
|
||||
indexOverride: null,
|
||||
};
|
||||
}
|
||||
return {
|
||||
documents: [
|
||||
{
|
||||
monitorName: '{{context.monitorName}}',
|
||||
monitorUrl: '{{{context.monitorUrl}}}',
|
||||
statusMessage: '{{{context.status}}}',
|
||||
latestErrorMessage: '{{{context.lastErrorMessage}}}',
|
||||
observerLocation: '{{context.locationName}}',
|
||||
statusMessage: '{{{context.statusMessage}}}',
|
||||
latestErrorMessage: '{{{context.latestErrorMessage}}}',
|
||||
observerLocation: '{{context.observerLocation}}',
|
||||
},
|
||||
],
|
||||
indexOverride: null,
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
|
||||
export const SyntheticsCommonStateCodec = t.intersection([
|
||||
t.partial({
|
||||
firstTriggeredAt: t.string,
|
||||
lastTriggeredAt: t.string,
|
||||
lastResolvedAt: t.string,
|
||||
meta: t.record(t.string, t.unknown),
|
||||
idWithLocation: t.string,
|
||||
}),
|
||||
t.type({
|
||||
firstCheckedAt: t.string,
|
||||
lastCheckedAt: t.string,
|
||||
isTriggered: t.boolean,
|
||||
}),
|
||||
]);
|
||||
|
||||
export type SyntheticsCommonState = t.TypeOf<typeof SyntheticsCommonStateCodec>;
|
||||
|
||||
export const SyntheticsMonitorStatusAlertStateCodec = t.type({
|
||||
configId: t.string,
|
||||
locationId: t.string,
|
||||
locationName: t.string,
|
||||
errorStartedAt: t.string,
|
||||
lastErrorMessage: t.string,
|
||||
stateId: t.string,
|
||||
});
|
||||
|
||||
export type SyntheticsMonitorStatusAlertState = t.TypeOf<
|
||||
typeof SyntheticsMonitorStatusAlertStateCodec
|
||||
>;
|
|
@ -51,5 +51,3 @@ export const LocationMonitorsType = t.type({
|
|||
})
|
||||
),
|
||||
});
|
||||
|
||||
export type LocationMonitorsResponse = t.TypeOf<typeof LocationMonitorsType>;
|
||||
|
|
|
@ -13,5 +13,3 @@ export * from './monitor';
|
|||
export * from './ping';
|
||||
export * from './snapshot';
|
||||
export * from './network_events';
|
||||
export * from './monitor_management';
|
||||
export * from './monitor_management/synthetics_private_locations';
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
|
||||
export const AlertConfigCodec = t.intersection([
|
||||
t.interface({
|
||||
enabled: t.boolean,
|
||||
}),
|
||||
t.partial({
|
||||
groupBy: t.string,
|
||||
}),
|
||||
]);
|
||||
|
||||
export const AlertConfigsCodec = t.partial({
|
||||
tls: AlertConfigCodec,
|
||||
status: AlertConfigCodec,
|
||||
});
|
||||
|
||||
export type AlertConfig = t.TypeOf<typeof AlertConfigCodec>;
|
||||
export type AlertConfigs = t.TypeOf<typeof AlertConfigsCodec>;
|
||||
|
||||
export const toggleStatusAlert = (configs: AlertConfigs = {}): AlertConfigs => {
|
||||
if (configs.status?.enabled) {
|
||||
return {
|
||||
...configs,
|
||||
status: {
|
||||
...configs.status,
|
||||
enabled: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
return {
|
||||
...configs,
|
||||
status: {
|
||||
enabled: true,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const isStatusEnabled = (configs: AlertConfigs = {}): boolean => {
|
||||
return configs.status?.enabled ?? false;
|
||||
};
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
import { tEnum } from '../../utils/t_enum';
|
||||
import { ConfigKey } from '../../constants/monitor_management';
|
||||
export { ConfigKey } from '../../constants/monitor_management';
|
||||
|
||||
export const ConfigKeyCodec = tEnum<ConfigKey>('ConfigKey', ConfigKey);
|
||||
export type ConfigKeyType = t.TypeOf<typeof ConfigKeyCodec>;
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
|
||||
const MonitorFilterCodec = t.interface({
|
||||
label: t.string,
|
||||
count: t.number,
|
||||
});
|
||||
|
||||
export type MonitorFilter = t.TypeOf<typeof MonitorFilterCodec>;
|
||||
|
||||
export const MonitorFiltersResultCodec = t.interface({
|
||||
monitorTypes: t.array(MonitorFilterCodec),
|
||||
tags: t.array(MonitorFilterCodec),
|
||||
locations: t.array(MonitorFilterCodec),
|
||||
projects: t.array(MonitorFilterCodec),
|
||||
schedules: t.array(MonitorFilterCodec),
|
||||
});
|
||||
|
||||
export type MonitorFiltersResult = t.TypeOf<typeof MonitorFiltersResultCodec>;
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export * from './state';
|
||||
export * from './config_key';
|
||||
export * from './monitor_configs';
|
||||
export * from './monitor_meta_data';
|
||||
export * from './monitor_types';
|
||||
export * from './monitor_types_project';
|
||||
export * from './locations';
|
||||
export * from './synthetics_private_locations';
|
||||
export * from './synthetics_overview_status';
|
||||
export * from './synthetics_params';
|
||||
export * from './filters';
|
|
@ -1,147 +0,0 @@
|
|||
/*
|
||||
* 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 { isLeft } from 'fp-ts/lib/Either';
|
||||
import * as t from 'io-ts';
|
||||
import { tEnum } from '../../utils/t_enum';
|
||||
|
||||
export enum LocationStatus {
|
||||
GA = 'ga',
|
||||
BETA = 'beta',
|
||||
EXPERIMENTAL = 'experimental',
|
||||
}
|
||||
|
||||
export enum BandwidthLimitKey {
|
||||
DOWNLOAD = 'download',
|
||||
UPLOAD = 'upload',
|
||||
}
|
||||
|
||||
export const DEFAULT_BANDWIDTH_LIMIT = {
|
||||
[BandwidthLimitKey.DOWNLOAD]: 100,
|
||||
[BandwidthLimitKey.UPLOAD]: 30,
|
||||
};
|
||||
|
||||
export const DEFAULT_THROTTLING = {
|
||||
[BandwidthLimitKey.DOWNLOAD]: DEFAULT_BANDWIDTH_LIMIT[BandwidthLimitKey.DOWNLOAD],
|
||||
[BandwidthLimitKey.UPLOAD]: DEFAULT_BANDWIDTH_LIMIT[BandwidthLimitKey.UPLOAD],
|
||||
};
|
||||
|
||||
export const BandwidthLimitKeyCodec = tEnum<BandwidthLimitKey>(
|
||||
'BandwidthLimitKey',
|
||||
BandwidthLimitKey
|
||||
);
|
||||
|
||||
export type BandwidthLimitKeyType = t.TypeOf<typeof BandwidthLimitKeyCodec>;
|
||||
|
||||
export const LocationGeoCodec = t.interface({
|
||||
lat: t.union([t.string, t.number]),
|
||||
lon: t.union([t.string, t.number]),
|
||||
});
|
||||
|
||||
export const LocationStatusCodec = tEnum<LocationStatus>('LocationStatus', LocationStatus);
|
||||
export type LocationStatusType = t.TypeOf<typeof LocationStatusCodec>;
|
||||
|
||||
export const ManifestLocationCodec = t.interface({
|
||||
url: t.string,
|
||||
geo: t.interface({
|
||||
name: t.string,
|
||||
location: LocationGeoCodec,
|
||||
}),
|
||||
status: LocationStatusCodec,
|
||||
});
|
||||
|
||||
export const ServiceLocationCodec = t.intersection([
|
||||
t.interface({
|
||||
id: t.string,
|
||||
label: t.string,
|
||||
isServiceManaged: t.boolean,
|
||||
}),
|
||||
t.partial({
|
||||
url: t.string,
|
||||
geo: LocationGeoCodec,
|
||||
status: LocationStatusCodec,
|
||||
isInvalid: t.boolean,
|
||||
}),
|
||||
]);
|
||||
|
||||
export const PublicLocationCodec = t.intersection([
|
||||
ServiceLocationCodec,
|
||||
t.interface({ url: t.string }),
|
||||
]);
|
||||
|
||||
export const PublicLocationsCodec = t.array(PublicLocationCodec);
|
||||
|
||||
export const MonitorServiceLocationCodec = t.intersection([
|
||||
t.interface({
|
||||
id: t.string,
|
||||
}),
|
||||
t.partial({
|
||||
label: t.string,
|
||||
geo: LocationGeoCodec,
|
||||
url: t.string,
|
||||
isServiceManaged: t.boolean,
|
||||
status: t.string,
|
||||
}),
|
||||
]);
|
||||
|
||||
export const ServiceLocationErrors = t.array(
|
||||
t.interface({
|
||||
locationId: t.string,
|
||||
error: t.intersection([
|
||||
t.interface({
|
||||
reason: t.string,
|
||||
status: t.number,
|
||||
}),
|
||||
t.partial({
|
||||
failed_monitors: t.union([
|
||||
t.array(
|
||||
t.interface({
|
||||
id: t.string,
|
||||
message: t.string,
|
||||
})
|
||||
),
|
||||
t.null,
|
||||
]),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
);
|
||||
|
||||
export const ServiceLocationsCodec = t.array(ServiceLocationCodec);
|
||||
export const MonitorServiceLocationsCodec = t.array(MonitorServiceLocationCodec);
|
||||
|
||||
export const LocationCodec = t.intersection([
|
||||
ServiceLocationCodec,
|
||||
t.partial({ isServiceManaged: t.boolean }),
|
||||
]);
|
||||
|
||||
export const LocationsCodec = t.array(LocationCodec);
|
||||
|
||||
export const isServiceLocationInvalid = (location: MonitorServiceLocation) =>
|
||||
isLeft(MonitorServiceLocationCodec.decode(location));
|
||||
|
||||
export const ThrottlingOptionsCodec = t.interface({
|
||||
[BandwidthLimitKey.DOWNLOAD]: t.number,
|
||||
[BandwidthLimitKey.UPLOAD]: t.number,
|
||||
});
|
||||
|
||||
export const ServiceLocationsApiResponseCodec = t.interface({
|
||||
throttling: t.union([ThrottlingOptionsCodec, t.undefined]),
|
||||
locations: ServiceLocationsCodec,
|
||||
});
|
||||
|
||||
export type ManifestLocation = t.TypeOf<typeof ManifestLocationCodec>;
|
||||
export type ServiceLocation = t.TypeOf<typeof ServiceLocationCodec>;
|
||||
export type ServiceLocations = t.TypeOf<typeof ServiceLocationsCodec>;
|
||||
export type MonitorServiceLocation = t.TypeOf<typeof MonitorServiceLocationCodec>;
|
||||
export type MonitorServiceLocations = t.TypeOf<typeof MonitorServiceLocationsCodec>;
|
||||
export type ServiceLocationsApiResponse = t.TypeOf<typeof ServiceLocationsApiResponseCodec>;
|
||||
export type ServiceLocationErrors = t.TypeOf<typeof ServiceLocationErrors>;
|
||||
export type ThrottlingOptions = t.TypeOf<typeof ThrottlingOptionsCodec>;
|
||||
export type Locations = t.TypeOf<typeof LocationsCodec>;
|
||||
export type PublicLocation = t.TypeOf<typeof PublicLocationCodec>;
|
||||
export type PublicLocations = t.TypeOf<typeof PublicLocationsCodec>;
|
|
@ -1,146 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
import { tEnum } from '../../utils/t_enum';
|
||||
|
||||
export enum DataStream {
|
||||
HTTP = 'http',
|
||||
TCP = 'tcp',
|
||||
ICMP = 'icmp',
|
||||
BROWSER = 'browser',
|
||||
}
|
||||
|
||||
export const DataStreamCodec = tEnum<DataStream>('DataStream', DataStream);
|
||||
export type DataStreamType = t.TypeOf<typeof DataStreamCodec>;
|
||||
|
||||
export enum HTTPMethod {
|
||||
GET = 'GET',
|
||||
POST = 'POST',
|
||||
PUT = 'PUT',
|
||||
DELETE = 'DELETE',
|
||||
HEAD = 'HEAD',
|
||||
}
|
||||
|
||||
export const HTTPMethodCodec = tEnum<HTTPMethod>('HTTPMethod', HTTPMethod);
|
||||
export type HTTPMethodType = t.TypeOf<typeof HTTPMethodCodec>;
|
||||
|
||||
export enum ResponseBodyIndexPolicy {
|
||||
ALWAYS = 'always',
|
||||
NEVER = 'never',
|
||||
ON_ERROR = 'on_error',
|
||||
}
|
||||
|
||||
export const ResponseBodyIndexPolicyCodec = tEnum<ResponseBodyIndexPolicy>(
|
||||
'ResponseBodyIndexPolicy',
|
||||
ResponseBodyIndexPolicy
|
||||
);
|
||||
export type ResponseBodyIndexPolicyType = t.TypeOf<typeof ResponseBodyIndexPolicyCodec>;
|
||||
|
||||
export enum MonacoEditorLangId {
|
||||
JSON = 'xjson',
|
||||
PLAINTEXT = 'plaintext',
|
||||
XML = 'xml',
|
||||
JAVASCRIPT = 'javascript',
|
||||
}
|
||||
|
||||
export const MonacoEditorLangIdCodec = tEnum<MonacoEditorLangId>(
|
||||
'MonacoEditorLangId',
|
||||
MonacoEditorLangId
|
||||
);
|
||||
export type MonacoEditorLangIdType = t.TypeOf<typeof MonacoEditorLangIdCodec>;
|
||||
|
||||
export enum CodeEditorMode {
|
||||
FORM = 'form',
|
||||
JSON = 'json',
|
||||
PLAINTEXT = 'text',
|
||||
XML = 'xml',
|
||||
}
|
||||
|
||||
export const CodeEditorModeCodec = tEnum<CodeEditorMode>('CodeEditorMode', CodeEditorMode);
|
||||
export type CodeEditorModeType = t.TypeOf<typeof CodeEditorModeCodec>;
|
||||
|
||||
export enum ContentType {
|
||||
JSON = 'application/json',
|
||||
TEXT = 'text/plain',
|
||||
XML = 'application/xml',
|
||||
FORM = 'application/x-www-form-urlencoded',
|
||||
}
|
||||
|
||||
export const ContentTypeCodec = tEnum<ContentType>('ContentType', ContentType);
|
||||
export type ContentTypeType = t.TypeOf<typeof ContentTypeCodec>;
|
||||
|
||||
export enum ScheduleUnit {
|
||||
MINUTES = 'm',
|
||||
SECONDS = 's',
|
||||
}
|
||||
|
||||
export const ScheduleUnitCodec = tEnum<ScheduleUnit>('ScheduleUnit', ScheduleUnit);
|
||||
export type ScheduleUnitType = t.TypeOf<typeof ScheduleUnitCodec>;
|
||||
|
||||
export enum VerificationMode {
|
||||
CERTIFICATE = 'certificate',
|
||||
FULL = 'full',
|
||||
NONE = 'none',
|
||||
STRICT = 'strict',
|
||||
}
|
||||
|
||||
export const VerificationModeCodec = tEnum<VerificationMode>('VerificationMode', VerificationMode);
|
||||
export type VerificationModeType = t.TypeOf<typeof VerificationModeCodec>;
|
||||
|
||||
export enum TLSVersion {
|
||||
ONE_ZERO = 'TLSv1.0',
|
||||
ONE_ONE = 'TLSv1.1',
|
||||
ONE_TWO = 'TLSv1.2',
|
||||
ONE_THREE = 'TLSv1.3',
|
||||
}
|
||||
|
||||
export const TLSVersionCodec = tEnum<TLSVersion>('TLSVersion', TLSVersion);
|
||||
export type TLSVersionType = t.TypeOf<typeof TLSVersionCodec>;
|
||||
|
||||
export enum ScreenshotOption {
|
||||
ON = 'on',
|
||||
OFF = 'off',
|
||||
ONLY_ON_FAILURE = 'only-on-failure',
|
||||
}
|
||||
|
||||
export const ScreenshotOptionCodec = tEnum<ScreenshotOption>('ScreenshotOption', ScreenshotOption);
|
||||
export type ScreenshotOptionType = t.TypeOf<typeof ScreenshotOptionCodec>;
|
||||
|
||||
export enum SourceType {
|
||||
UI = 'ui',
|
||||
PROJECT = 'project',
|
||||
}
|
||||
|
||||
export const SourceTypeCodec = tEnum<SourceType>('SourceType', SourceType);
|
||||
|
||||
export enum FormMonitorType {
|
||||
SINGLE = 'single',
|
||||
MULTISTEP = 'multistep',
|
||||
HTTP = 'http',
|
||||
TCP = 'tcp',
|
||||
ICMP = 'icmp',
|
||||
}
|
||||
|
||||
export const FormMonitorTypeCodec = tEnum<FormMonitorType>('FormMonitorType', FormMonitorType);
|
||||
|
||||
export enum Mode {
|
||||
ANY = 'any',
|
||||
ALL = 'all',
|
||||
}
|
||||
export const ModeCodec = tEnum<Mode>('Mode', Mode);
|
||||
export type ModeType = t.TypeOf<typeof ModeCodec>;
|
||||
|
||||
export const ResponseCheckJSONCodec = t.interface({
|
||||
description: t.string,
|
||||
expression: t.string,
|
||||
});
|
||||
export type ResponseCheckJSON = t.TypeOf<typeof ResponseCheckJSONCodec>;
|
||||
|
||||
export const RequestBodyCheckCodec = t.interface({ value: t.string, type: CodeEditorModeCodec });
|
||||
|
||||
export type RequestBodyCheck = t.TypeOf<typeof RequestBodyCheckCodec>;
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
|
||||
const ScriptSourceCodec = t.interface({
|
||||
is_generated_script: t.boolean,
|
||||
file_name: t.string,
|
||||
});
|
||||
|
||||
export const MetadataCodec = t.partial({
|
||||
is_tls_enabled: t.boolean,
|
||||
script_source: ScriptSourceCodec,
|
||||
});
|
||||
|
||||
export type Metadata = t.TypeOf<typeof MetadataCodec>;
|
|
@ -1,428 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
import { AlertConfigsCodec } from './alert_config';
|
||||
import { secretKeys } from '../../constants/monitor_management';
|
||||
import { ConfigKey } from './config_key';
|
||||
import { MonitorServiceLocationCodec, ServiceLocationErrors } from './locations';
|
||||
import {
|
||||
DataStream,
|
||||
DataStreamCodec,
|
||||
FormMonitorTypeCodec,
|
||||
ModeCodec,
|
||||
ResponseBodyIndexPolicyCodec,
|
||||
ResponseCheckJSONCodec,
|
||||
ScheduleUnitCodec,
|
||||
SourceTypeCodec,
|
||||
TLSVersionCodec,
|
||||
VerificationModeCodec,
|
||||
RequestBodyCheckCodec,
|
||||
} from './monitor_configs';
|
||||
import { MetadataCodec } from './monitor_meta_data';
|
||||
import { PrivateLocationCodec } from './synthetics_private_locations';
|
||||
|
||||
const ScheduleCodec = t.interface({
|
||||
number: t.string,
|
||||
unit: ScheduleUnitCodec,
|
||||
});
|
||||
|
||||
export type SyntheticsMonitorSchedule = t.TypeOf<typeof ScheduleCodec>;
|
||||
|
||||
// TLSFields
|
||||
export const TLSFieldsCodec = t.partial({
|
||||
[ConfigKey.TLS_CERTIFICATE_AUTHORITIES]: t.string,
|
||||
[ConfigKey.TLS_CERTIFICATE]: t.string,
|
||||
[ConfigKey.TLS_VERIFICATION_MODE]: VerificationModeCodec,
|
||||
[ConfigKey.TLS_VERSION]: t.array(TLSVersionCodec),
|
||||
});
|
||||
|
||||
export const TLSSensitiveFieldsCodec = t.partial({
|
||||
[ConfigKey.TLS_KEY]: t.string,
|
||||
[ConfigKey.TLS_KEY_PASSPHRASE]: t.string,
|
||||
});
|
||||
|
||||
export const TLSCodec = t.intersection([TLSFieldsCodec, TLSSensitiveFieldsCodec]);
|
||||
|
||||
export type TLSFields = t.TypeOf<typeof TLSCodec>;
|
||||
|
||||
// CommonFields
|
||||
export const CommonFieldsCodec = t.intersection([
|
||||
t.interface({
|
||||
[ConfigKey.NAME]: t.string,
|
||||
[ConfigKey.NAMESPACE]: t.string,
|
||||
[ConfigKey.MONITOR_TYPE]: DataStreamCodec,
|
||||
[ConfigKey.ENABLED]: t.boolean,
|
||||
[ConfigKey.SCHEDULE]: ScheduleCodec,
|
||||
[ConfigKey.APM_SERVICE_NAME]: t.string,
|
||||
[ConfigKey.TAGS]: t.array(t.string),
|
||||
[ConfigKey.LOCATIONS]: t.array(t.union([MonitorServiceLocationCodec, PrivateLocationCodec])),
|
||||
[ConfigKey.MONITOR_QUERY_ID]: t.string,
|
||||
[ConfigKey.CONFIG_ID]: t.string,
|
||||
}),
|
||||
t.partial({
|
||||
[ConfigKey.FORM_MONITOR_TYPE]: FormMonitorTypeCodec,
|
||||
[ConfigKey.TIMEOUT]: t.union([t.string, t.null]),
|
||||
[ConfigKey.REVISION]: t.number,
|
||||
[ConfigKey.MONITOR_SOURCE_TYPE]: SourceTypeCodec,
|
||||
[ConfigKey.CONFIG_HASH]: t.string,
|
||||
[ConfigKey.JOURNEY_ID]: t.string,
|
||||
[ConfigKey.PROJECT_ID]: t.string,
|
||||
[ConfigKey.ORIGINAL_SPACE]: t.string,
|
||||
[ConfigKey.CUSTOM_HEARTBEAT_ID]: t.string,
|
||||
[ConfigKey.ALERT_CONFIG]: AlertConfigsCodec,
|
||||
[ConfigKey.PARAMS]: t.string,
|
||||
}),
|
||||
]);
|
||||
|
||||
export type CommonFields = t.TypeOf<typeof CommonFieldsCodec>;
|
||||
|
||||
// TCP Simple Fields
|
||||
export const TCPSimpleFieldsCodec = t.intersection([
|
||||
t.interface({
|
||||
[ConfigKey.METADATA]: MetadataCodec,
|
||||
[ConfigKey.HOSTS]: t.string,
|
||||
[ConfigKey.PORT]: t.union([t.number, t.null]),
|
||||
}),
|
||||
t.partial({
|
||||
[ConfigKey.URLS]: t.string,
|
||||
}),
|
||||
CommonFieldsCodec,
|
||||
]);
|
||||
|
||||
export type TCPSimpleFields = t.TypeOf<typeof TCPSimpleFieldsCodec>;
|
||||
|
||||
// TCPAdvancedFields
|
||||
export const TCPAdvancedFieldsCodec = t.intersection([
|
||||
t.interface({
|
||||
[ConfigKey.PROXY_URL]: t.string,
|
||||
[ConfigKey.PROXY_USE_LOCAL_RESOLVER]: t.boolean,
|
||||
}),
|
||||
t.partial({
|
||||
[ConfigKey.MODE]: ModeCodec,
|
||||
[ConfigKey.IPV4]: t.boolean,
|
||||
[ConfigKey.IPV6]: t.boolean,
|
||||
}),
|
||||
]);
|
||||
|
||||
export const TCPSensitiveAdvancedFieldsCodec = t.interface({
|
||||
[ConfigKey.RESPONSE_RECEIVE_CHECK]: t.string,
|
||||
[ConfigKey.REQUEST_SEND_CHECK]: t.string,
|
||||
});
|
||||
|
||||
export const TCPAdvancedCodec = t.intersection([
|
||||
TCPAdvancedFieldsCodec,
|
||||
TCPSensitiveAdvancedFieldsCodec,
|
||||
]);
|
||||
|
||||
export type TCPAdvancedFields = t.TypeOf<typeof TCPAdvancedCodec>;
|
||||
|
||||
// TCPFields
|
||||
export const EncryptedTCPFieldsCodec = t.intersection([
|
||||
TCPSimpleFieldsCodec,
|
||||
TCPAdvancedFieldsCodec,
|
||||
TLSFieldsCodec,
|
||||
]);
|
||||
|
||||
export const TCPFieldsCodec = t.intersection([
|
||||
EncryptedTCPFieldsCodec,
|
||||
TCPSensitiveAdvancedFieldsCodec,
|
||||
TLSSensitiveFieldsCodec,
|
||||
]);
|
||||
|
||||
export type TCPFields = t.TypeOf<typeof TCPFieldsCodec>;
|
||||
|
||||
// ICMP SimpleFields
|
||||
export const ICMPSimpleFieldsCodec = t.intersection([
|
||||
t.interface({
|
||||
[ConfigKey.HOSTS]: t.string,
|
||||
[ConfigKey.WAIT]: t.string,
|
||||
}),
|
||||
CommonFieldsCodec,
|
||||
]);
|
||||
|
||||
export type ICMPSimpleFields = t.TypeOf<typeof ICMPSimpleFieldsCodec>;
|
||||
|
||||
// ICMPAdvancedFields
|
||||
export const ICMPAdvancedFieldsCodec = t.partial({
|
||||
[ConfigKey.MODE]: ModeCodec,
|
||||
[ConfigKey.IPV4]: t.boolean,
|
||||
[ConfigKey.IPV6]: t.boolean,
|
||||
});
|
||||
|
||||
// ICMPFields
|
||||
export const ICMPFieldsCodec = t.intersection([ICMPSimpleFieldsCodec, ICMPAdvancedFieldsCodec]);
|
||||
|
||||
export type ICMPFields = t.TypeOf<typeof ICMPFieldsCodec>;
|
||||
|
||||
// HTTPSimpleFields
|
||||
export const HTTPSimpleFieldsCodec = t.intersection([
|
||||
t.interface({
|
||||
[ConfigKey.METADATA]: MetadataCodec,
|
||||
[ConfigKey.MAX_REDIRECTS]: t.string,
|
||||
[ConfigKey.URLS]: t.string,
|
||||
[ConfigKey.PORT]: t.union([t.number, t.null]),
|
||||
}),
|
||||
CommonFieldsCodec,
|
||||
]);
|
||||
|
||||
export type HTTPSimpleFields = t.TypeOf<typeof HTTPSimpleFieldsCodec>;
|
||||
|
||||
// HTTPAdvancedFields
|
||||
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,
|
||||
[ConfigKey.RESPONSE_BODY_MAX_BYTES]: t.string,
|
||||
[ConfigKey.IPV4]: t.boolean,
|
||||
[ConfigKey.IPV6]: t.boolean,
|
||||
}),
|
||||
]);
|
||||
|
||||
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]: RequestBodyCheckCodec,
|
||||
[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),
|
||||
[ConfigKey.RESPONSE_JSON_CHECK]: t.array(ResponseCheckJSONCodec),
|
||||
}),
|
||||
]);
|
||||
|
||||
export const HTTPAdvancedCodec = t.intersection([
|
||||
HTTPAdvancedFieldsCodec,
|
||||
HTTPSensitiveAdvancedFieldsCodec,
|
||||
]);
|
||||
|
||||
export type HTTPAdvancedFields = t.TypeOf<typeof HTTPAdvancedCodec>;
|
||||
|
||||
// HTTPFields
|
||||
export const EncryptedHTTPFieldsCodec = t.intersection([
|
||||
HTTPSimpleFieldsCodec,
|
||||
HTTPAdvancedFieldsCodec,
|
||||
TLSFieldsCodec,
|
||||
]);
|
||||
|
||||
export const HTTPFieldsCodec = t.intersection([
|
||||
EncryptedHTTPFieldsCodec,
|
||||
HTTPSensitiveAdvancedFieldsCodec,
|
||||
TLSSensitiveFieldsCodec,
|
||||
]);
|
||||
|
||||
export type HTTPFields = t.TypeOf<typeof HTTPFieldsCodec>;
|
||||
|
||||
export const EncryptedBrowserSimpleFieldsCodec = t.intersection([
|
||||
t.intersection([
|
||||
t.interface({
|
||||
[ConfigKey.METADATA]: MetadataCodec,
|
||||
}),
|
||||
t.partial({
|
||||
[ConfigKey.PLAYWRIGHT_OPTIONS]: t.string,
|
||||
[ConfigKey.TEXT_ASSERTION]: t.string,
|
||||
}),
|
||||
]),
|
||||
CommonFieldsCodec,
|
||||
]);
|
||||
|
||||
export const BrowserSensitiveSimpleFieldsCodec = t.intersection([
|
||||
t.interface({
|
||||
[ConfigKey.SOURCE_INLINE]: t.string,
|
||||
[ConfigKey.SOURCE_PROJECT_CONTENT]: t.string,
|
||||
[ConfigKey.URLS]: t.union([t.string, t.null]),
|
||||
[ConfigKey.PORT]: t.union([t.number, t.null]),
|
||||
}),
|
||||
CommonFieldsCodec,
|
||||
]);
|
||||
|
||||
export const ThrottlingConfigValueCodec = t.interface({
|
||||
download: t.string,
|
||||
upload: t.string,
|
||||
latency: t.string,
|
||||
});
|
||||
|
||||
export type ThrottlingConfigValue = t.TypeOf<typeof ThrottlingConfigValueCodec>;
|
||||
|
||||
export const ThrottlingConfigCodec = t.interface({
|
||||
value: t.union([ThrottlingConfigValueCodec, t.null]),
|
||||
label: t.string,
|
||||
id: t.string,
|
||||
});
|
||||
|
||||
export type ThrottlingConfig = t.TypeOf<typeof ThrottlingConfigCodec>;
|
||||
|
||||
export const EncryptedBrowserAdvancedFieldsCodec = t.interface({
|
||||
[ConfigKey.SCREENSHOTS]: t.string,
|
||||
[ConfigKey.JOURNEY_FILTERS_MATCH]: t.string,
|
||||
[ConfigKey.JOURNEY_FILTERS_TAGS]: t.array(t.string),
|
||||
[ConfigKey.IGNORE_HTTPS_ERRORS]: t.boolean,
|
||||
[ConfigKey.THROTTLING_CONFIG]: ThrottlingConfigCodec,
|
||||
});
|
||||
|
||||
export const BrowserSimpleFieldsCodec = t.intersection([
|
||||
EncryptedBrowserSimpleFieldsCodec,
|
||||
BrowserSensitiveSimpleFieldsCodec,
|
||||
]);
|
||||
|
||||
export const BrowserSensitiveAdvancedFieldsCodec = t.interface({
|
||||
[ConfigKey.SYNTHETICS_ARGS]: t.array(t.string),
|
||||
});
|
||||
|
||||
export const BrowserAdvancedFieldsCodec = t.intersection([
|
||||
EncryptedBrowserAdvancedFieldsCodec,
|
||||
BrowserSensitiveAdvancedFieldsCodec,
|
||||
]);
|
||||
|
||||
export const EncryptedBrowserFieldsCodec = t.intersection([
|
||||
EncryptedBrowserSimpleFieldsCodec,
|
||||
EncryptedBrowserAdvancedFieldsCodec,
|
||||
TLSFieldsCodec,
|
||||
]);
|
||||
|
||||
export const BrowserFieldsCodec = t.intersection([
|
||||
BrowserSimpleFieldsCodec,
|
||||
BrowserAdvancedFieldsCodec,
|
||||
TLSCodec,
|
||||
]);
|
||||
|
||||
export type BrowserFields = t.TypeOf<typeof BrowserFieldsCodec>;
|
||||
export type BrowserSimpleFields = t.TypeOf<typeof BrowserSimpleFieldsCodec>;
|
||||
export type BrowserAdvancedFields = t.TypeOf<typeof BrowserAdvancedFieldsCodec>;
|
||||
|
||||
// MonitorFields, represents any possible monitor type
|
||||
export const MonitorFieldsCodec = t.intersection([
|
||||
HTTPFieldsCodec,
|
||||
TCPFieldsCodec,
|
||||
ICMPSimpleFieldsCodec,
|
||||
BrowserFieldsCodec,
|
||||
]);
|
||||
|
||||
export type MonitorFields = t.TypeOf<typeof MonitorFieldsCodec>;
|
||||
|
||||
// Monitor, represents one of (Icmp | Tcp | Http | Browser)
|
||||
export const SyntheticsMonitorCodec = t.union([
|
||||
HTTPFieldsCodec,
|
||||
TCPFieldsCodec,
|
||||
ICMPSimpleFieldsCodec,
|
||||
BrowserFieldsCodec,
|
||||
]);
|
||||
|
||||
export const EncryptedSyntheticsMonitorCodec = t.union([
|
||||
EncryptedHTTPFieldsCodec,
|
||||
EncryptedTCPFieldsCodec,
|
||||
ICMPSimpleFieldsCodec,
|
||||
EncryptedBrowserFieldsCodec,
|
||||
]);
|
||||
|
||||
export type SyntheticsMonitor = t.TypeOf<typeof SyntheticsMonitorCodec>;
|
||||
|
||||
export const SyntheticsMonitorWithIdCodec = t.intersection([
|
||||
SyntheticsMonitorCodec,
|
||||
t.interface({ id: t.string }),
|
||||
]);
|
||||
|
||||
export const HeartbeatConfigCodec = t.intersection([
|
||||
SyntheticsMonitorWithIdCodec,
|
||||
t.partial({
|
||||
fields_under_root: t.boolean,
|
||||
fields: t.intersection([
|
||||
t.interface({
|
||||
config_id: t.string,
|
||||
}),
|
||||
t.partial({
|
||||
run_once: t.boolean,
|
||||
test_run_id: t.string,
|
||||
'monitor.project.name': t.string,
|
||||
'monitor.project.id': t.string,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
]);
|
||||
|
||||
export const EncryptedSyntheticsSavedMonitorCodec = t.intersection([
|
||||
EncryptedSyntheticsMonitorCodec,
|
||||
t.interface({ id: t.string, updated_at: t.string, created_at: t.string }),
|
||||
]);
|
||||
|
||||
export type SyntheticsMonitorWithId = t.TypeOf<typeof SyntheticsMonitorWithIdCodec>;
|
||||
|
||||
export type EncryptedSyntheticsSavedMonitor = t.TypeOf<typeof EncryptedSyntheticsSavedMonitorCodec>;
|
||||
|
||||
export type HeartbeatConfig = t.TypeOf<typeof HeartbeatConfigCodec>;
|
||||
|
||||
export const MonitorDefaultsCodec = t.interface({
|
||||
[DataStream.HTTP]: HTTPFieldsCodec,
|
||||
[DataStream.TCP]: TCPFieldsCodec,
|
||||
[DataStream.ICMP]: ICMPSimpleFieldsCodec,
|
||||
[DataStream.BROWSER]: BrowserFieldsCodec,
|
||||
});
|
||||
|
||||
export type MonitorDefaults = t.TypeOf<typeof MonitorDefaultsCodec>;
|
||||
|
||||
export const MonitorManagementListResultCodec = t.type({
|
||||
monitors: t.array(EncryptedSyntheticsSavedMonitorCodec),
|
||||
page: t.number,
|
||||
perPage: t.number,
|
||||
total: t.union([t.number, t.null]),
|
||||
absoluteTotal: t.union([t.number, t.null]),
|
||||
syncErrors: t.union([ServiceLocationErrors, t.null]),
|
||||
});
|
||||
|
||||
export type MonitorManagementListResult = t.TypeOf<typeof MonitorManagementListResultCodec>;
|
||||
|
||||
export const MonitorOverviewItemCodec = t.intersection([
|
||||
t.interface({
|
||||
name: t.string,
|
||||
id: t.string,
|
||||
configId: t.string,
|
||||
location: MonitorServiceLocationCodec,
|
||||
isEnabled: t.boolean,
|
||||
isStatusAlertEnabled: t.boolean,
|
||||
type: t.string,
|
||||
tags: t.array(t.string),
|
||||
}),
|
||||
t.partial({
|
||||
projectId: t.string,
|
||||
}),
|
||||
]);
|
||||
|
||||
export type MonitorOverviewItem = t.TypeOf<typeof MonitorOverviewItemCodec>;
|
||||
|
||||
export const MonitorOverviewResultCodec = t.type({
|
||||
total: t.number,
|
||||
allMonitorIds: t.array(t.string),
|
||||
monitors: t.array(MonitorOverviewItemCodec),
|
||||
});
|
||||
|
||||
export type MonitorOverviewResult = t.TypeOf<typeof MonitorOverviewResultCodec>;
|
||||
|
||||
export const SyntheticsMonitorWithSecretsCodec = t.intersection([
|
||||
EncryptedSyntheticsMonitorCodec,
|
||||
t.interface({
|
||||
secrets: t.string,
|
||||
}),
|
||||
]);
|
||||
|
||||
export type Secret = typeof secretKeys[number];
|
||||
|
||||
export type SyntheticsMonitorWithSecrets = Omit<
|
||||
t.TypeOf<typeof SyntheticsMonitorWithSecretsCodec>,
|
||||
Secret
|
||||
>;
|
||||
|
||||
export type EncryptedSyntheticsMonitor = Omit<SyntheticsMonitorWithSecrets, 'secrets'>;
|
|
@ -1,88 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
import { AlertConfigsCodec } from './alert_config';
|
||||
import { ScreenshotOptionCodec } from './monitor_configs';
|
||||
|
||||
export const ProjectMonitorThrottlingConfigCodec = t.union([
|
||||
t.interface({
|
||||
download: t.number,
|
||||
upload: t.number,
|
||||
latency: t.number,
|
||||
}),
|
||||
t.boolean,
|
||||
]);
|
||||
|
||||
export const ProjectMonitorCodec = t.intersection([
|
||||
t.interface({
|
||||
type: t.string,
|
||||
id: t.string,
|
||||
name: t.string,
|
||||
schedule: t.number,
|
||||
}),
|
||||
t.partial({
|
||||
content: t.string,
|
||||
timeout: t.string,
|
||||
privateLocations: t.array(t.string),
|
||||
locations: t.array(t.string),
|
||||
throttling: ProjectMonitorThrottlingConfigCodec,
|
||||
screenshot: ScreenshotOptionCodec,
|
||||
tags: t.union([t.string, t.array(t.string)]),
|
||||
ignoreHTTPSErrors: t.boolean,
|
||||
playwrightOptions: t.record(t.string, t.unknown),
|
||||
filter: t.interface({
|
||||
match: t.string,
|
||||
}),
|
||||
params: t.record(t.string, t.unknown),
|
||||
enabled: t.boolean,
|
||||
alert: AlertConfigsCodec,
|
||||
urls: t.union([t.string, t.array(t.string)]),
|
||||
hosts: t.union([t.string, t.array(t.string)]),
|
||||
max_redirects: t.string,
|
||||
wait: t.string,
|
||||
hash: t.string,
|
||||
namespace: t.string,
|
||||
}),
|
||||
]);
|
||||
|
||||
export const ProjectMonitorsRequestCodec = t.interface({
|
||||
monitors: t.array(ProjectMonitorCodec),
|
||||
});
|
||||
|
||||
export const LegacyProjectMonitorsRequestCodec = t.interface({
|
||||
project: t.string,
|
||||
keep_stale: t.boolean,
|
||||
monitors: t.array(ProjectMonitorCodec),
|
||||
});
|
||||
|
||||
export const ProjectMonitorMetaDataCodec = t.interface({
|
||||
hash: t.string,
|
||||
journey_id: t.string,
|
||||
});
|
||||
|
||||
export const ProjectMonitorsResponseCodec = t.intersection([
|
||||
t.interface({
|
||||
total: t.number,
|
||||
monitors: t.array(ProjectMonitorMetaDataCodec),
|
||||
}),
|
||||
t.partial({
|
||||
after_key: t.string,
|
||||
}),
|
||||
]);
|
||||
|
||||
export type ProjectMonitorThrottlingConfig = t.TypeOf<typeof ProjectMonitorThrottlingConfigCodec>;
|
||||
|
||||
export type ProjectMonitor = t.TypeOf<typeof ProjectMonitorCodec>;
|
||||
|
||||
export type LegacyProjectMonitorsRequest = t.TypeOf<typeof LegacyProjectMonitorsRequestCodec>;
|
||||
|
||||
export type ProjectMonitorsRequest = t.TypeOf<typeof ProjectMonitorsRequestCodec>;
|
||||
|
||||
export type ProjectMonitorsResponse = t.TypeOf<typeof ProjectMonitorsResponseCodec>;
|
||||
|
||||
export type ProjectMonitorMetaData = t.TypeOf<typeof ProjectMonitorMetaDataCodec>;
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* 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 { schema, TypeOf } from '@kbn/config-schema';
|
||||
import { ConfigKey } from '../../constants/monitor_management';
|
||||
|
||||
export const MonitorSortFieldSchema = schema.maybe(
|
||||
schema.oneOf([
|
||||
schema.literal('enabled'),
|
||||
schema.literal('status'),
|
||||
schema.literal('updated_at'),
|
||||
schema.literal(`${ConfigKey.NAME}.keyword`),
|
||||
schema.literal(`${ConfigKey.TAGS}.keyword`),
|
||||
schema.literal(`${ConfigKey.PROJECT_ID}.keyword`),
|
||||
schema.literal(`${ConfigKey.MONITOR_TYPE}.keyword`),
|
||||
schema.literal(`${ConfigKey.SCHEDULE}.keyword`),
|
||||
schema.literal(ConfigKey.JOURNEY_ID),
|
||||
])
|
||||
);
|
||||
|
||||
export type MonitorListSortField = TypeOf<typeof MonitorSortFieldSchema>;
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
|
||||
export const FetchMonitorManagementListQueryArgsCodec = t.partial({
|
||||
page: t.number,
|
||||
perPage: t.number,
|
||||
sortField: t.string,
|
||||
sortOrder: t.union([t.literal('desc'), t.literal('asc')]),
|
||||
query: t.string,
|
||||
searchFields: t.array(t.string),
|
||||
tags: t.array(t.string),
|
||||
locations: t.array(t.string),
|
||||
monitorTypes: t.array(t.string),
|
||||
projects: t.array(t.string),
|
||||
schedules: t.array(t.string),
|
||||
monitorQueryIds: t.array(t.string),
|
||||
});
|
||||
|
||||
export type FetchMonitorManagementListQueryArgs = t.TypeOf<
|
||||
typeof FetchMonitorManagementListQueryArgsCodec
|
||||
>;
|
||||
|
||||
export const FetchMonitorOverviewQueryArgsCodec = t.partial({
|
||||
query: t.string,
|
||||
searchFields: t.array(t.string),
|
||||
tags: t.array(t.string),
|
||||
locations: t.array(t.string),
|
||||
projects: t.array(t.string),
|
||||
schedules: t.array(t.string),
|
||||
monitorTypes: t.array(t.string),
|
||||
sortField: t.string,
|
||||
sortOrder: t.string,
|
||||
});
|
||||
|
||||
export type FetchMonitorOverviewQueryArgs = t.TypeOf<typeof FetchMonitorOverviewQueryArgsCodec>;
|
||||
|
||||
export const MonitorManagementEnablementResultCodec = t.type({
|
||||
isEnabled: t.boolean,
|
||||
canEnable: t.boolean,
|
||||
canManageApiKeys: t.boolean,
|
||||
areApiKeysEnabled: t.boolean,
|
||||
isValidApiKey: t.boolean,
|
||||
});
|
||||
|
||||
export type MonitorManagementEnablementResult = t.TypeOf<
|
||||
typeof MonitorManagementEnablementResultCodec
|
||||
>;
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
import { ObserverCodec } from '../ping/observer';
|
||||
import { ErrorStateCodec } from '../ping/error_state';
|
||||
import { AgentType, MonitorType, PingErrorType, UrlType } from '..';
|
||||
|
||||
export const OverviewPingCode = t.interface({
|
||||
'@timestamp': t.string,
|
||||
summary: t.partial({
|
||||
down: t.number,
|
||||
up: t.number,
|
||||
}),
|
||||
monitor: MonitorType,
|
||||
observer: ObserverCodec,
|
||||
config_id: t.string,
|
||||
error: PingErrorType,
|
||||
agent: AgentType,
|
||||
url: UrlType,
|
||||
state: ErrorStateCodec,
|
||||
});
|
||||
|
||||
export const OverviewStatusMetaDataCodec = t.interface({
|
||||
monitorQueryId: t.string,
|
||||
configId: t.string,
|
||||
status: t.string,
|
||||
location: t.string,
|
||||
timestamp: t.string,
|
||||
ping: OverviewPingCode,
|
||||
});
|
||||
|
||||
export const OverviewPendingStatusMetaDataCodec = t.intersection([
|
||||
t.interface({
|
||||
monitorQueryId: t.string,
|
||||
configId: t.string,
|
||||
status: t.string,
|
||||
location: t.string,
|
||||
}),
|
||||
t.partial({
|
||||
timestamp: t.string,
|
||||
ping: OverviewPingCode,
|
||||
}),
|
||||
]);
|
||||
|
||||
export const OverviewStatusCodec = t.interface({
|
||||
allMonitorsCount: t.number,
|
||||
disabledMonitorsCount: t.number,
|
||||
projectMonitorsCount: t.number,
|
||||
up: t.number,
|
||||
down: t.number,
|
||||
pending: t.number,
|
||||
disabledCount: t.number,
|
||||
upConfigs: t.record(t.string, OverviewStatusMetaDataCodec),
|
||||
downConfigs: t.record(t.string, OverviewStatusMetaDataCodec),
|
||||
pendingConfigs: t.record(t.string, OverviewPendingStatusMetaDataCodec),
|
||||
enabledMonitorQueryIds: t.array(t.string),
|
||||
disabledMonitorQueryIds: t.array(t.string),
|
||||
allIds: t.array(t.string),
|
||||
});
|
||||
|
||||
export const OverviewStatusStateCodec = t.intersection([
|
||||
OverviewStatusCodec,
|
||||
t.interface({
|
||||
allConfigs: t.record(t.string, OverviewStatusMetaDataCodec),
|
||||
}),
|
||||
]);
|
||||
|
||||
export type OverviewPing = t.TypeOf<typeof OverviewPingCode>;
|
||||
export type OverviewStatus = t.TypeOf<typeof OverviewStatusCodec>;
|
||||
export type OverviewStatusState = t.TypeOf<typeof OverviewStatusStateCodec>;
|
||||
export type OverviewStatusMetaData = t.TypeOf<typeof OverviewStatusMetaDataCodec>;
|
||||
export type OverviewPendingStatusMetaData = t.TypeOf<typeof OverviewPendingStatusMetaDataCodec>;
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
|
||||
export const SyntheticsParamSOCodec = t.intersection([
|
||||
t.interface({
|
||||
key: t.string,
|
||||
value: t.string,
|
||||
}),
|
||||
t.partial({
|
||||
description: t.string,
|
||||
tags: t.array(t.string),
|
||||
namespaces: t.array(t.string),
|
||||
}),
|
||||
]);
|
||||
|
||||
export type SyntheticsParamSO = t.TypeOf<typeof SyntheticsParamSOCodec>;
|
||||
|
||||
export const SyntheticsParamRequestCodec = t.intersection([
|
||||
t.interface({
|
||||
key: t.string,
|
||||
value: t.string,
|
||||
}),
|
||||
t.partial({
|
||||
description: t.string,
|
||||
tags: t.array(t.string),
|
||||
share_across_spaces: t.boolean,
|
||||
}),
|
||||
]);
|
||||
|
||||
export type SyntheticsParamRequest = t.TypeOf<typeof SyntheticsParamRequestCodec>;
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
|
||||
export const PrivateLocationCodec = t.intersection([
|
||||
t.interface({
|
||||
label: t.string,
|
||||
id: t.string,
|
||||
agentPolicyId: t.string,
|
||||
concurrentMonitors: t.number,
|
||||
}),
|
||||
t.partial({
|
||||
isServiceManaged: t.boolean,
|
||||
isInvalid: t.boolean,
|
||||
tags: t.array(t.string),
|
||||
/* Empty Lat lon was accidentally saved as an empty string instead of undefined or null
|
||||
* Need a migration to fix */
|
||||
geo: t.interface({ lat: t.union([t.string, t.number]), lon: t.union([t.string, t.number]) }),
|
||||
}),
|
||||
]);
|
||||
|
||||
export const SyntheticsPrivateLocationsType = t.type({
|
||||
locations: t.array(PrivateLocationCodec),
|
||||
});
|
||||
export type PrivateLocation = t.TypeOf<typeof PrivateLocationCodec>;
|
||||
export type SyntheticsPrivateLocations = t.TypeOf<typeof SyntheticsPrivateLocationsType>;
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* 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 * as t from 'io-ts';
|
||||
|
||||
export const SyntheticsServiceApiKeyType = t.type({
|
||||
id: t.string,
|
||||
name: t.string,
|
||||
apiKey: t.string,
|
||||
});
|
||||
|
||||
export const SyntheticsServiceApiKeySaveType = t.intersection([
|
||||
t.type({
|
||||
success: t.boolean,
|
||||
}),
|
||||
t.partial({
|
||||
error: t.string,
|
||||
}),
|
||||
]);
|
||||
|
||||
export type SyntheticsServiceApiKey = t.TypeOf<typeof SyntheticsServiceApiKeyType>;
|
||||
export type SyntheticsServiceApiKeySaveResponse = t.TypeOf<typeof SyntheticsServiceApiKeySaveType>;
|
|
@ -1,9 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export const privateLocationsSavedObjectId = 'synthetics-privates-locations-singleton';
|
||||
export const privateLocationsSavedObjectName = 'synthetics-privates-locations';
|
|
@ -7,5 +7,4 @@
|
|||
|
||||
export * from './monitor_duration';
|
||||
export * from './synthetics_monitor';
|
||||
export * from './monitor_validation';
|
||||
export * from './integration_deprecation';
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* 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 { ConfigKey, MonitorFields, ThrottlingConfig } from '../runtime_types';
|
||||
|
||||
export type Validator = (config: Partial<MonitorFields & ThrottlingConfig>) => boolean;
|
||||
export type NamespaceValidator = (
|
||||
config: Partial<MonitorFields & ThrottlingConfig>
|
||||
) => false | string;
|
||||
|
||||
export type ConfigValidation = Omit<Record<ConfigKey, Validator>, ConfigKey.NAMESPACE> &
|
||||
Record<ConfigKey.NAMESPACE, NamespaceValidator>;
|
||||
|
||||
export type Validation = Partial<ConfigValidation>;
|
|
@ -1,11 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export const syntheticsMonitorType = 'synthetics-monitor';
|
||||
export const monitorAttributes = `${syntheticsMonitorType}.attributes`;
|
||||
|
||||
export const syntheticsParamType = 'synthetics-param';
|
|
@ -5,28 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import type { SimpleSavedObject } from '@kbn/core/public';
|
||||
import {
|
||||
Locations,
|
||||
MonitorFields,
|
||||
ServiceLocationErrors,
|
||||
SyntheticsMonitor,
|
||||
SyntheticsMonitorSchedule,
|
||||
} from '../runtime_types';
|
||||
|
||||
export interface MonitorIdParam {
|
||||
monitorId: string;
|
||||
}
|
||||
|
||||
export type DecryptedSyntheticsMonitorSavedObject = SimpleSavedObject<SyntheticsMonitor> & {
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
export interface TestNowResponse {
|
||||
schedule: SyntheticsMonitorSchedule;
|
||||
locations: Locations;
|
||||
errors?: ServiceLocationErrors;
|
||||
testRunId: string;
|
||||
configId: string;
|
||||
monitor: MonitorFields;
|
||||
}
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* 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 { format } from './get_monitor_url';
|
||||
|
||||
export const getSyntheticsErrorRouteFromMonitorId = ({
|
||||
configId,
|
||||
stateId,
|
||||
locationId,
|
||||
}: {
|
||||
stateId: string;
|
||||
configId: string;
|
||||
locationId: string;
|
||||
}) =>
|
||||
format({
|
||||
pathname: encodeURI(`/app/synthetics/monitor/${configId}/errors/${stateId}`),
|
||||
query: {
|
||||
locationId,
|
||||
},
|
||||
});
|
|
@ -1,17 +0,0 @@
|
|||
/*
|
||||
* 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 { PrivateLocation, ServiceLocation } from '../runtime_types';
|
||||
|
||||
export const formatLocation = (location: ServiceLocation | PrivateLocation) => {
|
||||
return {
|
||||
id: location.id,
|
||||
label: location.label,
|
||||
geo: location.geo,
|
||||
isServiceManaged: location.isServiceManaged,
|
||||
};
|
||||
};
|
|
@ -12,9 +12,14 @@ import { EuiButton, EuiCallOut } from '@elastic/eui';
|
|||
import type { PackagePolicyEditExtensionComponentProps } from '@kbn/fleet-plugin/public';
|
||||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import { useEditMonitorLocator } from './use_edit_monitor_locator';
|
||||
import { DataStream } from '../../../../common/runtime_types';
|
||||
import { DeprecateNoticeModal } from './deprecate_notice_modal';
|
||||
|
||||
enum DataStream {
|
||||
HTTP = 'http',
|
||||
TCP = 'tcp',
|
||||
ICMP = 'icmp',
|
||||
BROWSER = 'browser',
|
||||
}
|
||||
/**
|
||||
* Exports Synthetics-specific package policy instructions
|
||||
* for use in the Ingest app create / edit package policy
|
||||
|
|
|
@ -96,7 +96,6 @@ export const createAlert = async ({
|
|||
defaultSubjectMessage: MonitorStatusTranslations.defaultSubjectMessage,
|
||||
defaultRecoverySubjectMessage: MonitorStatusTranslations.defaultRecoverySubjectMessage,
|
||||
},
|
||||
isLegacy: true,
|
||||
});
|
||||
|
||||
const data: NewMonitorStatusAlert = {
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { SYNTHETICS_API_URLS } from '../../../../common/constants';
|
||||
import { API_URLS } from '../../../../common/constants';
|
||||
import { SyntheticsHasIntegrationMonitorsResponse } from '../../../../common/types/integration_deprecation';
|
||||
import { apiService } from './utils';
|
||||
|
||||
export const getHasIntegrationMonitors =
|
||||
async (): Promise<SyntheticsHasIntegrationMonitorsResponse> => {
|
||||
return await apiService.get(SYNTHETICS_API_URLS.SYNTHETICS_HAS_INTEGRATION_MONITORS);
|
||||
return await apiService.get(API_URLS.SYNTHETICS_HAS_INTEGRATION_MONITORS);
|
||||
};
|
||||
|
|
|
@ -6,14 +6,7 @@
|
|||
*/
|
||||
|
||||
import { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';
|
||||
import type {
|
||||
SavedObjectsClientContract,
|
||||
IScopedClusterClient,
|
||||
Logger,
|
||||
IBasePath,
|
||||
CoreStart,
|
||||
} from '@kbn/core/server';
|
||||
import type { TelemetryPluginSetup, TelemetryPluginStart } from '@kbn/telemetry-plugin/server';
|
||||
import type { SavedObjectsClientContract, IScopedClusterClient, IBasePath } from '@kbn/core/server';
|
||||
import { ObservabilityPluginSetup } from '@kbn/observability-plugin/server';
|
||||
import {
|
||||
EncryptedSavedObjectsPluginSetup,
|
||||
|
@ -33,8 +26,6 @@ import { FleetStartContract } from '@kbn/fleet-plugin/server';
|
|||
import { BfetchServerSetup } from '@kbn/bfetch-plugin/server';
|
||||
import { SharePluginSetup } from '@kbn/share-plugin/server';
|
||||
import { UptimeEsClient } from '../../lib';
|
||||
import type { TelemetryEventsSender } from '../../telemetry/sender';
|
||||
import type { UptimeRouter } from '../../../../types';
|
||||
import { UptimeConfig } from '../../../../../common/config';
|
||||
|
||||
export type UMElasticsearchQueryFnParams<P> = {
|
||||
|
@ -52,23 +43,10 @@ export type UMSavedObjectsQueryFn<T = any, P = undefined> = (
|
|||
) => Promise<T> | T;
|
||||
|
||||
export interface UptimeServerSetup {
|
||||
router: UptimeRouter;
|
||||
config: UptimeConfig;
|
||||
cloud?: CloudSetup;
|
||||
spaces?: SpacesPluginStart;
|
||||
fleet: FleetStartContract;
|
||||
security: SecurityPluginStart;
|
||||
savedObjectsClient?: SavedObjectsClientContract;
|
||||
authSavedObjectsClient?: SavedObjectsClientContract;
|
||||
encryptedSavedObjects: EncryptedSavedObjectsPluginStart;
|
||||
share: SharePluginSetup;
|
||||
stackVersion: string;
|
||||
logger: Logger;
|
||||
telemetry: TelemetryEventsSender;
|
||||
uptimeEsClient: UptimeEsClient;
|
||||
basePath: IBasePath;
|
||||
isDev?: boolean;
|
||||
coreStart: CoreStart;
|
||||
}
|
||||
|
||||
export interface UptimeCorePluginsSetup {
|
||||
|
@ -81,7 +59,6 @@ export interface UptimeCorePluginsSetup {
|
|||
ruleRegistry: RuleRegistryPluginSetupContract;
|
||||
encryptedSavedObjects: EncryptedSavedObjectsPluginSetup;
|
||||
taskManager: TaskManagerSetupContract;
|
||||
telemetry: TelemetryPluginSetup;
|
||||
bfetch: BfetchServerSetup;
|
||||
share: SharePluginSetup;
|
||||
}
|
||||
|
@ -91,6 +68,5 @@ export interface UptimeCorePluginsStart {
|
|||
fleet: FleetStartContract;
|
||||
encryptedSavedObjects: EncryptedSavedObjectsPluginStart;
|
||||
taskManager: TaskManagerStartContract;
|
||||
telemetry: TelemetryPluginStart;
|
||||
spaces?: SpacesPluginStart;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import {
|
|||
StatusCheckFilters,
|
||||
Ping,
|
||||
GetMonitorAvailabilityParams,
|
||||
OverviewPing,
|
||||
} from '../../../../common/runtime_types';
|
||||
import { CLIENT_ALERT_TYPES, MONITOR_STATUS } from '../../../../common/constants/uptime_alerts';
|
||||
import {
|
||||
|
@ -242,7 +241,7 @@ export const getStatusMessage = (
|
|||
return statusMessage + availabilityMessage;
|
||||
};
|
||||
|
||||
export const getInstanceId = (monitorInfo: Ping | OverviewPing, monIdByLoc: string) => {
|
||||
export const getInstanceId = (monitorInfo: Ping, monIdByLoc: string) => {
|
||||
const normalizeText = (txt: string) => {
|
||||
// replace url and name special characters with -
|
||||
return txt.replace(/[^A-Z0-9]+/gi, '_').toLowerCase();
|
||||
|
|
|
@ -14,7 +14,6 @@ import { LocatorPublic } from '@kbn/share-plugin/common';
|
|||
import { SharePluginSetup } from '@kbn/share-plugin/server';
|
||||
import { UMServerLibs } from '../../lib';
|
||||
import { UptimeCorePluginsSetup, UptimeServerSetup } from '../../adapters';
|
||||
import type { UptimeRouter } from '../../../../types';
|
||||
import { getUptimeESMockClient } from '../../requests/test_helpers';
|
||||
|
||||
/**
|
||||
|
@ -28,7 +27,6 @@ export const bootstrapDependencies = (
|
|||
customRequests?: any,
|
||||
customPlugins: any = { observability: { getAlertDetailsConfig: () => ({ uptime: true }) } }
|
||||
) => {
|
||||
const router = {} as UptimeRouter;
|
||||
const basePath = {
|
||||
prepend: (url: string) => {
|
||||
return `/hfe${url}`;
|
||||
|
@ -52,7 +50,6 @@ export const bootstrapDependencies = (
|
|||
// these server/libs parameters don't have any functionality, which is fine
|
||||
// because we aren't testing them here
|
||||
const server = {
|
||||
router,
|
||||
config: {},
|
||||
basePath,
|
||||
share,
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* 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 type { TelemetryEventsSender } from '../sender';
|
||||
|
||||
/**
|
||||
* Creates a mocked Telemetry Events Sender
|
||||
*/
|
||||
export const createMockTelemetryEventsSender = (
|
||||
enableTelemetry?: boolean
|
||||
): jest.Mocked<TelemetryEventsSender> => {
|
||||
return {
|
||||
setup: jest.fn(),
|
||||
start: jest.fn(),
|
||||
stop: jest.fn(),
|
||||
fetchTelemetryUrl: jest.fn(),
|
||||
queueTelemetryEvents: jest.fn(),
|
||||
isTelemetryOptedIn: jest.fn().mockReturnValue(enableTelemetry ?? jest.fn()),
|
||||
sendIfDue: jest.fn(),
|
||||
sendEvents: jest.fn(),
|
||||
} as unknown as jest.Mocked<TelemetryEventsSender>;
|
||||
};
|
|
@ -1,12 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export const MONITOR_UPDATE_CHANNEL = 'synthetics-monitor-update';
|
||||
export const MONITOR_CURRENT_CHANNEL = 'synthetics-monitor-current';
|
||||
export const MONITOR_ERROR_EVENTS_CHANNEL = 'synthetics-monitor-error-events';
|
||||
export const MONITOR_SYNC_STATE_CHANNEL = 'synthetics-monitor-sync-state';
|
||||
export const MONITOR_SYNC_EVENTS_CHANNEL = 'synthetics-monitor-sync-events';
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
/* eslint-disable dot-notation */
|
||||
import { TelemetryQueue } from './queue';
|
||||
|
||||
describe('TelemetryQueue', () => {
|
||||
describe('queueTelemetryEvents', () => {
|
||||
it('queues two events', () => {
|
||||
const queue = new TelemetryQueue();
|
||||
queue.addEvents([{ 'event.kind': '1' }, { 'event.kind': '2' }]);
|
||||
expect(queue['queue'].length).toBe(2);
|
||||
});
|
||||
|
||||
it('queues more than maxQueueSize events', () => {
|
||||
const queue = new TelemetryQueue();
|
||||
queue.addEvents([{ 'event.kind': '1' }, { 'event.kind': '2' }]);
|
||||
queue['maxQueueSize'] = 5;
|
||||
queue.addEvents([{ 'event.kind': '3' }, { 'event.kind': '4' }]);
|
||||
queue.addEvents([{ 'event.kind': '5' }, { 'event.kind': '6' }]);
|
||||
queue.addEvents([{ 'event.kind': '7' }, { 'event.kind': '8' }]);
|
||||
expect(queue['queue'].length).toBe(5);
|
||||
});
|
||||
|
||||
it('get and clear events', async () => {
|
||||
const queue = new TelemetryQueue();
|
||||
queue.addEvents([{ 'event.kind': '1' }, { 'event.kind': '2' }]);
|
||||
|
||||
expect(queue.getEvents().length).toBe(2);
|
||||
|
||||
queue.clearEvents();
|
||||
|
||||
expect(queue['queue'].length).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export const TELEMETRY_MAX_QUEUE_SIZE = 100;
|
||||
|
||||
export class TelemetryQueue<T> {
|
||||
private maxQueueSize = TELEMETRY_MAX_QUEUE_SIZE;
|
||||
private queue: T[] = [];
|
||||
|
||||
public addEvents(events: T[]) {
|
||||
const qlength = this.queue.length;
|
||||
|
||||
if (events.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (qlength >= this.maxQueueSize) {
|
||||
// we're full already
|
||||
return;
|
||||
}
|
||||
|
||||
if (events.length > this.maxQueueSize - qlength) {
|
||||
this.queue.push(...events.slice(0, this.maxQueueSize - qlength));
|
||||
} else {
|
||||
this.queue.push(...events);
|
||||
}
|
||||
}
|
||||
|
||||
public clearEvents() {
|
||||
this.queue = [];
|
||||
}
|
||||
|
||||
public getEvents(): T[] {
|
||||
return this.queue;
|
||||
}
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* eslint-disable dot-notation */
|
||||
|
||||
import { URL } from 'url';
|
||||
|
||||
import axios from 'axios';
|
||||
|
||||
import type { InfoResponse } from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import { loggingSystemMock } from '@kbn/core/server/mocks';
|
||||
|
||||
import { MONITOR_UPDATE_CHANNEL } from './constants';
|
||||
|
||||
import { TelemetryEventsSender } from './sender';
|
||||
import { LicenseGetResponse } from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
jest.mock('axios', () => {
|
||||
return {
|
||||
post: jest.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
const licenseMock: LicenseGetResponse = {
|
||||
license: {
|
||||
status: 'active',
|
||||
uid: '1d34eb9f-e66f-47d1-8d24-cd60d187587a',
|
||||
type: 'trial',
|
||||
issue_date: '2022-05-05T14:25:00.732Z',
|
||||
issue_date_in_millis: 165176070074432,
|
||||
expiry_date: '2022-06-04T14:25:00.732Z',
|
||||
expiry_date_in_millis: 165435270073332,
|
||||
max_nodes: 1000,
|
||||
max_resource_units: null,
|
||||
issued_to: '2c515bd215ce444441f83ffd36a9d3d2546',
|
||||
issuer: 'elasticsearch',
|
||||
start_date_in_millis: -1,
|
||||
},
|
||||
};
|
||||
|
||||
describe('TelemetryEventsSender', () => {
|
||||
let logger: ReturnType<typeof loggingSystemMock.createLogger>;
|
||||
let sender: TelemetryEventsSender;
|
||||
const sampleEvent = {
|
||||
configId: '12345',
|
||||
stackVersion: '8.1.0',
|
||||
type: 'http',
|
||||
locations: ['us_central'],
|
||||
locationsCount: 1,
|
||||
monitorNameLength: 8,
|
||||
monitorInterval: 180000,
|
||||
revision: 1,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
logger = loggingSystemMock.createLogger();
|
||||
sender = new TelemetryEventsSender(logger);
|
||||
sender['fetchLicenseInfo'] = jest.fn(async () => {
|
||||
return licenseMock as LicenseGetResponse;
|
||||
});
|
||||
|
||||
sender['fetchClusterInfo'] = jest.fn(async () => {
|
||||
return {
|
||||
cluster_uuid: '1',
|
||||
cluster_name: 'name',
|
||||
version: {
|
||||
number: '8.0.0',
|
||||
},
|
||||
} as InfoResponse;
|
||||
});
|
||||
sender.start(undefined, {
|
||||
elasticsearch: { client: { asInternalUser: { info: jest.fn(async () => ({})) } } },
|
||||
} as any);
|
||||
});
|
||||
|
||||
describe('queueTelemetryEvents', () => {
|
||||
it('queues two events', () => {
|
||||
sender.queueTelemetryEvents(MONITOR_UPDATE_CHANNEL, [sampleEvent]);
|
||||
expect(sender['queuesPerChannel'][MONITOR_UPDATE_CHANNEL]).toBeDefined();
|
||||
});
|
||||
|
||||
it('should send events when due', async () => {
|
||||
sender['telemetryStart'] = {
|
||||
getIsOptedIn: jest.fn(async () => true),
|
||||
};
|
||||
sender['telemetrySetup'] = {
|
||||
getTelemetryUrl: jest.fn(
|
||||
async () => new URL('https://telemetry-staging.elastic.co/v3/send/snapshot')
|
||||
),
|
||||
};
|
||||
|
||||
sender.queueTelemetryEvents(MONITOR_UPDATE_CHANNEL, [sampleEvent]);
|
||||
sender['sendEvents'] = jest.fn();
|
||||
|
||||
await sender['sendIfDue']();
|
||||
|
||||
expect(sender['sendEvents']).toHaveBeenCalledWith(
|
||||
`https://telemetry-staging.elastic.co/v3-dev/send/${MONITOR_UPDATE_CHANNEL}`,
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
|
||||
it("shouldn't send when telemetry is disabled", async () => {
|
||||
const telemetryStart = {
|
||||
getIsOptedIn: jest.fn(async () => false),
|
||||
};
|
||||
sender['telemetryStart'] = telemetryStart;
|
||||
|
||||
sender.queueTelemetryEvents(MONITOR_UPDATE_CHANNEL, [sampleEvent]);
|
||||
sender['sendEvents'] = jest.fn();
|
||||
|
||||
await sender['sendIfDue']();
|
||||
|
||||
expect(sender['sendEvents']).toBeCalledTimes(0);
|
||||
});
|
||||
|
||||
it('should send events to separate channels', async () => {
|
||||
sender['telemetryStart'] = {
|
||||
getIsOptedIn: jest.fn(async () => true),
|
||||
};
|
||||
sender['telemetrySetup'] = {
|
||||
getTelemetryUrl: jest.fn(
|
||||
async () => new URL('https://telemetry.elastic.co/v3/send/snapshot')
|
||||
),
|
||||
};
|
||||
|
||||
const myChannelEvents = [{ 'event.kind': '1' }, { 'event.kind': '2' }];
|
||||
// @ts-ignore
|
||||
sender.queueTelemetryEvents('my-channel', myChannelEvents);
|
||||
sender['queuesPerChannel']['my-channel']['getEvents'] = jest.fn(() => myChannelEvents);
|
||||
|
||||
expect(sender['queuesPerChannel']['my-channel']['queue'].length).toBe(2);
|
||||
|
||||
const myChannel2Events = [{ 'event.kind': '3' }];
|
||||
// @ts-ignore
|
||||
sender.queueTelemetryEvents('my-channel2', myChannel2Events);
|
||||
sender['queuesPerChannel']['my-channel2']['getEvents'] = jest.fn(() => myChannel2Events);
|
||||
|
||||
expect(sender['queuesPerChannel']['my-channel2']['queue'].length).toBe(1);
|
||||
|
||||
await sender['sendIfDue']();
|
||||
|
||||
expect(sender['queuesPerChannel']['my-channel']['getEvents']).toBeCalledTimes(1);
|
||||
expect(sender['queuesPerChannel']['my-channel2']['getEvents']).toBeCalledTimes(1);
|
||||
const requestConfig = {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-ndjson',
|
||||
'X-Elastic-Cluster-ID': '1',
|
||||
'X-Elastic-Cluster-Name': 'name',
|
||||
'X-Elastic-Stack-Version': '8.0.0',
|
||||
},
|
||||
timeout: 5000,
|
||||
};
|
||||
const event1 = { 'event.kind': '1', ...licenseMock };
|
||||
const event2 = { 'event.kind': '2', ...licenseMock };
|
||||
const event3 = { 'event.kind': '3', ...licenseMock };
|
||||
expect(axios.post).toHaveBeenCalledWith(
|
||||
'https://telemetry.elastic.co/v3/send/my-channel',
|
||||
`${JSON.stringify(event1)}\n${JSON.stringify(event2)}\n`,
|
||||
requestConfig
|
||||
);
|
||||
expect(axios.post).toHaveBeenCalledWith(
|
||||
'https://telemetry.elastic.co/v3/send/my-channel2',
|
||||
`${JSON.stringify(event3)}\n`,
|
||||
requestConfig
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,204 +0,0 @@
|
|||
/*
|
||||
* 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 type { CoreStart, ElasticsearchClient, Logger } from '@kbn/core/server';
|
||||
import type { TelemetryPluginStart, TelemetryPluginSetup } from '@kbn/telemetry-plugin/server';
|
||||
|
||||
import { cloneDeep } from 'lodash';
|
||||
|
||||
import axios from 'axios';
|
||||
|
||||
import type { InfoResponse, LicenseGetResponse } from '@elastic/elasticsearch/lib/api/types';
|
||||
|
||||
import { TelemetryQueue } from './queue';
|
||||
|
||||
import type { MonitorUpdateTelemetryChannel, MonitorUpdateTelemetryChannelEvents } from './types';
|
||||
|
||||
/**
|
||||
* Simplified version of https://github.com/elastic/kibana/blob/master/x-pack/plugins/security_solution/server/lib/telemetry/sender.ts
|
||||
* Sends batched events to telemetry v3 api
|
||||
*/
|
||||
export class TelemetryEventsSender {
|
||||
private readonly initialCheckDelayMs = 10 * 1000;
|
||||
private readonly checkIntervalMs = 30 * 1000;
|
||||
private readonly logger: Logger;
|
||||
|
||||
private telemetryStart?: TelemetryPluginStart;
|
||||
private telemetrySetup?: TelemetryPluginSetup;
|
||||
private intervalId?: NodeJS.Timeout;
|
||||
private isSending = false;
|
||||
private queuesPerChannel: { [channel: string]: TelemetryQueue<any> } = {};
|
||||
private isOptedIn?: boolean = true; // Assume true until the first check
|
||||
private esClient?: ElasticsearchClient;
|
||||
private clusterInfo?: InfoResponse;
|
||||
private licenseInfo?: LicenseGetResponse;
|
||||
|
||||
constructor(logger: Logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public setup(telemetrySetup?: TelemetryPluginSetup) {
|
||||
this.telemetrySetup = telemetrySetup;
|
||||
}
|
||||
|
||||
public async start(telemetryStart?: TelemetryPluginStart, core?: CoreStart) {
|
||||
this.telemetryStart = telemetryStart;
|
||||
this.esClient = core?.elasticsearch.client.asInternalUser;
|
||||
this.clusterInfo = await this.fetchClusterInfo();
|
||||
this.licenseInfo = await this.fetchLicenseInfo();
|
||||
|
||||
this.logger.debug(`Starting local task`);
|
||||
setTimeout(() => {
|
||||
this.sendIfDue();
|
||||
this.intervalId = setInterval(() => this.sendIfDue(), this.checkIntervalMs);
|
||||
}, this.initialCheckDelayMs);
|
||||
}
|
||||
|
||||
public stop() {
|
||||
if (this.intervalId) {
|
||||
clearInterval(this.intervalId);
|
||||
}
|
||||
}
|
||||
|
||||
public queueTelemetryEvents<T extends MonitorUpdateTelemetryChannel>(
|
||||
channel: T,
|
||||
events: Array<MonitorUpdateTelemetryChannelEvents[T]>
|
||||
) {
|
||||
if (!this.queuesPerChannel[channel]) {
|
||||
this.queuesPerChannel[channel] = new TelemetryQueue<MonitorUpdateTelemetryChannelEvents[T]>();
|
||||
}
|
||||
this.queuesPerChannel[channel].addEvents(cloneDeep(events));
|
||||
}
|
||||
|
||||
public async isTelemetryOptedIn() {
|
||||
this.isOptedIn = await this.telemetryStart?.getIsOptedIn();
|
||||
return this.isOptedIn === true;
|
||||
}
|
||||
|
||||
private async sendIfDue() {
|
||||
if (this.isSending) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isSending = true;
|
||||
|
||||
this.isOptedIn = await this.isTelemetryOptedIn();
|
||||
if (!this.isOptedIn) {
|
||||
this.logger.debug(`Telemetry is not opted-in.`);
|
||||
for (const channel of Object.keys(this.queuesPerChannel)) {
|
||||
this.queuesPerChannel[channel].clearEvents();
|
||||
}
|
||||
this.isSending = false;
|
||||
return;
|
||||
}
|
||||
|
||||
for (const channel of Object.keys(this.queuesPerChannel)) {
|
||||
await this.sendEvents(await this.fetchTelemetryUrl(channel), this.queuesPerChannel[channel]);
|
||||
}
|
||||
|
||||
this.isSending = false;
|
||||
}
|
||||
|
||||
private async fetchClusterInfo(): Promise<InfoResponse | undefined> {
|
||||
if (this.esClient === undefined || this.esClient === null) {
|
||||
throw Error('elasticsearch client is unavailable: cannot retrieve cluster information');
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.esClient.info();
|
||||
} catch (e) {
|
||||
this.logger.debug(`Error fetching cluster information: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
private async fetchLicenseInfo() {
|
||||
if (this.esClient === undefined || this.esClient === null) {
|
||||
throw Error('elasticsearch client is unavailable: cannot retrieve license information');
|
||||
}
|
||||
try {
|
||||
return await this.esClient.license.get();
|
||||
} catch (e) {
|
||||
this.logger.debug(`Error fetching license information: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async sendEvents(telemetryUrl: string, queue: TelemetryQueue<any>) {
|
||||
let events = queue.getEvents();
|
||||
if (events.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
events = events.map((event) => ({ ...event, license: this.licenseInfo?.license }));
|
||||
|
||||
try {
|
||||
this.logger.debug(`Telemetry URL: ${telemetryUrl}`);
|
||||
|
||||
queue.clearEvents();
|
||||
|
||||
this.logger.debug(JSON.stringify(events));
|
||||
|
||||
await this.send(events, telemetryUrl);
|
||||
} catch (err) {
|
||||
this.logger.debug(`Error sending telemetry events data: ${err}`);
|
||||
queue.clearEvents();
|
||||
}
|
||||
}
|
||||
|
||||
// Forms URLs like:
|
||||
// https://telemetry.elastic.co/v3/send/my-channel-name or
|
||||
// https://telemetry-staging.elastic.co/v3/send/my-channel-name
|
||||
private async fetchTelemetryUrl(channel: string): Promise<string> {
|
||||
const telemetryUrl = await this.telemetrySetup?.getTelemetryUrl();
|
||||
if (!telemetryUrl) {
|
||||
throw Error("Couldn't get telemetry URL");
|
||||
}
|
||||
if (!telemetryUrl.hostname.includes('staging')) {
|
||||
telemetryUrl.pathname = `/v3/send/${channel}`;
|
||||
} else {
|
||||
telemetryUrl.pathname = `/v3-dev/send/${channel}`;
|
||||
}
|
||||
return telemetryUrl.toString();
|
||||
}
|
||||
|
||||
private async send(events: unknown[], telemetryUrl: string) {
|
||||
const {
|
||||
cluster_name: clusterName,
|
||||
cluster_uuid: clusterUuid,
|
||||
version: clusterVersion,
|
||||
} = this.clusterInfo ?? {};
|
||||
|
||||
// using ndjson so that each line will be wrapped in json envelope on server side
|
||||
// see https://github.com/elastic/infra/blob/master/docs/telemetry/telemetry-next-dataflow.md#json-envelope
|
||||
const ndjson = this.transformDataToNdjson(events);
|
||||
|
||||
try {
|
||||
const resp = await axios.post(telemetryUrl, ndjson, {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-ndjson',
|
||||
...(clusterUuid ? { 'X-Elastic-Cluster-ID': clusterUuid } : undefined),
|
||||
...(clusterName ? { 'X-Elastic-Cluster-Name': clusterName } : undefined),
|
||||
'X-Elastic-Stack-Version': clusterVersion?.number ? clusterVersion.number : '8.2.0',
|
||||
},
|
||||
timeout: 5000,
|
||||
});
|
||||
this.logger.debug(`Events sent!. Response: ${resp.status} ${JSON.stringify(resp.data)}`);
|
||||
} catch (err) {
|
||||
this.logger.debug(
|
||||
`Error sending events: ${err.response.status} ${JSON.stringify(err.response.data)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private transformDataToNdjson = (data: unknown[]): string => {
|
||||
if (data.length !== 0) {
|
||||
const dataString = data.map((dataItem) => JSON.stringify(dataItem)).join('\n');
|
||||
return `${dataString}\n`;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* 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 { ServiceLocationErrors } from '../../../../common/runtime_types/monitor_management';
|
||||
import { MONITOR_ERROR_EVENTS_CHANNEL } from './constants';
|
||||
|
||||
export interface MonitorSyncEvent {
|
||||
total: number;
|
||||
totalTests: number;
|
||||
browserTests24h: number;
|
||||
httpTests24h: number;
|
||||
icmpTests24h: number;
|
||||
tcpTests24h: number;
|
||||
[key: string]: number;
|
||||
}
|
||||
|
||||
export interface MonitorUpdateEvent {
|
||||
updatedAt?: string;
|
||||
lastUpdatedAt?: string;
|
||||
durationSinceLastUpdated?: number;
|
||||
deletedAt?: string;
|
||||
type: string;
|
||||
stackVersion: string;
|
||||
monitorNameLength: number;
|
||||
monitorInterval: number;
|
||||
locations: string[];
|
||||
locationsCount: number;
|
||||
scriptType?: 'inline' | 'recorder' | 'zip' | 'project';
|
||||
revision?: number;
|
||||
errors?: ServiceLocationErrors;
|
||||
configId: string;
|
||||
}
|
||||
|
||||
export interface MonitorErrorEvent {
|
||||
type: string;
|
||||
message: string;
|
||||
reason?: string;
|
||||
code?: string;
|
||||
status?: number;
|
||||
url?: string;
|
||||
stackVersion: string;
|
||||
}
|
||||
|
||||
export interface MonitorUpdateTelemetryChannelEvents {
|
||||
// channel name => event type
|
||||
'synthetics-monitor-update': MonitorUpdateEvent;
|
||||
'synthetics-monitor-current': MonitorUpdateEvent;
|
||||
[MONITOR_ERROR_EVENTS_CHANNEL]: MonitorErrorEvent;
|
||||
'synthetics-monitor-sync-state': MonitorSyncEvent;
|
||||
'synthetics-monitor-sync-events': MonitorSyncEvent;
|
||||
}
|
||||
|
||||
export type MonitorUpdateTelemetryChannel = keyof MonitorUpdateTelemetryChannelEvents;
|
|
@ -9,8 +9,6 @@ import { schema } from '@kbn/config-schema';
|
|||
import { UMServerLibs } from '../../lib/lib';
|
||||
import { UMRestApiRouteFactory } from '../types';
|
||||
import { API_URLS } from '../../../../common/constants';
|
||||
import { ConfigKey, MonitorFields } from '../../../../common/runtime_types';
|
||||
import { syntheticsMonitorType } from '../../../../common/types/saved_objects';
|
||||
|
||||
export const createGetStatusBarRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
|
||||
method: 'GET',
|
||||
|
@ -35,44 +33,5 @@ export const createGetStatusBarRoute: UMRestApiRouteFactory = (libs: UMServerLib
|
|||
if (latestMonitor.docId) {
|
||||
return latestMonitor;
|
||||
}
|
||||
|
||||
if (!server.savedObjectsClient) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const {
|
||||
saved_objects: [monitorSavedObject],
|
||||
} = await savedObjectsClient.find({
|
||||
type: syntheticsMonitorType,
|
||||
perPage: 1,
|
||||
page: 1,
|
||||
filter: `${syntheticsMonitorType}.attributes.${ConfigKey.MONITOR_QUERY_ID}: "${monitorId}"`,
|
||||
});
|
||||
|
||||
if (!monitorSavedObject) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const {
|
||||
[ConfigKey.URLS]: url,
|
||||
[ConfigKey.NAME]: name,
|
||||
[ConfigKey.HOSTS]: host,
|
||||
[ConfigKey.MONITOR_TYPE]: type,
|
||||
} = monitorSavedObject.attributes as Partial<MonitorFields>;
|
||||
|
||||
return {
|
||||
url: {
|
||||
full: url || host,
|
||||
},
|
||||
monitor: {
|
||||
name,
|
||||
type,
|
||||
id: monitorSavedObject.id,
|
||||
},
|
||||
};
|
||||
} catch (e) {
|
||||
server.logger.error(e);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -70,11 +70,6 @@ export type UptimeRoute<ClientContract = unknown> = UMRouteDefinition<
|
|||
export type UMRestApiRouteFactory<ClientContract = unknown> = (
|
||||
libs: UMServerLibs
|
||||
) => UptimeRoute<ClientContract>;
|
||||
export type SyntheticsRestApiRouteFactory<
|
||||
ClientContract = any,
|
||||
QueryParams = Record<string, any>
|
||||
> = (libs: UMServerLibs) => SyntheticsRoute<ClientContract, QueryParams>;
|
||||
export type SyntheticsStreamingRouteFactory = (libs: UMServerLibs) => SyntheticsStreamingRoute;
|
||||
|
||||
/**
|
||||
* Functions of this type accept our internal route format and output a route
|
||||
|
@ -85,12 +80,6 @@ export type UMKibanaRouteWrapper = (
|
|||
server: UptimeServerSetup
|
||||
) => UMKibanaRoute;
|
||||
|
||||
export type SyntheticsRoute<
|
||||
ClientContract = unknown,
|
||||
QueryParams = Record<string, any>
|
||||
> = UMRouteDefinition<SyntheticsRouteHandler<ClientContract, QueryParams>>;
|
||||
export type SyntheticsStreamingRoute = UMRouteDefinition<SyntheticsStreamingRouteHandler>;
|
||||
|
||||
export interface UptimeRouteContext {
|
||||
uptimeEsClient: UptimeEsClient;
|
||||
context: UptimeRequestHandlerContext;
|
||||
|
@ -124,31 +113,3 @@ export interface RouteContext<Query = Record<string, any>> {
|
|||
subject?: Subject<unknown>;
|
||||
spaceId: string;
|
||||
}
|
||||
|
||||
export type SyntheticsRouteHandler<ClientContract = unknown, Query = Record<string, any>> = ({
|
||||
uptimeEsClient,
|
||||
context,
|
||||
request,
|
||||
response,
|
||||
server,
|
||||
savedObjectsClient,
|
||||
subject: Subject,
|
||||
}: RouteContext<Query>) => Promise<IKibanaResponse<ClientContract> | ClientContract>;
|
||||
|
||||
export type SyntheticsStreamingRouteHandler = ({
|
||||
uptimeEsClient,
|
||||
context,
|
||||
request,
|
||||
server,
|
||||
savedObjectsClient,
|
||||
subject: Subject,
|
||||
spaceId,
|
||||
}: {
|
||||
uptimeEsClient: UptimeEsClient;
|
||||
context: UptimeRequestHandlerContext;
|
||||
request: SyntheticsRequest;
|
||||
savedObjectsClient: SavedObjectsClientContract;
|
||||
server: UptimeServerSetup;
|
||||
subject?: Subject<unknown>;
|
||||
spaceId: string;
|
||||
}) => IKibanaResponse<any> | Promise<IKibanaResponse<any>>;
|
||||
|
|
|
@ -18,8 +18,6 @@ export const uptimeRouteWrapper: UMKibanaRouteWrapper = (uptimeRoute, server) =>
|
|||
const coreContext = await context.core;
|
||||
const { client: esClient } = coreContext.elasticsearch;
|
||||
|
||||
server.authSavedObjectsClient = coreContext.savedObjects.client;
|
||||
|
||||
const uptimeEsClient = new UptimeEsClient(
|
||||
coreContext.savedObjects.client,
|
||||
esClient.asCurrentUser,
|
||||
|
@ -30,7 +28,6 @@ export const uptimeRouteWrapper: UMKibanaRouteWrapper = (uptimeRoute, server) =>
|
|||
}
|
||||
);
|
||||
|
||||
server.uptimeEsClient = uptimeEsClient;
|
||||
const res = await uptimeRoute.handler({
|
||||
uptimeEsClient,
|
||||
savedObjectsClient: coreContext.savedObjects.client,
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
import { Logger } from '@kbn/core/server';
|
||||
import { createLifecycleRuleTypeFactory, IRuleDataClient } from '@kbn/rule-registry-plugin/server';
|
||||
import { UptimeRouter } from '../types';
|
||||
import { uptimeRequests } from './lib/requests';
|
||||
import { createRouteWithAuth, legacyUptimeRestApiRoutes, uptimeRouteWrapper } from './routes';
|
||||
import { UptimeServerSetup, UptimeCorePluginsSetup } from './lib/adapters';
|
||||
|
@ -28,7 +29,8 @@ export const initUptimeServer = (
|
|||
server: UptimeServerSetup,
|
||||
plugins: UptimeCorePluginsSetup,
|
||||
ruleDataClient: IRuleDataClient,
|
||||
logger: Logger
|
||||
logger: Logger,
|
||||
router: UptimeRouter
|
||||
) => {
|
||||
legacyUptimeRestApiRoutes.forEach((route) => {
|
||||
const { method, options, handler, validate, path } = uptimeRouteWrapper(
|
||||
|
@ -44,16 +46,16 @@ export const initUptimeServer = (
|
|||
|
||||
switch (method) {
|
||||
case 'GET':
|
||||
server.router.get(routeDefinition, handler);
|
||||
router.get(routeDefinition, handler);
|
||||
break;
|
||||
case 'POST':
|
||||
server.router.post(routeDefinition, handler);
|
||||
router.post(routeDefinition, handler);
|
||||
break;
|
||||
case 'PUT':
|
||||
server.router.put(routeDefinition, handler);
|
||||
router.put(routeDefinition, handler);
|
||||
break;
|
||||
case 'DELETE':
|
||||
server.router.delete(routeDefinition, handler);
|
||||
router.delete(routeDefinition, handler);
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Handler for method ${method} is not defined`);
|
||||
|
|
|
@ -19,7 +19,6 @@ import {
|
|||
UptimeCorePluginsStart,
|
||||
UptimeServerSetup,
|
||||
} from './legacy_uptime/lib/adapters';
|
||||
import { TelemetryEventsSender } from './legacy_uptime/lib/telemetry/sender';
|
||||
import {
|
||||
registerUptimeSavedObjects,
|
||||
savedObjectsAdapter,
|
||||
|
@ -28,18 +27,14 @@ import { UptimeConfig } from '../common/config';
|
|||
import { SYNTHETICS_RULE_TYPES_ALERT_CONTEXT } from '../common/constants/synthetics_alerts';
|
||||
import { uptimeRuleTypeFieldMap } from './legacy_uptime/lib/alerts/common';
|
||||
|
||||
export type UptimeRuleRegistry = ReturnType<Plugin['setup']>['ruleRegistry'];
|
||||
|
||||
export class Plugin implements PluginType {
|
||||
private initContext: PluginInitializerContext;
|
||||
private logger: Logger;
|
||||
private server?: UptimeServerSetup;
|
||||
private readonly telemetryEventsSender: TelemetryEventsSender;
|
||||
|
||||
constructor(initializerContext: PluginInitializerContext<UptimeConfig>) {
|
||||
this.initContext = initializerContext;
|
||||
this.logger = initializerContext.logger.get();
|
||||
this.telemetryEventsSender = new TelemetryEventsSender(this.logger);
|
||||
}
|
||||
|
||||
public setup(core: CoreSetup, plugins: UptimeCorePluginsSetup) {
|
||||
|
@ -65,19 +60,12 @@ export class Plugin implements PluginType {
|
|||
|
||||
this.server = {
|
||||
config,
|
||||
router: core.http.createRouter(),
|
||||
cloud: plugins.cloud,
|
||||
stackVersion: this.initContext.env.packageInfo.version,
|
||||
basePath: core.http.basePath,
|
||||
logger: this.logger,
|
||||
telemetry: this.telemetryEventsSender,
|
||||
isDev: this.initContext.env.mode.dev,
|
||||
share: plugins.share,
|
||||
} as UptimeServerSetup;
|
||||
};
|
||||
|
||||
this.telemetryEventsSender.setup(plugins.telemetry);
|
||||
|
||||
initUptimeServer(this.server, plugins, ruleDataClient, this.logger);
|
||||
initUptimeServer(this.server, plugins, ruleDataClient, this.logger, core.http.createRouter());
|
||||
|
||||
registerUptimeSavedObjects(core.savedObjects);
|
||||
|
||||
|
|
|
@ -55,7 +55,6 @@
|
|||
"@kbn/core-doc-links-browser",
|
||||
"@kbn/usage-collection-plugin",
|
||||
"@kbn/core-application-browser",
|
||||
"@kbn/telemetry-plugin",
|
||||
"@kbn/encrypted-saved-objects-plugin",
|
||||
"@kbn/task-manager-plugin",
|
||||
"@kbn/features-plugin",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue