From 3b5bf3cba7608913ae76d5cbdcf626a486c1cf45 Mon Sep 17 00:00:00 2001 From: Chris Cowan Date: Mon, 16 Oct 2023 11:44:48 -0600 Subject: [PATCH] Updating tests to reflect the changes by adding the delay --- .../__snapshots__/build_query.test.ts.snap | 124 +++++++++--------- .../slo_burn_rate/lib/build_query.test.ts | 9 +- .../server/services/slo/sli_client.test.ts | 8 +- 3 files changed, 72 insertions(+), 69 deletions(-) diff --git a/x-pack/plugins/observability/server/lib/rules/slo_burn_rate/lib/__snapshots__/build_query.test.ts.snap b/x-pack/plugins/observability/server/lib/rules/slo_burn_rate/lib/__snapshots__/build_query.test.ts.snap index 8699b28ab5a5e..77597b4fea26a 100644 --- a/x-pack/plugins/observability/server/lib/rules/slo_burn_rate/lib/__snapshots__/build_query.test.ts.snap +++ b/x-pack/plugins/observability/server/lib/rules/slo_burn_rate/lib/__snapshots__/build_query.test.ts.snap @@ -21,8 +21,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T23:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T22:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -70,8 +70,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T23:55:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T23:52:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -119,8 +119,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T18:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T17:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -168,8 +168,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T23:30:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T23:27:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -217,8 +217,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T00:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-30T23:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -266,8 +266,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T22:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T21:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -315,8 +315,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-29T00:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-28T23:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -364,8 +364,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T18:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T17:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -445,8 +445,8 @@ Object { Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-29T00:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-28T23:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -478,8 +478,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T23:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T22:56:00.000Z", + "lt": "2022-12-31T23:56:00.000Z", }, }, }, @@ -505,7 +505,7 @@ Object { }, "script": Object { "params": Object { - "target": 0.999, + "target": 0.98, }, "source": "params.total != null && params.total > 0 ? (1 - (params.good / params.total)) / (1 - params.target) : 0", }, @@ -527,8 +527,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T23:55:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T23:51:00.000Z", + "lt": "2022-12-31T23:56:00.000Z", }, }, }, @@ -554,7 +554,7 @@ Object { }, "script": Object { "params": Object { - "target": 0.999, + "target": 0.98, }, "source": "params.total != null && params.total > 0 ? (1 - (params.good / params.total)) / (1 - params.target) : 0", }, @@ -576,8 +576,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T18:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T17:56:00.000Z", + "lt": "2022-12-31T23:56:00.000Z", }, }, }, @@ -603,7 +603,7 @@ Object { }, "script": Object { "params": Object { - "target": 0.999, + "target": 0.98, }, "source": "params.total != null && params.total > 0 ? (1 - (params.good / params.total)) / (1 - params.target) : 0", }, @@ -625,8 +625,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T23:30:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T23:26:00.000Z", + "lt": "2022-12-31T23:56:00.000Z", }, }, }, @@ -652,7 +652,7 @@ Object { }, "script": Object { "params": Object { - "target": 0.999, + "target": 0.98, }, "source": "params.total != null && params.total > 0 ? (1 - (params.good / params.total)) / (1 - params.target) : 0", }, @@ -674,8 +674,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T00:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-30T23:56:00.000Z", + "lt": "2022-12-31T23:56:00.000Z", }, }, }, @@ -701,7 +701,7 @@ Object { }, "script": Object { "params": Object { - "target": 0.999, + "target": 0.98, }, "source": "params.total != null && params.total > 0 ? (1 - (params.good / params.total)) / (1 - params.target) : 0", }, @@ -723,8 +723,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T22:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T21:56:00.000Z", + "lt": "2022-12-31T23:56:00.000Z", }, }, }, @@ -750,7 +750,7 @@ Object { }, "script": Object { "params": Object { - "target": 0.999, + "target": 0.98, }, "source": "params.total != null && params.total > 0 ? (1 - (params.good / params.total)) / (1 - params.target) : 0", }, @@ -772,8 +772,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-29T00:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-28T23:56:00.000Z", + "lt": "2022-12-31T23:56:00.000Z", }, }, }, @@ -799,7 +799,7 @@ Object { }, "script": Object { "params": Object { - "target": 0.999, + "target": 0.98, }, "source": "params.total != null && params.total > 0 ? (1 - (params.good / params.total)) / (1 - params.target) : 0", }, @@ -821,8 +821,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T18:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T17:56:00.000Z", + "lt": "2022-12-31T23:56:00.000Z", }, }, }, @@ -848,7 +848,7 @@ Object { }, "script": Object { "params": Object { - "target": 0.999, + "target": 0.98, }, "source": "params.total != null && params.total > 0 ? (1 - (params.good / params.total)) / (1 - params.target) : 0", }, @@ -902,8 +902,8 @@ Object { Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-29T00:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-28T23:56:00.000Z", + "lt": "2022-12-31T23:56:00.000Z", }, }, }, @@ -935,8 +935,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T23:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T22:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -984,8 +984,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T23:55:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T23:52:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -1033,8 +1033,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T18:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T17:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -1082,8 +1082,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T23:30:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T23:27:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -1131,8 +1131,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T00:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-30T23:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -1180,8 +1180,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T22:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T21:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -1229,8 +1229,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-29T00:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-28T23:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -1278,8 +1278,8 @@ Object { "filter": Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-31T18:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-31T17:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, @@ -1362,8 +1362,8 @@ Object { Object { "range": Object { "@timestamp": Object { - "gte": "2022-12-29T00:00:00.000Z", - "lt": "2023-01-01T00:00:00.000Z", + "gte": "2022-12-28T23:57:00.000Z", + "lt": "2022-12-31T23:57:00.000Z", }, }, }, diff --git a/x-pack/plugins/observability/server/lib/rules/slo_burn_rate/lib/build_query.test.ts b/x-pack/plugins/observability/server/lib/rules/slo_burn_rate/lib/build_query.test.ts index 730fe8ae66e46..a77db347edacd 100644 --- a/x-pack/plugins/observability/server/lib/rules/slo_burn_rate/lib/build_query.test.ts +++ b/x-pack/plugins/observability/server/lib/rules/slo_burn_rate/lib/build_query.test.ts @@ -7,7 +7,11 @@ import { createBurnRateRule } from '../fixtures/rule'; import { buildQuery } from './build_query'; -import { createKQLCustomIndicator, createSLO } from '../../../../services/slo/fixtures/slo'; +import { + createKQLCustomIndicator, + createSLO, + createSLOWithTimeslicesBudgetingMethod, +} from '../../../../services/slo/fixtures/slo'; const STARTED_AT = new Date('2023-01-01T00:00:00.000Z'); @@ -29,10 +33,9 @@ describe('buildQuery()', () => { expect(buildQuery(STARTED_AT, slo, rule, { instanceId: 'example' })).toMatchSnapshot(); }); it('should return a valid query for timeslices', () => { - const slo = createSLO({ + const slo = createSLOWithTimeslicesBudgetingMethod({ id: 'test-slo', indicator: createKQLCustomIndicator(), - budgetingMethod: 'timeslices', }); const rule = createBurnRateRule(slo); expect(buildQuery(STARTED_AT, slo, rule)).toMatchSnapshot(); diff --git a/x-pack/plugins/observability/server/services/slo/sli_client.test.ts b/x-pack/plugins/observability/server/services/slo/sli_client.test.ts index 112a3162ba53d..ed540e4f79fc5 100644 --- a/x-pack/plugins/observability/server/services/slo/sli_client.test.ts +++ b/x-pack/plugins/observability/server/services/slo/sli_client.test.ts @@ -95,7 +95,7 @@ describe('SummaryClient', () => { [LONG_WINDOW]: { date_range: { field: '@timestamp', - ranges: [{ from: 'now-1h/m', to: 'now/m' }], + ranges: [{ from: 'now-1h-180s/m', to: 'now-180s/m' }], }, aggs: { good: { sum: { field: 'slo.numerator' } }, @@ -105,7 +105,7 @@ describe('SummaryClient', () => { [SHORT_WINDOW]: { date_range: { field: '@timestamp', - ranges: [{ from: 'now-5m/m', to: 'now/m' }], + ranges: [{ from: 'now-5m-180s/m', to: 'now-180s/m' }], }, aggs: { good: { sum: { field: 'slo.numerator' } }, @@ -185,7 +185,7 @@ describe('SummaryClient', () => { [LONG_WINDOW]: { date_range: { field: '@timestamp', - ranges: [{ from: 'now-1h/m', to: 'now/m' }], + ranges: [{ from: 'now-1h-720s/m', to: 'now-720s/m' }], }, aggs: { good: { @@ -203,7 +203,7 @@ describe('SummaryClient', () => { [SHORT_WINDOW]: { date_range: { field: '@timestamp', - ranges: [{ from: 'now-5m/m', to: 'now/m' }], + ranges: [{ from: 'now-5m-720s/m', to: 'now-720s/m' }], }, aggs: { good: {