[8.11] [Synthetics] Advanced fields broken for icmp monitors (#171161) (#171335)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[Synthetics] Advanced fields broken for icmp monitors
(#171161)](https://github.com/elastic/kibana/pull/171161)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2023-11-15T17:12:15Z","message":"[Synthetics]
Advanced fields broken for icmp monitors
(#171161)","sha":"b356231d02f65afded09f1c9a44bf0218738e1ac","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:uptime","backport:prev-minor","v8.12.0"],"number":171161,"url":"https://github.com/elastic/kibana/pull/171161","mergeCommit":{"message":"[Synthetics]
Advanced fields broken for icmp monitors
(#171161)","sha":"b356231d02f65afded09f1c9a44bf0218738e1ac"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/171161","number":171161,"mergeCommit":{"message":"[Synthetics]
Advanced fields broken for icmp monitors
(#171161)","sha":"b356231d02f65afded09f1c9a44bf0218738e1ac"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
This commit is contained in:
Kibana Machine 2023-11-15 13:31:14 -05:00 committed by GitHub
parent 03bdf83b7b
commit 5dbb0c4a3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,23 +18,23 @@ import {
DataStream,
DataStreamCodec,
HTTPFieldsCodec,
ICMPSimpleFieldsCodec,
MonitorFields,
TCPFieldsCodec,
SyntheticsMonitor,
Locations,
ICMPFieldsCodec,
} from '../../../common/runtime_types';
import { ALLOWED_SCHEDULES_IN_MINUTES } from '../../../common/constants/monitor_defaults';
type MonitorCodecType =
| typeof ICMPSimpleFieldsCodec
| typeof ICMPFieldsCodec
| typeof TCPFieldsCodec
| typeof HTTPFieldsCodec
| typeof BrowserFieldsCodec;
const monitorTypeToCodecMap: Record<DataStream, MonitorCodecType> = {
[DataStream.ICMP]: ICMPSimpleFieldsCodec,
[DataStream.ICMP]: ICMPFieldsCodec,
[DataStream.TCP]: TCPFieldsCodec,
[DataStream.HTTP]: HTTPFieldsCodec,
[DataStream.BROWSER]: BrowserFieldsCodec,
@ -67,7 +67,7 @@ export function validateMonitor(monitorFields: MonitorFields): ValidationResult
}
// Cast it to ICMPCodec to satisfy typing. During runtime, correct codec will be used to decode.
const SyntheticsMonitorCodec = monitorTypeToCodecMap[monitorType] as typeof ICMPSimpleFieldsCodec;
const SyntheticsMonitorCodec = monitorTypeToCodecMap[monitorType] as typeof ICMPFieldsCodec;
if (!SyntheticsMonitorCodec) {
return {