From 99b86071ccc246739865c6fa172149245e6ab332 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Sat, 2 Nov 2024 01:39:27 +1100 Subject: [PATCH] [8.x] [Synthetics] Added error track trace to status/tls rule context variable !! (#198599) (#198672) # Backport This will backport the following commits from `main` to `8.x`: - [[Synthetics] Added error track trace to status/tls rule context variable !! (#198599)](https://github.com/elastic/kibana/pull/198599) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Shahzad --- .../generated/observability_uptime_schema.ts | 1 + .../alert_as_data_fields.test.ts.snap | 20 +++++++++++++++++++ .../synthetics/common/field_names.ts | 1 + .../common/requests/get_certs_request_body.ts | 3 ++- .../common/rules/synthetics_rule_field_map.ts | 4 ++++ .../synthetics/common/runtime_types/certs.ts | 1 + .../alert_rules/status_rule/message_utils.ts | 7 ++++++- .../server/alert_rules/status_rule/types.ts | 1 + .../alert_rules/tls_rule/message_utils.ts | 4 ++++ .../server/alert_rules/translations.ts | 9 +++++++++ .../common/rules/uptime_rule_field_map.ts | 4 ++++ 11 files changed, 53 insertions(+), 2 deletions(-) diff --git a/packages/kbn-alerts-as-data-utils/src/schemas/generated/observability_uptime_schema.ts b/packages/kbn-alerts-as-data-utils/src/schemas/generated/observability_uptime_schema.ts index 8770b70402d08..bf37ffc1ddb9c 100644 --- a/packages/kbn-alerts-as-data-utils/src/schemas/generated/observability_uptime_schema.ts +++ b/packages/kbn-alerts-as-data-utils/src/schemas/generated/observability_uptime_schema.ts @@ -77,6 +77,7 @@ const ObservabilityUptimeAlertOptional = rt.partial({ 'anomaly.start': schemaDate, configId: schemaString, 'error.message': schemaString, + 'error.stack_trace': schemaString, 'host.name': schemaString, 'kibana.alert.context': schemaUnknown, 'kibana.alert.evaluation.threshold': schemaStringOrNumber, diff --git a/x-pack/plugins/alerting/server/integration_tests/__snapshots__/alert_as_data_fields.test.ts.snap b/x-pack/plugins/alerting/server/integration_tests/__snapshots__/alert_as_data_fields.test.ts.snap index 8c65843f2d844..0513842a6126b 100644 --- a/x-pack/plugins/alerting/server/integration_tests/__snapshots__/alert_as_data_fields.test.ts.snap +++ b/x-pack/plugins/alerting/server/integration_tests/__snapshots__/alert_as_data_fields.test.ts.snap @@ -9851,6 +9851,10 @@ Object { "required": false, "type": "text", }, + "error.stack_trace": Object { + "required": false, + "type": "wildcard", + }, "host.name": Object { "required": false, "type": "keyword", @@ -9991,6 +9995,10 @@ Object { "required": false, "type": "text", }, + "error.stack_trace": Object { + "required": false, + "type": "wildcard", + }, "host.name": Object { "required": false, "type": "keyword", @@ -10131,6 +10139,10 @@ Object { "required": false, "type": "text", }, + "error.stack_trace": Object { + "required": false, + "type": "wildcard", + }, "host.name": Object { "required": false, "type": "keyword", @@ -10271,6 +10283,10 @@ Object { "required": false, "type": "text", }, + "error.stack_trace": Object { + "required": false, + "type": "wildcard", + }, "host.name": Object { "required": false, "type": "keyword", @@ -10417,6 +10433,10 @@ Object { "required": false, "type": "text", }, + "error.stack_trace": Object { + "required": false, + "type": "wildcard", + }, "host.name": Object { "required": false, "type": "keyword", diff --git a/x-pack/plugins/observability_solution/synthetics/common/field_names.ts b/x-pack/plugins/observability_solution/synthetics/common/field_names.ts index e7f8e83d73b4b..45be741982b01 100644 --- a/x-pack/plugins/observability_solution/synthetics/common/field_names.ts +++ b/x-pack/plugins/observability_solution/synthetics/common/field_names.ts @@ -15,6 +15,7 @@ export const OBSERVER_NAME = 'observer.name'; export const SERVICE_NAME = 'service.name'; export const OBSERVER_GEO_NAME = 'observer.geo.name'; export const ERROR_MESSAGE = 'error.message'; +export const ERROR_STACK_TRACE = 'error.stack_trace'; export const STATE_ID = 'monitor.state.id'; export const CERT_COMMON_NAME = 'tls.server.x509.subject.common_name'; diff --git a/x-pack/plugins/observability_solution/synthetics/common/requests/get_certs_request_body.ts b/x-pack/plugins/observability_solution/synthetics/common/requests/get_certs_request_body.ts index f151192a730ed..31f389a909004 100644 --- a/x-pack/plugins/observability_solution/synthetics/common/requests/get_certs_request_body.ts +++ b/x-pack/plugins/observability_solution/synthetics/common/requests/get_certs_request_body.ts @@ -150,7 +150,7 @@ export const getCertsRequestBody = ({ 'service', 'labels', 'tags', - 'error.message', + 'error', ], collapse: { field: 'tls.server.hash.sha256', @@ -222,6 +222,7 @@ export const processCertsResult = (result: CertificatesResults): CertResult => { locationId: ping?.observer?.name, locationName: ping?.observer?.geo?.name, errorMessage: ping?.error?.message, + errorStackTrace: ping?.error?.stack_trace, }; }); const total = result.aggregations?.total?.value ?? 0; diff --git a/x-pack/plugins/observability_solution/synthetics/common/rules/synthetics_rule_field_map.ts b/x-pack/plugins/observability_solution/synthetics/common/rules/synthetics_rule_field_map.ts index f82f44ba2d24d..390916026668c 100644 --- a/x-pack/plugins/observability_solution/synthetics/common/rules/synthetics_rule_field_map.ts +++ b/x-pack/plugins/observability_solution/synthetics/common/rules/synthetics_rule_field_map.ts @@ -32,6 +32,10 @@ export const syntheticsRuleFieldMap: FieldMap = { type: 'text', required: false, }, + 'error.stack_trace': { + type: 'wildcard', + required: false, + }, 'agent.name': { type: 'keyword', required: false, diff --git a/x-pack/plugins/observability_solution/synthetics/common/runtime_types/certs.ts b/x-pack/plugins/observability_solution/synthetics/common/runtime_types/certs.ts index 4fe14a54c0d66..49ac5573294e1 100644 --- a/x-pack/plugins/observability_solution/synthetics/common/runtime_types/certs.ts +++ b/x-pack/plugins/observability_solution/synthetics/common/runtime_types/certs.ts @@ -51,6 +51,7 @@ export const CertType = t.intersection([ '@timestamp': t.string, serviceName: t.string, errorMessage: t.string, + errorStackTrace: t.union([t.string, t.null]), labels: t.record(t.string, t.string), tags: t.array(t.string), }), diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/message_utils.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/message_utils.ts index 812a900667cf7..6f01e9b234bf6 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/message_utils.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/message_utils.ts @@ -24,6 +24,7 @@ import { AGENT_NAME, STATE_ID, SERVICE_NAME, + ERROR_STACK_TRACE, } from '../../../common/field_names'; import { OverviewPing } from '../../../common/runtime_types'; import { UNNAMED_LOCATION } from '../../../common/constants'; @@ -42,6 +43,8 @@ export const getMonitorAlertDocument = ( [OBSERVER_GEO_NAME]: locationNames, [OBSERVER_NAME]: locationIds, [ERROR_MESSAGE]: monitorSummary.lastErrorMessage, + // done to avoid assigning null to the field + [ERROR_STACK_TRACE]: monitorSummary.lastErrorStack ? monitorSummary.lastErrorStack : undefined, [AGENT_NAME]: monitorSummary.hostName, [ALERT_REASON]: monitorSummary.reason, [STATE_ID]: monitorSummary.stateId, @@ -114,7 +117,9 @@ export const getMonitorSummary = ({ monitorId: monitorInfo.monitor?.id, monitorName, monitorType: typeToLabelMap[monitorInfo.monitor?.type] || monitorInfo.monitor?.type, - lastErrorMessage: monitorInfo.error?.message!, + lastErrorMessage: monitorInfo.error?.message, + // done to avoid assigning null to the field + lastErrorStack: monitorInfo.error?.stack_trace ? monitorInfo.error?.stack_trace : undefined, serviceName: monitorInfo.service?.name, labels: monitorInfo.labels, locationName: formattedLocationName, diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/types.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/types.ts index 82294e55c08fc..85ae989876107 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/types.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/types.ts @@ -69,6 +69,7 @@ export interface MonitorSummaryStatusRule { }; stateId?: string; lastErrorMessage?: string; + lastErrorStack?: string | null; timestamp: string; labels?: Record; } diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.ts index 15a6f093becd9..a6a7d82fb3335 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.ts @@ -29,6 +29,7 @@ import { CERT_VALID_NOT_AFTER, CERT_VALID_NOT_BEFORE, ERROR_MESSAGE, + ERROR_STACK_TRACE, MONITOR_ID, MONITOR_NAME, MONITOR_TYPE, @@ -103,6 +104,7 @@ export const getCertSummary = (cert: Cert, expirationThreshold: number, ageThres configId: cert.configId, monitorTags: cert.tags, errorMessage: cert.errorMessage, + errorStackTrace: cert.errorStackTrace, labels: cert.labels, }; }; @@ -123,6 +125,8 @@ export const getTLSAlertDocument = (cert: Cert, monitorSummary: CertSummary, uui [OBSERVER_GEO_NAME]: monitorSummary.locationName ? [monitorSummary.locationName] : [], [OBSERVER_NAME]: monitorSummary.locationId ? [monitorSummary.locationId] : [], [ERROR_MESSAGE]: monitorSummary.errorMessage, + // done to avoid assigning null to the field + [ERROR_STACK_TRACE]: monitorSummary.errorStackTrace ? monitorSummary.errorStackTrace : undefined, 'location.id': monitorSummary.locationId ? [monitorSummary.locationId] : [], 'location.name': monitorSummary.locationName ? [monitorSummary.locationName] : [], labels: cert.labels, diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/translations.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/translations.ts index 40017b00646f1..03063f92ee56c 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/translations.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/translations.ts @@ -79,6 +79,15 @@ export const commonMonitorStateI18: Array<{ } ), }, + { + name: 'lastErrorStack', + description: i18n.translate( + 'xpack.synthetics.alertRules.monitorStatus.actionVariables.state.lastErrorStack', + { + defaultMessage: 'Monitor last error stack trace.', + } + ), + }, { name: 'locationName', description: i18n.translate( diff --git a/x-pack/plugins/observability_solution/uptime/common/rules/uptime_rule_field_map.ts b/x-pack/plugins/observability_solution/uptime/common/rules/uptime_rule_field_map.ts index 6e0f73e183462..c157177b585ba 100644 --- a/x-pack/plugins/observability_solution/uptime/common/rules/uptime_rule_field_map.ts +++ b/x-pack/plugins/observability_solution/uptime/common/rules/uptime_rule_field_map.ts @@ -32,6 +32,10 @@ export const uptimeRuleFieldMap: FieldMap = { type: 'text', required: false, }, + 'error.stack_trace': { + type: 'wildcard', + required: false, + }, 'agent.name': { type: 'keyword', required: false,