From e8fffdeda312aae8721fc8112c07c0bff9d30bbb Mon Sep 17 00:00:00 2001 From: Kevin Delemme Date: Thu, 31 Oct 2024 15:14:07 -0400 Subject: [PATCH] Update tests --- .../__snapshots__/create_slo.test.ts.snap | 12 -- .../__snapshots__/reset_slo.test.ts.snap | 12 -- .../apm_transaction_duration.test.ts.snap | 115 +++++++++++- .../apm_transaction_error_rate.test.ts.snap | 115 +++++++++++- .../__snapshots__/histogram.test.ts.snap | 75 +++++++- .../__snapshots__/kql_custom.test.ts.snap | 75 +++++++- .../__snapshots__/metric_custom.test.ts.snap | 50 ++++- .../synthetics_availability.test.ts.snap | 140 ++++++++++++++ .../timeslice_metric.test.ts.snap | 50 ++++- .../transform_generator.test.ts.snap | 173 ++++++++++++++++++ .../synthetics_availability.test.ts | 119 +----------- .../transform_generator.test.ts | 54 +----- .../apis/observability/slo/create_slo.ts | 9 + 13 files changed, 795 insertions(+), 204 deletions(-) create mode 100644 x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/synthetics_availability.test.ts.snap create mode 100644 x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/transform_generator.test.ts.snap diff --git a/x-pack/plugins/observability_solution/slo/server/services/__snapshots__/create_slo.test.ts.snap b/x-pack/plugins/observability_solution/slo/server/services/__snapshots__/create_slo.test.ts.snap index d747d5083cd28..86ad3e4bb5534 100644 --- a/x-pack/plugins/observability_solution/slo/server/services/__snapshots__/create_slo.test.ts.snap +++ b/x-pack/plugins/observability_solution/slo/server/services/__snapshots__/create_slo.test.ts.snap @@ -18,18 +18,6 @@ Array [ "value": "{{{_ingest.timestamp}}}", }, }, - Object { - "set": Object { - "field": "slo.id", - "value": "unique-id", - }, - }, - Object { - "set": Object { - "field": "slo.revision", - "value": 1, - }, - }, Object { "date_index_name": Object { "date_formats": Array [ diff --git a/x-pack/plugins/observability_solution/slo/server/services/__snapshots__/reset_slo.test.ts.snap b/x-pack/plugins/observability_solution/slo/server/services/__snapshots__/reset_slo.test.ts.snap index 00dc9bb4654ae..8ca307b7caf20 100644 --- a/x-pack/plugins/observability_solution/slo/server/services/__snapshots__/reset_slo.test.ts.snap +++ b/x-pack/plugins/observability_solution/slo/server/services/__snapshots__/reset_slo.test.ts.snap @@ -214,18 +214,6 @@ exports[`ResetSLO resets all associated resources 8`] = ` "value": "{{{_ingest.timestamp}}}", }, }, - Object { - "set": Object { - "field": "slo.id", - "value": "irrelevant", - }, - }, - Object { - "set": Object { - "field": "slo.revision", - "value": 1, - }, - }, Object { "date_index_name": Object { "date_formats": Array [ diff --git a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/apm_transaction_duration.test.ts.snap b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/apm_transaction_duration.test.ts.snap index fe0c3a8904c05..309141dc4c9fd 100644 --- a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/apm_transaction_duration.test.ts.snap +++ b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/apm_transaction_duration.test.ts.snap @@ -190,6 +190,16 @@ Object { "field": "service.environment", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, } `; @@ -244,6 +254,16 @@ Object { "field": "service.name", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, } `; @@ -293,6 +313,16 @@ Object { "fixed_interval": "1m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, "transaction.name": Object { "terms": Object { "field": "transaction.name", @@ -347,6 +377,16 @@ Object { "fixed_interval": "1m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, "transaction.type": Object { "terms": Object { "field": "transaction.type", @@ -423,6 +463,16 @@ Object { "field": "service.name", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, "transaction.name": Object { "terms": Object { "field": "transaction.name", @@ -491,7 +541,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { @@ -571,6 +634,16 @@ Object { "field": "service.name", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, "transaction.name": Object { "terms": Object { "field": "transaction.name", @@ -639,7 +712,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { @@ -710,6 +796,16 @@ Object { "field": "service.name", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, "transaction.name": Object { "terms": Object { "field": "transaction.name", @@ -778,7 +874,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { diff --git a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/apm_transaction_error_rate.test.ts.snap b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/apm_transaction_error_rate.test.ts.snap index a081c2829f2bc..25496c8906698 100644 --- a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/apm_transaction_error_rate.test.ts.snap +++ b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/apm_transaction_error_rate.test.ts.snap @@ -178,6 +178,16 @@ Object { "field": "service.environment", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, } `; @@ -228,6 +238,16 @@ Object { "field": "service.name", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, } `; @@ -273,6 +293,16 @@ Object { "fixed_interval": "1m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, "transaction.name": Object { "terms": Object { "field": "transaction.name", @@ -323,6 +353,16 @@ Object { "fixed_interval": "1m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, "transaction.type": Object { "terms": Object { "field": "transaction.type", @@ -390,6 +430,16 @@ Object { "field": "service.name", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, "transaction.name": Object { "terms": Object { "field": "transaction.name", @@ -454,7 +504,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { @@ -525,6 +588,16 @@ Object { "field": "service.name", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, "transaction.name": Object { "terms": Object { "field": "transaction.name", @@ -589,7 +662,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { @@ -651,6 +737,16 @@ Object { "field": "service.name", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, "transaction.name": Object { "terms": Object { "field": "transaction.name", @@ -715,7 +811,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { diff --git a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/histogram.test.ts.snap b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/histogram.test.ts.snap index 43026be44a3bb..bb7ccec260c77 100644 --- a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/histogram.test.ts.snap +++ b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/histogram.test.ts.snap @@ -153,6 +153,16 @@ Object { "fixed_interval": "2m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, }, }, "settings": Object { @@ -189,7 +199,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { @@ -282,6 +305,16 @@ Object { "fixed_interval": "2m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, }, }, "settings": Object { @@ -318,7 +351,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { @@ -402,6 +448,16 @@ Object { "fixed_interval": "1m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, }, }, "settings": Object { @@ -438,7 +494,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { diff --git a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/kql_custom.test.ts.snap b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/kql_custom.test.ts.snap index 95e1e3abf6aa5..89f06005b52ee 100644 --- a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/kql_custom.test.ts.snap +++ b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/kql_custom.test.ts.snap @@ -167,6 +167,16 @@ Object { "fixed_interval": "2m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, }, }, "settings": Object { @@ -203,7 +213,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { @@ -269,6 +292,16 @@ Object { "fixed_interval": "2m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, }, }, "settings": Object { @@ -305,7 +338,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { @@ -362,6 +408,16 @@ Object { "fixed_interval": "1m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, }, }, "settings": Object { @@ -398,7 +454,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { diff --git a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/metric_custom.test.ts.snap b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/metric_custom.test.ts.snap index 4b7dab85cec60..45cc9960153a2 100644 --- a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/metric_custom.test.ts.snap +++ b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/metric_custom.test.ts.snap @@ -204,6 +204,16 @@ Object { "fixed_interval": "2m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, }, }, "settings": Object { @@ -240,7 +250,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { @@ -335,6 +358,16 @@ Object { "fixed_interval": "1m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, }, }, "settings": Object { @@ -371,7 +404,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { diff --git a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/synthetics_availability.test.ts.snap b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/synthetics_availability.test.ts.snap new file mode 100644 index 0000000000000..3d55f6f88d411 --- /dev/null +++ b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/synthetics_availability.test.ts.snap @@ -0,0 +1,140 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Synthetics Availability Transform Generator returns the expected transform params 1`] = ` +Object { + "_meta": Object { + "managed": true, + "managed_by": "observability", + "version": 3.3, + }, + "defer_validation": true, + "description": "Rolled-up SLI data for SLO: irrelevant [id: irrelevant, revision: 1]", + "dest": Object { + "index": ".slo-observability.sli-v3.3", + "pipeline": ".slo-observability.sli.pipeline-irrelevant-1", + }, + "frequency": "1m", + "pivot": Object { + "aggregations": Object { + "slo.denominator": Object { + "filter": Object { + "term": Object { + "summary.final_attempt": true, + }, + }, + }, + "slo.numerator": Object { + "filter": Object { + "term": Object { + "monitor.status": "up", + }, + }, + }, + }, + "group_by": Object { + "@timestamp": Object { + "date_histogram": Object { + "field": "@timestamp", + "fixed_interval": "1m", + }, + }, + "monitor.config_id": Object { + "terms": Object { + "field": "config_id", + }, + }, + "monitor.name": Object { + "terms": Object { + "field": "monitor.name", + }, + }, + "observer.geo.name": Object { + "terms": Object { + "field": "observer.geo.name", + }, + }, + "observer.name": Object { + "terms": Object { + "field": "observer.name", + }, + }, + "slo.groupings.monitor.id": Object { + "terms": Object { + "field": "monitor.id", + }, + }, + "slo.groupings.monitor.name": Object { + "terms": Object { + "field": "monitor.name", + }, + }, + "slo.groupings.observer.geo.name": Object { + "terms": Object { + "field": "observer.geo.name", + }, + }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, + }, + }, + "settings": Object { + "deduce_mappings": false, + "unattended": true, + }, + "source": Object { + "index": "synthetics-*", + "query": Object { + "bool": Object { + "filter": Array [ + Object { + "term": Object { + "summary.final_attempt": true, + }, + }, + Object { + "term": Object { + "meta.space_id": "custom-space", + }, + }, + Object { + "range": Object { + "@timestamp": Object { + "gte": "now-7d/d", + }, + }, + }, + ], + }, + }, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, + }, + "sync": Object { + "time": Object { + "delay": "1m", + "field": "event.ingested", + }, + }, + "transform_id": "slo-irrelevant-1", +} +`; diff --git a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/timeslice_metric.test.ts.snap b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/timeslice_metric.test.ts.snap index 449d1c2fb74d2..8ddd288f46f0a 100644 --- a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/timeslice_metric.test.ts.snap +++ b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/timeslice_metric.test.ts.snap @@ -174,6 +174,16 @@ Object { "fixed_interval": "2m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, }, }, "settings": Object { @@ -207,7 +217,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { @@ -365,6 +388,16 @@ Object { "fixed_interval": "2m", }, }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, }, }, "settings": Object { @@ -398,7 +431,20 @@ Object { ], }, }, - "runtime_mappings": Object {}, + "runtime_mappings": Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, + }, }, "sync": Object { "time": Object { diff --git a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/transform_generator.test.ts.snap b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/transform_generator.test.ts.snap new file mode 100644 index 0000000000000..6bae7d1078791 --- /dev/null +++ b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/__snapshots__/transform_generator.test.ts.snap @@ -0,0 +1,173 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Transform Generator builds common runtime mappings and group by with single group by 1`] = ` +Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, +} +`; + +exports[`Transform Generator builds common runtime mappings and group by with single group by 2`] = ` +Object { + "@timestamp": Object { + "date_histogram": Object { + "field": "@timestamp", + "fixed_interval": "1m", + }, + }, + "slo.groupings.example": Object { + "terms": Object { + "field": "example", + }, + }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, +} +`; + +exports[`Transform Generator builds common runtime mappings and group by with single group by 3`] = ` +Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, +} +`; + +exports[`Transform Generator builds common runtime mappings and group by with single group by 4`] = ` +Object { + "@timestamp": Object { + "date_histogram": Object { + "field": "@timestamp", + "fixed_interval": "1m", + }, + }, + "slo.groupings.example": Object { + "terms": Object { + "field": "example", + }, + }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, +} +`; + +exports[`Transform Generator builds common runtime mappings without multi group by 1`] = ` +Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, +} +`; + +exports[`Transform Generator builds common runtime mappings without multi group by 2`] = ` +Object { + "@timestamp": Object { + "date_histogram": Object { + "field": "@timestamp", + "fixed_interval": "1m", + }, + }, + "slo.groupings.example1": Object { + "terms": Object { + "field": "example1", + }, + }, + "slo.groupings.example2": Object { + "terms": Object { + "field": "example2", + }, + }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, +} +`; + +exports[`Transform Generator builds empty runtime mappings without group by 1`] = ` +Object { + "slo.id": Object { + "script": Object { + "source": "emit('irrelevant')", + }, + "type": "keyword", + }, + "slo.revision": Object { + "script": Object { + "source": "emit(1)", + }, + "type": "long", + }, +} +`; + +exports[`Transform Generator builds empty runtime mappings without group by 2`] = ` +Object { + "@timestamp": Object { + "date_histogram": Object { + "field": "@timestamp", + "fixed_interval": "1m", + }, + }, + "slo.id": Object { + "terms": Object { + "field": "slo.id", + }, + }, + "slo.revision": Object { + "terms": Object { + "field": "slo.revision", + }, + }, +} +`; diff --git a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/synthetics_availability.test.ts b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/synthetics_availability.test.ts index f9caeb9f57c31..565a0d56d1ff4 100644 --- a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/synthetics_availability.test.ts +++ b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/synthetics_availability.test.ts @@ -5,13 +5,12 @@ * 2.0. */ -import { ALL_VALUE } from '@kbn/slo-schema'; import { dataViewsService } from '@kbn/data-views-plugin/server/mocks'; +import { ALL_VALUE } from '@kbn/slo-schema'; import { SLODefinition } from '../../domain/models'; +import { twoMinute } from '../fixtures/duration'; import { createSLO, createSyntheticsAvailabilityIndicator } from '../fixtures/slo'; import { SyntheticsAvailabilityTransformGenerator } from './synthetics_availability'; -import { SYNTHETICS_INDEX_PATTERN } from '../../../common/constants'; -import { twoMinute } from '../fixtures/duration'; const generator = new SyntheticsAvailabilityTransformGenerator(); @@ -22,119 +21,7 @@ describe('Synthetics Availability Transform Generator', () => { const slo = createSLO({ id: 'irrelevant', indicator: createSyntheticsAvailabilityIndicator() }); const transform = await generator.getTransformParams(slo, spaceId, dataViewsService); - expect(transform).toEqual({ - _meta: { - managed: true, - managed_by: 'observability', - version: 3.3, - }, - defer_validation: true, - description: 'Rolled-up SLI data for SLO: irrelevant [id: irrelevant, revision: 1]', - dest: { - index: '.slo-observability.sli-v3.3', - pipeline: '.slo-observability.sli.pipeline-irrelevant-1', - }, - frequency: '1m', - pivot: { - aggregations: { - 'slo.denominator': { - filter: { - term: { - 'summary.final_attempt': true, - }, - }, - }, - 'slo.numerator': { - filter: { - term: { - 'monitor.status': 'up', - }, - }, - }, - }, - group_by: { - '@timestamp': { - date_histogram: { - field: '@timestamp', - fixed_interval: '1m', - }, - }, - 'monitor.config_id': { - terms: { - field: 'config_id', - }, - }, - 'monitor.name': { - terms: { - field: 'monitor.name', - }, - }, - 'observer.name': { - terms: { - field: 'observer.name', - }, - }, - 'observer.geo.name': { - terms: { - field: 'observer.geo.name', - }, - }, - 'slo.groupings.monitor.name': { - terms: { - field: 'monitor.name', - }, - }, - 'slo.groupings.observer.geo.name': { - terms: { - field: 'observer.geo.name', - }, - }, - 'slo.groupings.monitor.id': { - terms: { - field: 'monitor.id', - }, - }, - }, - }, - settings: { - deduce_mappings: false, - unattended: true, - }, - source: { - index: SYNTHETICS_INDEX_PATTERN, - query: { - bool: { - filter: [ - { - term: { - 'summary.final_attempt': true, - }, - }, - { - term: { - 'meta.space_id': 'custom-space', - }, - }, - { - range: { - '@timestamp': { - gte: 'now-7d/d', - }, - }, - }, - ], - }, - }, - runtime_mappings: {}, - }, - sync: { - time: { - delay: '1m', - field: 'event.ingested', - }, - }, - transform_id: 'slo-irrelevant-1', - }); + expect(transform).toMatchSnapshot(); expect(transform.source.query?.bool?.filter).toContainEqual({ term: { 'summary.final_attempt': true, diff --git a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/transform_generator.test.ts b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/transform_generator.test.ts index ffb165fdb4326..9f07c6cfb5afa 100644 --- a/x-pack/plugins/observability_solution/slo/server/services/transform_generators/transform_generator.test.ts +++ b/x-pack/plugins/observability_solution/slo/server/services/transform_generators/transform_generator.test.ts @@ -17,19 +17,10 @@ describe('Transform Generator', () => { indicator: createAPMTransactionErrorRateIndicator(), }); const commonRuntime = generator.buildCommonRuntimeMappings(slo); - - expect(commonRuntime).toEqual({}); + expect(commonRuntime).toMatchSnapshot(); const commonGroupBy = generator.buildCommonGroupBy(slo); - - expect(commonGroupBy).toEqual({ - '@timestamp': { - date_histogram: { - field: '@timestamp', - fixed_interval: '1m', - }, - }, - }); + expect(commonGroupBy).toMatchSnapshot(); }); it.each(['example', ['example']])( @@ -42,24 +33,10 @@ describe('Transform Generator', () => { indicator, }); const commonRuntime = generator.buildCommonRuntimeMappings(slo); - - expect(commonRuntime).toEqual({}); + expect(commonRuntime).toMatchSnapshot(); const commonGroupBy = generator.buildCommonGroupBy(slo); - - expect(commonGroupBy).toEqual({ - '@timestamp': { - date_histogram: { - field: '@timestamp', - fixed_interval: '1m', - }, - }, - 'slo.groupings.example': { - terms: { - field: 'example', - }, - }, - }); + expect(commonGroupBy).toMatchSnapshot(); } ); @@ -71,28 +48,9 @@ describe('Transform Generator', () => { indicator, }); const commonRuntime = generator.buildCommonRuntimeMappings(slo); - - expect(commonRuntime).toEqual({}); + expect(commonRuntime).toMatchSnapshot(); const commonGroupBy = generator.buildCommonGroupBy(slo); - - expect(commonGroupBy).toEqual({ - '@timestamp': { - date_histogram: { - field: '@timestamp', - fixed_interval: '1m', - }, - }, - 'slo.groupings.example1': { - terms: { - field: 'example1', - }, - }, - 'slo.groupings.example2': { - terms: { - field: 'example2', - }, - }, - }); + expect(commonGroupBy).toMatchSnapshot(); }); }); diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/slo/create_slo.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/slo/create_slo.ts index 28cef8c2c566c..bab12ed82d8ee 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/slo/create_slo.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/slo/create_slo.ts @@ -101,7 +101,16 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { index: '.slo-observability.sli-v3.3', pipeline: `.slo-observability.sli.pipeline-${id}-1`, }); + expect(rollUpTransformResponse.transforms[0].source.runtime_fields).eql({ + 'slo.id': { + type: 'keyword', + script: { source: `emit('${id}')` }, + }, + 'slo.revision': { type: 'long', script: { source: 'emit(1)' } }, + }); expect(rollUpTransformResponse.transforms[0].pivot.group_by).eql({ + 'slo.id': { terms: { field: 'slo.id' } }, + 'slo.revision': { terms: { field: 'slo.revision' } }, 'slo.groupings.tags': { terms: { field: 'tags' } }, '@timestamp': { date_histogram: { field: '@timestamp', fixed_interval: '1m' } }, });