diff --git a/.buildkite/ftr_oblt_stateful_configs.yml b/.buildkite/ftr_oblt_stateful_configs.yml index 6f0cb38be3a62..7655ce6de38cf 100644 --- a/.buildkite/ftr_oblt_stateful_configs.yml +++ b/.buildkite/ftr_oblt_stateful_configs.yml @@ -30,7 +30,6 @@ enabled: - x-pack/test/api_integration/apis/metrics_ui/config.ts - x-pack/test/api_integration/apis/osquery/config.ts - x-pack/test/api_integration/apis/synthetics/config.ts - - x-pack/test/api_integration/apis/slos/config.ts - x-pack/test/api_integration/apis/uptime/config.ts - x-pack/test/api_integration/apis/entity_manager/config.ts - x-pack/test/apm_api_integration/basic/config.ts diff --git a/x-pack/test/api_integration/apis/slos/config.ts b/x-pack/test/api_integration/apis/slos/config.ts deleted file mode 100644 index c755e2a46882d..0000000000000 --- a/x-pack/test/api_integration/apis/slos/config.ts +++ /dev/null @@ -1,29 +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 { FtrConfigProviderContext } from '@kbn/test'; - -export default async function ({ readConfigFile }: FtrConfigProviderContext) { - const baseIntegrationTestsConfig = await readConfigFile(require.resolve('../../config.ts')); - - return { - ...baseIntegrationTestsConfig.getAll(), - testFiles: [require.resolve('.')], - // overriding default timeouts from packages/kbn-test/src/functional_test_runner/lib/config/schema.ts - // so we can easily adjust them for serverless where needed - timeouts: { - find: 10 * 1000, - try: 120 * 1000, - waitFor: 20 * 1000, - esRequestTimeout: 30 * 1000, - kibanaReportCompletion: 60 * 1000, - kibanaStabilize: 15 * 1000, - navigateStatusPageCheck: 250, - waitForExists: 2500, - }, - }; -} diff --git a/x-pack/test/api_integration/apis/slos/create_slo.ts b/x-pack/test/api_integration/apis/slos/create_slo.ts deleted file mode 100644 index 71ce8434a61f1..0000000000000 --- a/x-pack/test/api_integration/apis/slos/create_slo.ts +++ /dev/null @@ -1,488 +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 expect from '@kbn/expect'; -import { cleanup } from '@kbn/infra-forge'; -import type { CreateSLOInput } from '@kbn/slo-schema'; -import { SO_SLO_TYPE } from '@kbn/slo-plugin/server/saved_objects'; - -import { FtrProviderContext } from '../../ftr_provider_context'; -import { sloData } from './fixtures/create_slo'; -import { loadTestData } from './helper/load_test_data'; -import { SloEsClient } from './helper/es'; - -export default function ({ getService }: FtrProviderContext) { - describe('Create SLOs', function () { - this.tags('skipCloud'); - - const supertestAPI = getService('supertest'); - const kibanaServer = getService('kibanaServer'); - const esClient = getService('es'); - const slo = getService('slo'); - const retry = getService('retry'); - const logger = getService('log'); - const sloEsClient = new SloEsClient(esClient); - - let createSLOInput: CreateSLOInput; - - before(async () => { - await slo.createUser(); - await loadTestData(getService); - await slo.deleteAllSLOs(); - }); - - beforeEach(() => { - createSLOInput = sloData; - }); - - afterEach(async () => { - await slo.deleteAllSLOs(); - }); - - after(async () => { - await cleanup({ esClient, logger }); - await sloEsClient.deleteTestSourceData(); - }); - - it('creates a new slo and transforms', async () => { - const apiResponse = await slo.create(createSLOInput); - - expect(apiResponse.body).property('id'); - - const { id } = apiResponse.body; - - const savedObject = await kibanaServer.savedObjects.find({ - type: SO_SLO_TYPE, - }); - - expect(savedObject.saved_objects.length).eql(1); - - expect(savedObject.saved_objects[0].attributes).eql({ - budgetingMethod: 'occurrences', - updatedAt: savedObject.saved_objects[0].attributes.updatedAt, - createdAt: savedObject.saved_objects[0].attributes.createdAt, - description: 'Fixture for api integration tests', - enabled: true, - groupBy: 'tags', - id, - indicator: { - params: { - filter: 'system.network.name: eth1', - good: 'container.cpu.user.pct < 1', - index: 'kbn-data-forge*', - timestampField: '@timestamp', - total: 'container.cpu.user.pct: *', - }, - type: 'sli.kql.custom', - }, - name: 'Test SLO for api integration', - objective: { - target: 0.99, - }, - revision: 1, - settings: { - frequency: '1m', - syncDelay: '1m', - preventInitialBackfill: false, - }, - tags: ['test'], - timeWindow: { - duration: '7d', - type: 'rolling', - }, - version: 2, - }); - - const rollUpTransformResponse = await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // expect roll up transform to be created - expect(rollUpTransformResponse.body).eql({ - count: 1, - transforms: [ - { - id: `slo-${id}-1`, - authorization: { roles: ['slo_editor', 'editor'] }, - version: '10.0.0', - create_time: rollUpTransformResponse.body.transforms[0].create_time, - source: { - index: ['kbn-data-forge*'], - query: { - bool: { - filter: [ - { range: { '@timestamp': { gte: 'now-7d/d' } } }, - { - bool: { - should: [ - { - match: { - 'system.network.name': 'eth1', - }, - }, - ], - minimum_should_match: 1, - }, - }, - { - exists: { - field: 'tags', - }, - }, - ], - }, - }, - }, - dest: { - index: '.slo-observability.sli-v3.3', - pipeline: `.slo-observability.sli.pipeline-${id}-1`, - }, - frequency: '1m', - sync: { time: { field: '@timestamp', delay: '1m' } }, - pivot: { - group_by: { - 'slo.groupings.tags': { terms: { field: 'tags' } }, - '@timestamp': { date_histogram: { field: '@timestamp', fixed_interval: '1m' } }, - }, - aggregations: { - 'slo.numerator': { - filter: { - bool: { - should: [{ range: { 'container.cpu.user.pct': { lt: '1' } } }], - minimum_should_match: 1, - }, - }, - }, - 'slo.denominator': { - filter: { - bool: { - should: [{ exists: { field: 'container.cpu.user.pct' } }], - minimum_should_match: 1, - }, - }, - }, - }, - }, - description: `Rolled-up SLI data for SLO: Test SLO for api integration [id: ${id}, revision: 1]`, - settings: { deduce_mappings: false, unattended: true }, - _meta: { version: 3.3, managed: true, managed_by: 'observability' }, - }, - ], - }); - - const summaryTransform = await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // expect summary transform to be created - expect(summaryTransform.body).eql({ - count: 1, - transforms: [ - { - id: `slo-summary-${id}-1`, - authorization: { roles: ['slo_editor', 'editor'] }, - version: '10.0.0', - create_time: summaryTransform.body.transforms[0].create_time, - source: { - index: ['.slo-observability.sli-v3.3*'], - query: { - bool: { - filter: [ - { range: { '@timestamp': { gte: 'now-7d/m', lte: 'now/m' } } }, - { term: { 'slo.id': id } }, - { term: { 'slo.revision': 1 } }, - ], - }, - }, - }, - dest: { - index: '.slo-observability.summary-v3.3', - pipeline: `.slo-observability.summary.pipeline-${id}-1`, - }, - frequency: '1m', - sync: { time: { field: 'event.ingested', delay: '65s' } }, - pivot: { - group_by: { - 'slo.id': { terms: { field: 'slo.id' } }, - 'slo.instanceId': { terms: { field: 'slo.instanceId' } }, - 'slo.revision': { terms: { field: 'slo.revision' } }, - 'slo.groupings.tags': { - terms: { field: 'slo.groupings.tags' }, - }, - 'monitor.config_id': { - terms: { - field: 'monitor.config_id', - missing_bucket: true, - }, - }, - 'monitor.name': { - terms: { - field: 'monitor.name', - missing_bucket: true, - }, - }, - 'observer.geo.name': { - terms: { - field: 'observer.geo.name', - missing_bucket: true, - }, - }, - 'observer.name': { - terms: { - field: 'observer.name', - missing_bucket: true, - }, - }, - 'service.name': { terms: { field: 'service.name', missing_bucket: true } }, - 'service.environment': { - terms: { field: 'service.environment', missing_bucket: true }, - }, - 'transaction.name': { terms: { field: 'transaction.name', missing_bucket: true } }, - 'transaction.type': { terms: { field: 'transaction.type', missing_bucket: true } }, - }, - aggregations: { - goodEvents: { sum: { field: 'slo.numerator' } }, - totalEvents: { sum: { field: 'slo.denominator' } }, - sliValue: { - bucket_script: { - buckets_path: { goodEvents: 'goodEvents', totalEvents: 'totalEvents' }, - script: - 'if (params.totalEvents == 0) { return -1 } else if (params.goodEvents >= params.totalEvents) { return 1 } else { return params.goodEvents / params.totalEvents }', - }, - }, - errorBudgetInitial: { bucket_script: { buckets_path: {}, script: '1 - 0.99' } }, - errorBudgetConsumed: { - bucket_script: { - buckets_path: { - sliValue: 'sliValue', - errorBudgetInitial: 'errorBudgetInitial', - }, - script: - 'if (params.sliValue == -1) { return 0 } else { return (1 - params.sliValue) / params.errorBudgetInitial }', - }, - }, - errorBudgetRemaining: { - bucket_script: { - buckets_path: { errorBudgetConsumed: 'errorBudgetConsumed' }, - script: '1 - params.errorBudgetConsumed', - }, - }, - statusCode: { - bucket_script: { - buckets_path: { - sliValue: 'sliValue', - errorBudgetRemaining: 'errorBudgetRemaining', - }, - script: { - source: - 'if (params.sliValue == -1) { return 0 } else if (params.sliValue >= 0.99) { return 4 } else if (params.errorBudgetRemaining > 0) { return 2 } else { return 1 }', - }, - }, - }, - latestSliTimestamp: { max: { field: '@timestamp' } }, - fiveMinuteBurnRate: { - filter: { - range: { - '@timestamp': { - gte: 'now-480s/m', - lte: 'now-180s/m', - }, - }, - }, - aggs: { - goodEvents: { - sum: { - field: 'slo.numerator', - }, - }, - totalEvents: { - sum: { - field: 'slo.denominator', - }, - }, - }, - }, - oneHourBurnRate: { - filter: { - range: { - '@timestamp': { - gte: 'now-3780s/m', - lte: 'now-180s/m', - }, - }, - }, - aggs: { - goodEvents: { - sum: { - field: 'slo.numerator', - }, - }, - totalEvents: { - sum: { - field: 'slo.denominator', - }, - }, - }, - }, - oneDayBurnRate: { - filter: { - range: { - '@timestamp': { - gte: 'now-86580s/m', - lte: 'now-180s/m', - }, - }, - }, - aggs: { - goodEvents: { - sum: { - field: 'slo.numerator', - }, - }, - totalEvents: { - sum: { - field: 'slo.denominator', - }, - }, - }, - }, - }, - }, - description: `Summarise the rollup data of SLO: Test SLO for api integration [id: ${id}, revision: 1].`, - settings: { deduce_mappings: false, unattended: true }, - _meta: { version: 3.3, managed: true, managed_by: 'observability' }, - }, - ], - }); - }); - - it('creates instanceId for SLOs with multi groupBy', async () => { - createSLOInput.groupBy = ['system.network.name', 'event.dataset']; - - const apiResponse = await slo.create(createSLOInput); - - expect(apiResponse.body).property('id'); - - const { id } = apiResponse.body; - - await retry.tryForTime(300 * 1000, async () => { - const response = await esClient.search(getEsQuery(id)); - - // @ts-ignore - expect(response.aggregations?.last_doc.hits?.hits[0]._source.slo.instanceId).eql( - 'eth1,system.network' - ); - }); - }); - - it('creates instanceId for SLOs with single groupBy', async () => { - createSLOInput.groupBy = 'system.network.name'; - - const apiResponse = await slo.create(createSLOInput); - - expect(apiResponse.body).property('id'); - - const { id } = apiResponse.body; - - await retry.tryForTime(300 * 1000, async () => { - const response = await esClient.search(getEsQuery(id)); - - // @ts-ignore - expect(response.aggregations?.last_doc.hits?.hits[0]._source.slo.instanceId).eql('eth1'); - }); - }); - - it('creates instanceId for SLOs without groupBy ([])', async () => { - createSLOInput.groupBy = []; - - const apiResponse = await slo.create(createSLOInput); - - expect(apiResponse.body).property('id'); - - const { id } = apiResponse.body; - - await retry.tryForTime(300 * 1000, async () => { - const response = await esClient.search(getEsQuery(id)); - - // @ts-ignore - expect(response.aggregations?.last_doc.hits?.hits[0]._source.slo.instanceId).eql('*'); - }); - }); - - it('creates instanceId for SLOs without groupBy (["*"])', async () => { - createSLOInput.groupBy = ['*']; - - const apiResponse = await slo.create(createSLOInput); - - expect(apiResponse.body).property('id'); - - const { id } = apiResponse.body; - - await retry.tryForTime(300 * 1000, async () => { - const response = await esClient.search(getEsQuery(id)); - - // @ts-ignore - expect(response.aggregations?.last_doc.hits?.hits[0]._source.slo.instanceId).eql('*'); - }); - }); - - it('creates instanceId for SLOs without groupBy ("")', async () => { - createSLOInput.groupBy = ''; - - const apiResponse = await slo.create(createSLOInput); - - expect(apiResponse.body).property('id'); - - const { id } = apiResponse.body; - - await retry.tryForTime(300 * 1000, async () => { - const response = await esClient.search(getEsQuery(id)); - - // @ts-ignore - expect(response.aggregations?.last_doc.hits?.hits[0]._source.slo.instanceId).eql('*'); - }); - }); - }); -} - -const getEsQuery = (id: string) => ({ - index: '.slo-observability.sli-v3*', - size: 0, - query: { - bool: { - filter: [ - { - term: { - 'slo.id': id, - }, - }, - ], - }, - }, - aggs: { - last_doc: { - top_hits: { - sort: [ - { - '@timestamp': { - order: 'desc', - }, - }, - ], - _source: { - includes: ['slo.instanceId'], - }, - size: 1, - }, - }, - }, -}); diff --git a/x-pack/test/api_integration/apis/slos/delete_slo.ts b/x-pack/test/api_integration/apis/slos/delete_slo.ts deleted file mode 100644 index 979564f06be55..0000000000000 --- a/x-pack/test/api_integration/apis/slos/delete_slo.ts +++ /dev/null @@ -1,141 +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 { cleanup } from '@kbn/infra-forge'; -import expect from '@kbn/expect'; -import type { CreateSLOInput } from '@kbn/slo-schema'; -import { SO_SLO_TYPE } from '@kbn/slo-plugin/server/saved_objects'; - -import { FtrProviderContext } from '../../ftr_provider_context'; -import { sloData } from './fixtures/create_slo'; -import { loadTestData } from './helper/load_test_data'; -import { SloEsClient } from './helper/es'; - -export default function ({ getService }: FtrProviderContext) { - describe('Delete SLOs', function () { - this.tags('skipCloud'); - - const supertestAPI = getService('supertest'); - const kibanaServer = getService('kibanaServer'); - const esClient = getService('es'); - const logger = getService('log'); - const slo = getService('slo'); - const retry = getService('retry'); - const sloEsClient = new SloEsClient(esClient); - - let createSLOInput: CreateSLOInput; - - before(async () => { - await slo.createUser(); - await slo.deleteAllSLOs(); - await sloEsClient.deleteTestSourceData(); - await loadTestData(getService); - }); - - beforeEach(() => { - createSLOInput = sloData; - }); - - afterEach(async () => { - await slo.deleteAllSLOs(); - }); - - after(async () => { - await cleanup({ esClient, logger }); - await sloEsClient.deleteTestSourceData(); - }); - - it('deletes new slo saved object and transforms', async () => { - const response = await slo.create(createSLOInput); - - expect(response.body).property('id'); - - const { id } = response.body; - - await retry.tryForTime(10000, async () => { - const savedObject = await kibanaServer.savedObjects.find({ - type: SO_SLO_TYPE, - }); - - expect(savedObject.saved_objects.length).eql(1); - - expect(savedObject.saved_objects[0].attributes.id).eql(id); - }); - - await retry.tryForTime(300 * 1000, async () => { - // expect summary and rollup data to exist - const sloSummaryResponse = await sloEsClient.getSLOSummaryDataById(id); - const sloRollupResponse = await sloEsClient.getSLORollupDataById(id); - - expect(sloSummaryResponse.hits.hits.length > 0).eql(true); - expect(sloRollupResponse.hits.hits.length > 0).eql(true); - - const rollUpTransformResponse = await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // expect roll up transform to be created - expect(rollUpTransformResponse.body.transforms[0].id).eql(`slo-${id}-1`); - - const summaryTransform = await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // expect summary transform to be created - expect(summaryTransform.body.transforms[0].id).eql(`slo-summary-${id}-1`); - - await slo.delete(id); - }); - - // await retry.tryForTime(150 * 1000, async () => { - const savedObjectAfterDelete = await kibanaServer.savedObjects.find({ - type: SO_SLO_TYPE, - }); - - // SO should now be deleted - expect(savedObjectAfterDelete.saved_objects.length).eql(0); - - // roll up transform should be deleted - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - // summary transform should be deleted - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - // expect summary and rollup documents to be deleted - await retry.waitForWithTimeout('SLO summary data is deleted', 60 * 1000, async () => { - const sloSummaryResponseAfterDeletion = await sloEsClient.getSLOSummaryDataById(id); - if (sloSummaryResponseAfterDeletion.hits.hits.length > 0) { - throw new Error('SLO summary data not deleted yet'); - } - return true; - }); - - await retry.waitForWithTimeout('SLO rollup data is deleted', 60 * 1000, async () => { - const sloRollupResponseAfterDeletion = await sloEsClient.getSLORollupDataById(id); - if (sloRollupResponseAfterDeletion.hits.hits.length > 1) { - throw new Error('SLO rollup data not deleted yet'); - } - return true; - }); - }); - }); -} diff --git a/x-pack/test/api_integration/apis/slos/fetch_historical_summary.ts b/x-pack/test/api_integration/apis/slos/fetch_historical_summary.ts deleted file mode 100644 index 96f8e21c8c593..0000000000000 --- a/x-pack/test/api_integration/apis/slos/fetch_historical_summary.ts +++ /dev/null @@ -1,134 +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 expect from '@kbn/expect'; -import { - SLO_DESTINATION_INDEX_NAME, - SLO_DESTINATION_INDEX_PATTERN, -} from '@kbn/slo-plugin/common/constants'; -import { ALL_VALUE } from '@kbn/slo-schema'; -import moment from 'moment'; -import { FtrProviderContext } from '../../ftr_provider_context'; - -export default function ({ getService }: FtrProviderContext) { - const esClient = getService('es'); - const esDeleteAllIndices = getService('esDeleteAllIndices'); - const sloApi = getService('slo'); - - const SLO_ID = 'slo-fake-1'; - - describe('fetch historical summary', () => { - before(async () => { - await sloApi.createUser(); - const now = moment().startOf('minute'); - const curr = now.clone().subtract(30, 'days'); - const end = now.clone().add(5, 'minutes'); - - const batchOperations = []; - while (curr.isSameOrBefore(end)) { - batchOperations.push([ - { index: { _index: SLO_DESTINATION_INDEX_NAME } }, - { - '@timestamp': curr.toISOString(), - slo: { - id: SLO_ID, - revision: 1, - instanceId: ALL_VALUE, - numerator: 90, - denominator: 100, - isGoodSlice: 1, - groupings: {}, - }, - }, - ]); - curr.add(1, 'minute'); - } - - await esClient.bulk({ - index: SLO_DESTINATION_INDEX_NAME, - operations: batchOperations.flat(), - refresh: 'wait_for', - }); - - await esClient.indices.refresh({ index: SLO_DESTINATION_INDEX_NAME }); - }); - - after(async () => { - await esDeleteAllIndices(SLO_DESTINATION_INDEX_PATTERN); - }); - - it('computes the historical summary for a rolling occurrences SLO', async () => { - const response = await sloApi.fetchHistoricalSummary({ - list: [ - { - sloId: SLO_ID, - instanceId: ALL_VALUE, - timeWindow: { - duration: '7d', - type: 'rolling', - }, - budgetingMethod: 'occurrences', - objective: { - target: 0.9, - }, - groupBy: ALL_VALUE, - revision: 1, - }, - ], - }); - expect(response[0].sloId).to.eql(SLO_ID); - expect(response[0].instanceId).to.eql(ALL_VALUE); - const numberOfBuckets = response[0].data.length; - expect(numberOfBuckets).to.be.within(168, 170); // 7 days * 24 hours/day * 1 bucket/hour + 2 extra bucket due to histogram agg rounding - const last = response[0].data.pop(); - expect(last?.errorBudget).to.eql({ - consumed: 1, - initial: 0.1, - isEstimated: false, - remaining: 0, - }); - expect(last?.sliValue).to.eql(0.9); - expect(last?.status).to.eql('HEALTHY'); - }); - - it('computes the historical summary for a rolling timeslices SLO', async () => { - const response = await sloApi.fetchHistoricalSummary({ - list: [ - { - sloId: SLO_ID, - instanceId: ALL_VALUE, - timeWindow: { - duration: '7d', - type: 'rolling', - }, - budgetingMethod: 'timeslices', - objective: { - target: 0.9, - timesliceTarget: 0.8, - timesliceWindow: '1m', - }, - groupBy: ALL_VALUE, - revision: 1, - }, - ], - }); - expect(response[0].sloId).to.eql(SLO_ID); - expect(response[0].instanceId).to.eql(ALL_VALUE); - const numberOfBuckets = response[0].data.length; - expect(numberOfBuckets).to.be.within(168, 170); // 7 days * 24 hours/day * 1 bucket/hour + 2 extra bucket due to histogram agg rounding - const last = response[0].data.pop(); - expect(last?.errorBudget).to.eql({ - consumed: 0, - initial: 0.1, - isEstimated: false, - remaining: 1, - }); - expect(last?.sliValue).to.eql(1); - expect(last?.status).to.eql('HEALTHY'); - }); - }); -} diff --git a/x-pack/test/api_integration/apis/slos/get_slo.ts b/x-pack/test/api_integration/apis/slos/get_slo.ts deleted file mode 100644 index 815409853c7d6..0000000000000 --- a/x-pack/test/api_integration/apis/slos/get_slo.ts +++ /dev/null @@ -1,492 +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 { cleanup } from '@kbn/infra-forge'; -import expect from 'expect'; -import type { CreateSLOInput } from '@kbn/slo-schema'; - -import { FtrProviderContext } from '../../ftr_provider_context'; -import { loadTestData } from './helper/load_test_data'; -import { SloEsClient } from './helper/es'; -import { sloData } from './fixtures/create_slo'; - -export const expectSummary = (summary: Record) => { - expect(summary).toEqual({ - sliValue: expect.any(Number), - errorBudget: { - initial: expect.any(Number), - consumed: expect.any(Number), - remaining: expect.any(Number), - isEstimated: expect.any(Boolean), - }, - status: expect.any(String), - fiveMinuteBurnRate: expect.any(Number), - oneDayBurnRate: expect.any(Number), - oneHourBurnRate: expect.any(Number), - }); -}; - -export default function ({ getService }: FtrProviderContext) { - describe('GetSLOs', function () { - this.tags('skipCloud'); - - const supertestAPI = getService('supertest'); - const esClient = getService('es'); - const logger = getService('log'); - const retry = getService('retry'); - const slo = getService('slo'); - // const transform = getService('transform'); - const sloEsClient = new SloEsClient(esClient); - - // const onFailure = async () => { - // const allTransforms = await transform.api.getTransformList(); - // for (const tf of allTransforms.transforms) { - // await transform.api.scheduleTransform(tf.id); - // } - // }; - - let createSLOInput: CreateSLOInput; - - const createSLO = async (requestOverrides?: Record) => { - return await slo.create({ - ...createSLOInput, - ...requestOverrides, - }); - }; - - before(async () => { - await slo.createUser(); - await slo.deleteAllSLOs(); - await sloEsClient.deleteTestSourceData(); - await loadTestData(getService); - }); - - beforeEach(async () => { - createSLOInput = sloData; - }); - - afterEach(async () => { - await retry.tryForTime(60 * 1000, async () => { - await slo.deleteAllSLOs(); - }); - }); - - after(async () => { - await cleanup({ esClient, logger }); - await sloEsClient.deleteTestSourceData(); - }); - - it('gets slo by id and calculates SLI - occurrences rolling', async () => { - const response = await createSLO({ - groupBy: '*', - }); - const id = response.body.id; - - await retry.tryForTime(300 * 1000, async () => { - const getResponse = await supertestAPI - .get(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send() - .expect(200); - - expect(getResponse.body).toEqual({ - name: 'Test SLO for api integration', - description: 'Fixture for api integration tests', - indicator: { - type: 'sli.kql.custom', - params: { - index: 'kbn-data-forge*', - filter: `system.network.name: eth1`, - good: 'container.cpu.user.pct < 1', - total: 'container.cpu.user.pct: *', - timestampField: '@timestamp', - }, - }, - budgetingMethod: 'occurrences', - timeWindow: { duration: '7d', type: 'rolling' }, - objective: { target: 0.99 }, - tags: ['test'], - groupBy: '*', - groupings: {}, - id, - settings: { syncDelay: '1m', frequency: '1m', preventInitialBackfill: false }, - revision: 1, - enabled: true, - createdAt: getResponse.body.createdAt, - updatedAt: getResponse.body.updatedAt, - version: 2, - instanceId: '*', - meta: {}, - summary: expect.any(Object), - }); - expectSummary(getResponse.body.summary); - }); - }); - - it('gets slo by id and calculates SLI - occurrences calendarAligned', async () => { - const response = await createSLO({ - groupBy: '*', - timeWindow: { - duration: '1w', - type: 'calendarAligned', - }, - }); - const id = response.body.id; - - await retry.tryForTime(300 * 1000, async () => { - const getResponse = await supertestAPI - .get(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send() - .expect(200); - - // expect summary transform to be created - expect(getResponse.body).toEqual({ - name: 'Test SLO for api integration', - description: 'Fixture for api integration tests', - indicator: { - type: 'sli.kql.custom', - params: { - index: 'kbn-data-forge*', - filter: `system.network.name: eth1`, - good: 'container.cpu.user.pct < 1', - total: 'container.cpu.user.pct: *', - timestampField: '@timestamp', - }, - }, - budgetingMethod: 'occurrences', - timeWindow: { duration: '1w', type: 'calendarAligned' }, - objective: { target: 0.99 }, - tags: ['test'], - groupBy: '*', - groupings: {}, - id, - settings: { syncDelay: '1m', frequency: '1m', preventInitialBackfill: false }, - revision: 1, - enabled: true, - createdAt: getResponse.body.createdAt, - updatedAt: getResponse.body.updatedAt, - version: 2, - instanceId: '*', - meta: {}, - summary: expect.any(Object), - }); - expectSummary(getResponse.body.summary); - }); - }); - - it('gets slo by id and calculates SLI - timeslices rolling', async () => { - const response = await createSLO({ - groupBy: '*', - timeWindow: { - duration: '7d', - type: 'rolling', - }, - budgetingMethod: 'timeslices', - objective: { - target: 0.99, - timesliceTarget: 0.95, - timesliceWindow: '1m', - }, - }); - const id = response.body.id; - - await retry.tryForTime(300 * 1000, async () => { - const getResponse = await supertestAPI - .get(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send() - .expect(200); - - // expect summary transform to be created - expect(getResponse.body).toEqual({ - name: 'Test SLO for api integration', - description: 'Fixture for api integration tests', - indicator: { - type: 'sli.kql.custom', - params: { - index: 'kbn-data-forge*', - filter: `system.network.name: eth1`, - good: 'container.cpu.user.pct < 1', - total: 'container.cpu.user.pct: *', - timestampField: '@timestamp', - }, - }, - budgetingMethod: 'timeslices', - timeWindow: { duration: '7d', type: 'rolling' }, - objective: { - target: 0.99, - timesliceTarget: 0.95, - timesliceWindow: '1m', - }, - tags: ['test'], - groupBy: '*', - groupings: {}, - id, - settings: { syncDelay: '1m', frequency: '1m', preventInitialBackfill: false }, - revision: 1, - enabled: true, - createdAt: getResponse.body.createdAt, - updatedAt: getResponse.body.updatedAt, - version: 2, - instanceId: '*', - meta: {}, - summary: expect.any(Object), - }); - expectSummary(getResponse.body.summary); - }); - }); - - it('gets slo by id and calculates SLI - timeslices calendarAligned', async () => { - const response = await createSLO({ - groupBy: '*', - timeWindow: { - duration: '1w', - type: 'calendarAligned', - }, - budgetingMethod: 'timeslices', - objective: { - target: 0.99, - timesliceTarget: 0.95, - timesliceWindow: '10m', - }, - }); - const id = response.body.id; - - await retry.tryForTime(300 * 1000, async () => { - const getResponse = await supertestAPI - .get(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send() - .expect(200); - - expect(getResponse.body).toEqual({ - name: 'Test SLO for api integration', - description: 'Fixture for api integration tests', - indicator: { - type: 'sli.kql.custom', - params: { - index: 'kbn-data-forge*', - filter: `system.network.name: eth1`, - good: 'container.cpu.user.pct < 1', - total: 'container.cpu.user.pct: *', - timestampField: '@timestamp', - }, - }, - budgetingMethod: 'timeslices', - timeWindow: { duration: '1w', type: 'calendarAligned' }, - objective: { - target: 0.99, - timesliceTarget: 0.95, - timesliceWindow: '10m', - }, - tags: ['test'], - groupBy: '*', - groupings: {}, - id, - settings: { syncDelay: '1m', frequency: '1m', preventInitialBackfill: false }, - revision: 1, - enabled: true, - createdAt: getResponse.body.createdAt, - updatedAt: getResponse.body.updatedAt, - version: 2, - instanceId: '*', - meta: {}, - summary: expect.any(Object), - }); - expectSummary(getResponse.body.summary); - }); - }); - - it('gets slos by query', async () => { - await createSLO(); - await createSLO({ name: 'test int' }); - - await retry.tryForTime(360 * 1000, async () => { - const response = await supertestAPI - .get(`/api/observability/slos`) - .set('kbn-xsrf', 'true') - .send() - .expect(200); - - expect(response.body.results.length).toEqual(2); - - const searchResponse = await supertestAPI - .get(`/api/observability/slos?kqlQuery=slo.name%3Aapi*`) - .set('kbn-xsrf', 'true') - .send() - .expect(200); - - expect(searchResponse.body.results.length).toEqual(1); - - const searchResponse2 = await supertestAPI - .get(`/api/observability/slos?kqlQuery=slo.name%3Aint`) - .set('kbn-xsrf', 'true') - .send() - .expect(200); - - expect(searchResponse2.body.results.length).toEqual(1); - - const searchResponse3 = await supertestAPI - .get(`/api/observability/slos?kqlQuery=slo.name%3Aint*`) - .set('kbn-xsrf', 'true') - .send() - .expect(200); - - expect(searchResponse3.body.results.length).toEqual(2); - - const searchResponse4 = await supertestAPI - .get(`/api/observability/slos?kqlQuery=int*`) - .set('kbn-xsrf', 'true') - .send() - .expect(200); - - expect(searchResponse4.body.results.length).toEqual(2); - }); - }); - - // not possible for now to reliably fix this - // it.skip('gets slos instances', async () => { - // const createResponse = await createSLO(); - // const id = createResponse.body.id; - // - // await retry.tryForTime( - // 400 * 1000, - // async () => { - // const response = await supertestAPI - // .get(`/api/observability/slos`) - // .set('kbn-xsrf', 'true') - // .send() - // .expect(200); - // const res = response.body.results; - // expect(res.length).toEqual(3); - // const groups = res.map((r: any) => r.groupings.tags); - // - // expect(groups.sort()).toEqual(['1', '2', '3']); - // - // const instanceResponse = await supertestAPI - // .get(`/internal/observability/slos/${id}/_instances`) - // .set('kbn-xsrf', 'true') - // .send() - // .expect(200); - // - // // expect 3 instances to be created - // expect(instanceResponse.body.groupBy).toEqual('tags'); - // expect(instanceResponse.body.instances.sort()).toEqual(['1', '2', '3']); - // }, - // onFailure, - // 10 * 1000 - // ); - // }); - - it('gets slo definitions', async () => { - const createResponse = await createSLO(); - const id = createResponse.body.id; - const secondCreateResponse = await createSLO({ name: 'test name int' }); - const secondId = secondCreateResponse.body.id; - const response = await slo.getDefinitions(); - - expect(response.body).toEqual({ - page: 1, - perPage: 100, - results: [ - { - budgetingMethod: 'occurrences', - createdAt: response.body.results[0].createdAt, - description: 'Fixture for api integration tests', - enabled: true, - groupBy: 'tags', - id, - indicator: { - params: { - filter: 'system.network.name: eth1', - good: 'container.cpu.user.pct < 1', - index: 'kbn-data-forge*', - timestampField: '@timestamp', - total: 'container.cpu.user.pct: *', - }, - type: 'sli.kql.custom', - }, - name: 'Test SLO for api integration', - objective: { - target: 0.99, - }, - revision: 1, - settings: { - frequency: '1m', - syncDelay: '1m', - preventInitialBackfill: false, - }, - tags: ['test'], - timeWindow: { - duration: '7d', - type: 'rolling', - }, - updatedAt: response.body.results[0].updatedAt, - version: 2, - }, - { - budgetingMethod: 'occurrences', - createdAt: response.body.results[1].createdAt, - description: 'Fixture for api integration tests', - enabled: true, - groupBy: 'tags', - id: secondId, - indicator: { - params: { - filter: 'system.network.name: eth1', - good: 'container.cpu.user.pct < 1', - index: 'kbn-data-forge*', - timestampField: '@timestamp', - total: 'container.cpu.user.pct: *', - }, - type: 'sli.kql.custom', - }, - name: 'test name int', - objective: { - target: 0.99, - }, - revision: 1, - settings: { - frequency: '1m', - syncDelay: '1m', - preventInitialBackfill: false, - }, - tags: ['test'], - timeWindow: { - duration: '7d', - type: 'rolling', - }, - updatedAt: response.body.results[1].updatedAt, - version: 2, - }, - ], - total: 2, - }); - - // can search by name - const searchResponse = await slo.getDefinitions({ search: 'api' }); - - expect(searchResponse.body.total).toEqual(1); - - const searchResponse2 = await supertestAPI - .get(`/api/observability/slos/_definitions?search=int`) - .set('kbn-xsrf', 'true') - .send() - .expect(200); - - expect(searchResponse2.body.total).toEqual(1); - - const searchResponse3 = await supertestAPI - .get(`/api/observability/slos/_definitions?search=int*`) - .set('kbn-xsrf', 'true') - .send() - .expect(200); - - expect(searchResponse3.body.total).toEqual(2); - }); - }); -} diff --git a/x-pack/test/api_integration/apis/slos/index.ts b/x-pack/test/api_integration/apis/slos/index.ts deleted file mode 100644 index 3401b195ccee5..0000000000000 --- a/x-pack/test/api_integration/apis/slos/index.ts +++ /dev/null @@ -1,19 +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 { FtrProviderContext } from '../../ftr_provider_context'; - -export default function ({ loadTestFile }: FtrProviderContext) { - describe('SLO API Tests', () => { - loadTestFile(require.resolve('./get_slo')); - loadTestFile(require.resolve('./create_slo')); - loadTestFile(require.resolve('./delete_slo')); - loadTestFile(require.resolve('./update_slo')); - loadTestFile(require.resolve('./reset_slo')); - loadTestFile(require.resolve('./fetch_historical_summary')); - }); -} diff --git a/x-pack/test/api_integration/apis/slos/reset_slo.ts b/x-pack/test/api_integration/apis/slos/reset_slo.ts deleted file mode 100644 index cccac8f1796be..0000000000000 --- a/x-pack/test/api_integration/apis/slos/reset_slo.ts +++ /dev/null @@ -1,93 +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 { cleanup } from '@kbn/infra-forge'; -import expect from '@kbn/expect'; -import { SO_SLO_TYPE } from '@kbn/slo-plugin/server/saved_objects'; - -import { FtrProviderContext } from '../../ftr_provider_context'; -import { loadTestData } from './helper/load_test_data'; -import { SloEsClient } from './helper/es'; - -export default function ({ getService }: FtrProviderContext) { - describe('Reset SLOs', function () { - this.tags('skipCloud'); - - const kibanaServer = getService('kibanaServer'); - const esClient = getService('es'); - const logger = getService('log'); - const slo = getService('slo'); - const sloEsClient = new SloEsClient(esClient); - - before(async () => { - await sloEsClient.deleteTestSourceData(); - await slo.createUser(); - await slo.deleteAllSLOs(); - await loadTestData(getService); - }); - - afterEach(async () => { - await slo.deleteAllSLOs(); - }); - - after(async () => { - await cleanup({ esClient, logger }); - await sloEsClient.deleteTestSourceData(); - }); - - it('updates the SO and transforms', async () => { - // create mock old SLO - const id = 'bdaeccdd-dc63-4138-a1d5-92c075f88087'; - await kibanaServer.savedObjects.clean({ - types: [SO_SLO_TYPE], - }); - await kibanaServer.savedObjects.create({ - type: SO_SLO_TYPE, - overwrite: true, - id, - attributes: { - name: 'Test SLO for api integration', - description: 'Fixture for api integration tests', - indicator: { - type: 'sli.kql.custom', - params: { - index: 'kbn-data-forge*', - filter: 'system.network.name: eth1', - good: 'container.cpu.user.pct < 1', - total: 'container.cpu.user.pct: *', - timestampField: '@timestamp', - }, - }, - budgetingMethod: 'occurrences', - timeWindow: { duration: '7d', type: 'rolling' }, - objective: { target: 0.99 }, - tags: ['test'], - groupBy: '*', - id, - settings: { - syncDelay: '1m', - frequency: '1m', - }, - revision: 1, - enabled: true, - createdAt: '2023-12-14T01:12:35.638Z', - updatedAt: '2023-12-14T01:12:35.638Z', - version: 1, - }, - }); - - const responseBeforeReset = await slo.getDefinitions(); - - expect(responseBeforeReset.body.results[0].version).eql(1); - - await slo.reset(id); - - const responseAfterReset = await slo.getDefinitions(); - - expect(responseAfterReset.body.results[0].version).eql(2); - }); - }); -} diff --git a/x-pack/test/api_integration/apis/slos/update_slo.ts b/x-pack/test/api_integration/apis/slos/update_slo.ts deleted file mode 100644 index a8f4aa1a334f8..0000000000000 --- a/x-pack/test/api_integration/apis/slos/update_slo.ts +++ /dev/null @@ -1,764 +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 { cleanup } from '@kbn/infra-forge'; -import expect from '@kbn/expect'; -import type { CreateSLOInput } from '@kbn/slo-schema'; -import { SO_SLO_TYPE } from '@kbn/slo-plugin/server/saved_objects'; - -import { FtrProviderContext } from '../../ftr_provider_context'; -import { loadTestData } from './helper/load_test_data'; -import { sloData } from './fixtures/create_slo'; - -export default function ({ getService }: FtrProviderContext) { - describe('UpdateSLOs', function () { - this.tags('skipCloud'); - - const supertestAPI = getService('supertest'); - const kibanaServer = getService('kibanaServer'); - const esClient = getService('es'); - const logger = getService('log'); - const slo = getService('slo'); - - let createSLOInput: CreateSLOInput; - - before(async () => { - await slo.createUser(); - await slo.deleteAllSLOs(); - await loadTestData(getService); - }); - - beforeEach(() => { - createSLOInput = sloData; - }); - - afterEach(async () => { - await slo.deleteAllSLOs(); - }); - - after(async () => { - await cleanup({ esClient, logger }); - }); - - it('updates the SO and transforms', async () => { - const apiResponse = await supertestAPI - .post('/api/observability/slos') - .set('kbn-xsrf', 'true') - .send(createSLOInput) - .expect(200); - - expect(apiResponse.body).property('id'); - - const { id } = apiResponse.body; - - await supertestAPI - .put(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send({ - ...createSLOInput, - groupBy: 'hosts', - }) - .expect(200); - - const savedObject = await kibanaServer.savedObjects.find({ - type: SO_SLO_TYPE, - }); - - expect(savedObject.saved_objects.length).eql(1); - - expect(savedObject.saved_objects[0].attributes).eql({ - budgetingMethod: 'occurrences', - updatedAt: savedObject.saved_objects[0].attributes.updatedAt, - createdAt: savedObject.saved_objects[0].attributes.createdAt, - description: 'Fixture for api integration tests', - enabled: true, - groupBy: 'hosts', - id, - indicator: { - params: { - filter: 'system.network.name: eth1', - good: 'container.cpu.user.pct < 1', - index: 'kbn-data-forge*', - timestampField: '@timestamp', - total: 'container.cpu.user.pct: *', - }, - type: 'sli.kql.custom', - }, - name: 'Test SLO for api integration', - objective: { - target: 0.99, - }, - revision: 2, - settings: { - frequency: '1m', - syncDelay: '1m', - preventInitialBackfill: false, - }, - tags: ['test'], - timeWindow: { - duration: '7d', - type: 'rolling', - }, - version: 2, - }); - - const rollUpTransformResponse = await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-2`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // expect roll up transform to be created - expect(rollUpTransformResponse.body).eql({ - count: 1, - transforms: [ - { - id: `slo-${id}-2`, - authorization: { roles: ['superuser'] }, - version: '10.0.0', - create_time: rollUpTransformResponse.body.transforms[0].create_time, - source: { - index: ['kbn-data-forge*'], - query: { - bool: { - filter: [ - { range: { '@timestamp': { gte: 'now-7d/d' } } }, - { - bool: { - should: [ - { - match: { - 'system.network.name': 'eth1', - }, - }, - ], - minimum_should_match: 1, - }, - }, - { - exists: { - field: 'hosts', - }, - }, - ], - }, - }, - }, - dest: { - index: '.slo-observability.sli-v3.3', - pipeline: `.slo-observability.sli.pipeline-${id}-2`, - }, - frequency: '1m', - sync: { time: { field: '@timestamp', delay: '1m' } }, - pivot: { - group_by: { - 'slo.groupings.hosts': { terms: { field: 'hosts' } }, - '@timestamp': { date_histogram: { field: '@timestamp', fixed_interval: '1m' } }, - }, - aggregations: { - 'slo.numerator': { - filter: { - bool: { - should: [{ range: { 'container.cpu.user.pct': { lt: '1' } } }], - minimum_should_match: 1, - }, - }, - }, - 'slo.denominator': { - filter: { - bool: { - should: [{ exists: { field: 'container.cpu.user.pct' } }], - minimum_should_match: 1, - }, - }, - }, - }, - }, - description: `Rolled-up SLI data for SLO: Test SLO for api integration [id: ${id}, revision: 2]`, - settings: { deduce_mappings: false, unattended: true }, - _meta: { version: 3.3, managed: true, managed_by: 'observability' }, - }, - ], - }); - - const summaryTransform = await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-2`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // expect summary transform to be created - expect(summaryTransform.body).eql({ - count: 1, - transforms: [ - { - id: `slo-summary-${id}-2`, - authorization: { roles: ['superuser'] }, - version: '10.0.0', - create_time: summaryTransform.body.transforms[0].create_time, - source: { - index: ['.slo-observability.sli-v3.3*'], - query: { - bool: { - filter: [ - { range: { '@timestamp': { gte: 'now-7d/m', lte: 'now/m' } } }, - { term: { 'slo.id': id } }, - { term: { 'slo.revision': 2 } }, - ], - }, - }, - }, - dest: { - index: '.slo-observability.summary-v3.3', - pipeline: `.slo-observability.summary.pipeline-${id}-2`, - }, - frequency: '1m', - sync: { time: { field: 'event.ingested', delay: '65s' } }, - pivot: { - group_by: { - 'slo.id': { terms: { field: 'slo.id' } }, - 'slo.revision': { terms: { field: 'slo.revision' } }, - 'slo.instanceId': { terms: { field: 'slo.instanceId' } }, - 'slo.groupings.hosts': { - terms: { field: 'slo.groupings.hosts' }, - }, - 'monitor.config_id': { - terms: { - field: 'monitor.config_id', - missing_bucket: true, - }, - }, - 'monitor.name': { - terms: { - field: 'monitor.name', - missing_bucket: true, - }, - }, - 'observer.geo.name': { - terms: { - field: 'observer.geo.name', - missing_bucket: true, - }, - }, - 'observer.name': { - terms: { - field: 'observer.name', - missing_bucket: true, - }, - }, - 'service.name': { terms: { field: 'service.name', missing_bucket: true } }, - 'service.environment': { - terms: { field: 'service.environment', missing_bucket: true }, - }, - 'transaction.name': { terms: { field: 'transaction.name', missing_bucket: true } }, - 'transaction.type': { terms: { field: 'transaction.type', missing_bucket: true } }, - }, - aggregations: { - goodEvents: { sum: { field: 'slo.numerator' } }, - totalEvents: { sum: { field: 'slo.denominator' } }, - sliValue: { - bucket_script: { - buckets_path: { goodEvents: 'goodEvents', totalEvents: 'totalEvents' }, - script: - 'if (params.totalEvents == 0) { return -1 } else if (params.goodEvents >= params.totalEvents) { return 1 } else { return params.goodEvents / params.totalEvents }', - }, - }, - errorBudgetInitial: { bucket_script: { buckets_path: {}, script: '1 - 0.99' } }, - errorBudgetConsumed: { - bucket_script: { - buckets_path: { - sliValue: 'sliValue', - errorBudgetInitial: 'errorBudgetInitial', - }, - script: - 'if (params.sliValue == -1) { return 0 } else { return (1 - params.sliValue) / params.errorBudgetInitial }', - }, - }, - errorBudgetRemaining: { - bucket_script: { - buckets_path: { errorBudgetConsumed: 'errorBudgetConsumed' }, - script: '1 - params.errorBudgetConsumed', - }, - }, - statusCode: { - bucket_script: { - buckets_path: { - sliValue: 'sliValue', - errorBudgetRemaining: 'errorBudgetRemaining', - }, - script: { - source: - 'if (params.sliValue == -1) { return 0 } else if (params.sliValue >= 0.99) { return 4 } else if (params.errorBudgetRemaining > 0) { return 2 } else { return 1 }', - }, - }, - }, - latestSliTimestamp: { max: { field: '@timestamp' } }, - fiveMinuteBurnRate: { - filter: { - range: { - '@timestamp': { - gte: 'now-480s/m', - lte: 'now-180s/m', - }, - }, - }, - aggs: { - goodEvents: { - sum: { - field: 'slo.numerator', - }, - }, - totalEvents: { - sum: { - field: 'slo.denominator', - }, - }, - }, - }, - oneHourBurnRate: { - filter: { - range: { - '@timestamp': { - gte: 'now-3780s/m', - lte: 'now-180s/m', - }, - }, - }, - aggs: { - goodEvents: { - sum: { - field: 'slo.numerator', - }, - }, - totalEvents: { - sum: { - field: 'slo.denominator', - }, - }, - }, - }, - oneDayBurnRate: { - filter: { - range: { - '@timestamp': { - gte: 'now-86580s/m', - lte: 'now-180s/m', - }, - }, - }, - aggs: { - goodEvents: { - sum: { - field: 'slo.numerator', - }, - }, - totalEvents: { - sum: { - field: 'slo.denominator', - }, - }, - }, - }, - }, - }, - description: `Summarise the rollup data of SLO: Test SLO for api integration [id: ${id}, revision: 2].`, - settings: { deduce_mappings: false, unattended: true }, - _meta: { version: 3.3, managed: true, managed_by: 'observability' }, - }, - ], - }); - }); - - it('updates an existing slo and does not update transforms when relevant fields are changed', async () => { - const request = createSLOInput; - - const apiResponse = await supertestAPI - .post('/api/observability/slos') - .set('kbn-xsrf', 'true') - .send(request) - .expect(200); - - expect(apiResponse.body).property('id'); - - const { id } = apiResponse.body; - - const savedObject = await kibanaServer.savedObjects.find({ - type: SO_SLO_TYPE, - }); - - expect(savedObject.saved_objects.length).eql(1); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // change name - await supertestAPI - .put(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send({ - ...request, - name: 'test name', - }) - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // change description - await supertestAPI - .put(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send({ - ...request, - description: 'test description', - }) - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // change tags - await supertestAPI - .put(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send({ - ...request, - tags: ['testTag'], - }) - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - }); - - it('updates an existing slo and updates transforms when relevant fields are changed', async () => { - const request = createSLOInput; - - const apiResponse = await supertestAPI - .post('/api/observability/slos') - .set('kbn-xsrf', 'true') - .send(request) - .expect(200); - - expect(apiResponse.body).property('id'); - - const { id } = apiResponse.body; - - const savedObject = await kibanaServer.savedObjects.find({ - type: SO_SLO_TYPE, - }); - - expect(savedObject.saved_objects.length).eql(1); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // change group by - await supertestAPI - .put(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send({ - ...request, - groupBy: 'hosts', - }) - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-1`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-2`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-2`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // change indicator - await supertestAPI - .put(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send({ - ...request, - indicator: { - ...request.indicator, - params: { - ...request.indicator.params, - index: 'test-index-*', - }, - }, - }) - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-2`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-2`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-3`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-3`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // change time window - await supertestAPI - .put(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send({ - ...request, - timeWindow: { - ...request.timeWindow, - duration: '7d', - }, - }) - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-3`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-3`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-4`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-4`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // change objective - await supertestAPI - .put(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send({ - ...request, - objective: { - target: 0.97, - }, - }) - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-4`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-4`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-5`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-5`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // change budgetingMethod - await supertestAPI - .put(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send({ - ...request, - budgetingMethod: 'timeslices', - objective: { - target: 0.99, - timesliceTarget: 0.95, - timesliceWindow: '1m', - }, - }) - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-5`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-5`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-6`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-6`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - // change settings - await supertestAPI - .put(`/api/observability/slos/${id}`) - .set('kbn-xsrf', 'true') - .send({ - ...request, - settings: { - frequency: '2m', - syncDelay: '5m', - }, - }) - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-6`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-6`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(404); - - await supertestAPI - .get(`/internal/transform/transforms/slo-${id}-7`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - - await supertestAPI - .get(`/internal/transform/transforms/slo-summary-${id}-7`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '1') - .send() - .expect(200); - }); - }); -} diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/index.ts b/x-pack/test_serverless/api_integration/test_suites/observability/index.ts index 63f8236a335b6..bfe3fd4cbb2c6 100644 --- a/x-pack/test_serverless/api_integration/test_suites/observability/index.ts +++ b/x-pack/test_serverless/api_integration/test_suites/observability/index.ts @@ -15,7 +15,6 @@ export default function ({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./apm_api_integration/service_maps/service_maps')); loadTestFile(require.resolve('./apm_api_integration/traces/critical_path')); loadTestFile(require.resolve('./cases')); - loadTestFile(require.resolve('./slos')); loadTestFile(require.resolve('./synthetics')); loadTestFile(require.resolve('./dataset_quality_api_integration')); }); diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/slos/create_slo.ts b/x-pack/test_serverless/api_integration/test_suites/observability/slos/create_slo.ts deleted file mode 100644 index 93aaa77e4e215..0000000000000 --- a/x-pack/test_serverless/api_integration/test_suites/observability/slos/create_slo.ts +++ /dev/null @@ -1,371 +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 { cleanup, generate } from '@kbn/infra-forge'; -import expect from '@kbn/expect'; -import type { GetTransformsResponseSchema } from '@kbn/transform-plugin/server/routes/api_schemas/transforms'; -import { SO_SLO_TYPE } from '@kbn/slo-plugin/server/saved_objects'; -import { ALL_VALUE } from '@kbn/slo-schema'; -import { - getSLOPipelineId, - getSLOSummaryPipelineId, - SLO_SUMMARY_TEMP_INDEX_NAME, -} from '@kbn/slo-plugin/common/constants'; -import type { RoleCredentials } from '../../../../shared/services'; -import { FtrProviderContext } from '../../../ftr_provider_context'; - -interface ExpectedTransforms { - count: number; - typeOfVersion: string; - typeOfCreateTime: string; - results: Record; -} - -function assertTransformsResponseBody( - body: GetTransformsResponseSchema, - expectedTransforms: ExpectedTransforms -) { - expect(body.count).to.eql(expectedTransforms.count); - expect(body.transforms).to.have.length(expectedTransforms.count); - - body.transforms.forEach((transform, index) => { - const expectedTransform = expectedTransforms.results[`transform${index}`]; - expect(transform.id).to.eql(expectedTransform.id); - expect(transform.dest.index).to.eql(expectedTransform.destIndex); - expect(typeof transform.version).to.eql(expectedTransforms.typeOfVersion); - expect(typeof transform.create_time).to.eql(expectedTransforms.typeOfCreateTime); - }); -} - -export default function ({ getService }: FtrProviderContext) { - const esClient = getService('es'); - const supertest = getService('supertest'); - - const esDeleteAllIndices = getService('esDeleteAllIndices'); - const logger = getService('log'); - const dataViewApi = getService('dataViewApi'); - const sloApi = getService('sloApi'); - const kibanaServer = getService('kibanaServer'); - const transform = getService('transform'); - const svlUserManager = getService('svlUserManager'); - const svlCommonApi = getService('svlCommonApi'); - - describe('create_slo', () => { - // DATE_VIEW should match the index template: - // x-pack/packages/kbn-infra-forge/src/data_sources/composable/template.json - const DATE_VIEW = 'kbn-data-forge-fake_hosts'; - const DATA_VIEW_ID = 'data-view-id'; - let infraDataIndex: string; - let roleAuthc: RoleCredentials; - - before(async () => { - infraDataIndex = await generate({ - esClient, - lookback: 'now-15m', - logger, - }); - await dataViewApi.create({ - name: DATE_VIEW, - id: DATA_VIEW_ID, - title: DATE_VIEW, - }); - await kibanaServer.savedObjects.cleanStandardList(); - roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin'); - }); - - after(async () => { - await dataViewApi.delete({ - id: DATA_VIEW_ID, - }); - await supertest - .delete('/api/observability/slos/my-custom-id1') - .set(svlCommonApi.getInternalRequestHeader()); - - await supertest - .delete('/api/observability/slos/my-custom-id2') - .set(svlCommonApi.getInternalRequestHeader()); - - await supertest - .delete('/api/observability/slos/my-custom-id3') - .set(svlCommonApi.getInternalRequestHeader()); - - await supertest - .delete('/api/observability/slos/my-custom-id4') - .set(svlCommonApi.getInternalRequestHeader()); - - await esDeleteAllIndices([infraDataIndex]); - await cleanup({ esClient, logger }); - await kibanaServer.savedObjects.clean({ types: [SO_SLO_TYPE] }); - await transform.api.cleanTransformIndices(); - await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc); - }); - - describe('non partition by SLO', () => { - const sloId = 'my-custom-id1'; - - before(async () => { - await sloApi.create( - { - id: sloId, - name: 'my custom name', - description: 'my custom description', - indicator: { - type: 'sli.kql.custom', - params: { - index: infraDataIndex, - good: 'system.cpu.total.norm.pct > 1', - total: 'system.cpu.total.norm.pct: *', - timestampField: '@timestamp', - }, - }, - timeWindow: { - duration: '7d', - type: 'rolling', - }, - budgetingMethod: 'occurrences', - objective: { - target: 0.999, - }, - groupBy: ALL_VALUE, - }, - roleAuthc - ); - }); - - it('saves the SLO definition', async () => { - const savedObject = await kibanaServer.savedObjects.find({ - type: SO_SLO_TYPE, - }); - expect(savedObject.total).to.eql(1); - expect(savedObject.saved_objects[0].attributes.version).eql(2); - expect(savedObject.saved_objects[0].attributes.revision).eql(1); - }); - - it('creates the rollup and summary transforms', async () => { - const expectedTransforms: ExpectedTransforms = { - count: 2, - results: { - transform0: { id: 'slo-my-custom-id1-1', destIndex: '.slo-observability.sli-v3.3' }, - transform1: { - id: 'slo-summary-my-custom-id1-1', - destIndex: '.slo-observability.summary-v3.3', - }, - }, - typeOfVersion: 'string', - typeOfCreateTime: 'number', - }; - const { body, status } = await supertest - .get(`/internal/transform/transforms`) - .set('kbn-xsrf', 'foo') - .set('x-elastic-internal-origin', 'foo') - .set('elastic-api-version', '1') - .set(roleAuthc.apiKeyHeader) - .send(); - transform.api.assertResponseStatusCode(200, status, body); - assertTransformsResponseBody(body, expectedTransforms); - }); - - it('creates ingest pipelines', async () => { - const sloRevision = 1; - const rollupPipelineResponse = await esClient.ingest.getPipeline({ - id: getSLOPipelineId(sloId, sloRevision), - }); - const expectedRollupPipeline = `.slo-observability.sli.pipeline-${sloId}-${sloRevision}`; - expect(rollupPipelineResponse[expectedRollupPipeline]).not.to.be(undefined); - - const summaryPipelineResponse = await esClient.ingest.getPipeline({ - id: getSLOSummaryPipelineId(sloId, sloRevision), - }); - const expectedSummaryPipeline = `.slo-observability.summary.pipeline-${sloId}-${sloRevision}`; - expect(summaryPipelineResponse[expectedSummaryPipeline]).not.to.be(undefined); - expect(summaryPipelineResponse[expectedSummaryPipeline].description).to.be( - `Ingest pipeline for SLO summary data [id: ${sloId}, revision: ${sloRevision}]` - ); - }); - - it('creates summary TEMP index', async () => { - const result = await sloApi.waitForSloSummaryTempIndexToExist(SLO_SUMMARY_TEMP_INDEX_NAME); - expect(result).to.be(true); - }); - - it('finds the created SLO', async () => { - const createdSlo = await sloApi.waitForSloCreated({ - sloId, - roleAuthc, - }); - expect(createdSlo.id).to.be(sloId); - expect(createdSlo.groupBy).to.be(ALL_VALUE); - }); - }); - - describe('SLO with long description', () => { - it('creates an SLO with description over 256 characters', async () => { - const sloId = 'my-custom-id2'; - await sloApi.create( - { - id: sloId, - name: 'my super long SLO name and description', - description: - 'Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. ', - indicator: { - type: 'sli.kql.custom', - params: { - index: infraDataIndex, - good: 'system.cpu.total.norm.pct > 1', - total: 'system.cpu.total.norm.pct: *', - timestampField: '@timestamp', - }, - }, - timeWindow: { - duration: '7d', - type: 'rolling', - }, - budgetingMethod: 'occurrences', - objective: { - target: 0.999, - }, - groupBy: '*', - }, - roleAuthc - ); - - const createdSlo = await sloApi.waitForSloCreated({ - sloId, - roleAuthc, - }); - expect(createdSlo.id).to.be(sloId); - }); - }); - - describe('SLO with special characters in the description', () => { - it("creates an SLO that has ' character in the description", async () => { - const sloId = 'my-custom-id3'; - await sloApi.create( - { - id: sloId, - name: 'my SLO with weird characters in the description', - description: - "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.", - indicator: { - type: 'sli.kql.custom', - params: { - index: infraDataIndex, - good: 'system.cpu.total.norm.pct > 1', - total: 'system.cpu.total.norm.pct: *', - timestampField: '@timestamp', - }, - }, - timeWindow: { - duration: '7d', - type: 'rolling', - }, - budgetingMethod: 'occurrences', - objective: { - target: 0.999, - }, - groupBy: '*', - }, - roleAuthc - ); - const createdSlo = await sloApi.waitForSloCreated({ - sloId, - roleAuthc, - }); - expect(createdSlo.id).to.be(sloId); - }); - }); - - describe('partition by SLO', () => { - it('creates a partition by SLO', async () => { - const sloId = 'my-custom-id4'; - await sloApi.create( - { - id: sloId, - name: 'Group by SLO', - description: 'This is a group by SLO.', - indicator: { - type: 'sli.kql.custom', - params: { - index: infraDataIndex, - good: 'system.cpu.total.norm.pct > 1', - total: 'system.cpu.total.norm.pct: *', - timestampField: '@timestamp', - }, - }, - timeWindow: { - duration: '7d', - type: 'rolling', - }, - budgetingMethod: 'occurrences', - objective: { - target: 0.999, - }, - groupBy: 'host.name', - }, - roleAuthc - ); - const createdSlo = await sloApi.waitForSloCreated({ - sloId, - roleAuthc, - }); - expect(createdSlo.id).to.be(sloId); - expect(createdSlo.groupBy).not.to.be(ALL_VALUE); - expect(createdSlo.groupBy).to.be('host.name'); - }); - }); - - describe('Total transforms', () => { - it('returns all the transforms for above created SLOs', async () => { - const expectedTransforms: ExpectedTransforms = { - count: 8, - results: { - transform0: { id: 'slo-my-custom-id1-1', destIndex: '.slo-observability.sli-v3.3' }, - transform1: { id: 'slo-my-custom-id2-1', destIndex: '.slo-observability.sli-v3.3' }, - transform2: { id: 'slo-my-custom-id3-1', destIndex: '.slo-observability.sli-v3.3' }, - transform3: { id: 'slo-my-custom-id4-1', destIndex: '.slo-observability.sli-v3.3' }, - transform4: { - id: 'slo-summary-my-custom-id1-1', - destIndex: '.slo-observability.summary-v3.3', - }, - transform5: { - id: 'slo-summary-my-custom-id2-1', - destIndex: '.slo-observability.summary-v3.3', - }, - transform6: { - id: 'slo-summary-my-custom-id3-1', - destIndex: '.slo-observability.summary-v3.3', - }, - transform7: { - id: 'slo-summary-my-custom-id4-1', - destIndex: '.slo-observability.summary-v3.3', - }, - }, - typeOfVersion: 'string', - typeOfCreateTime: 'number', - }; - const { body, status } = await supertest - .get(`/internal/transform/transforms`) - .set('kbn-xsrf', 'foo') - .set('x-elastic-internal-origin', 'foo') - .set('elastic-api-version', '1') - .set(roleAuthc.apiKeyHeader) - .send(); - transform.api.assertResponseStatusCode(200, status, body); - assertTransformsResponseBody(body, expectedTransforms); - }); - }); - - describe('Total SO definitions', () => { - it('returns SO definitions for above created SLOs', async () => { - const savedObject = await kibanaServer.savedObjects.find({ - type: SO_SLO_TYPE, - }); - expect(savedObject.total).to.eql(4); - }); - }); - }); -} diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/slos/delete_slo.ts b/x-pack/test_serverless/api_integration/test_suites/observability/slos/delete_slo.ts deleted file mode 100644 index c33bde45e1720..0000000000000 --- a/x-pack/test_serverless/api_integration/test_suites/observability/slos/delete_slo.ts +++ /dev/null @@ -1,175 +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 { SO_SLO_TYPE } from '@kbn/slo-plugin/server/saved_objects'; -import { cleanup, generate } from '@kbn/infra-forge'; -import expect from '@kbn/expect'; -import { ALL_VALUE } from '@kbn/slo-schema'; -import { - getSLOSummaryTransformId, - getSLOTransformId, - getSLOSummaryPipelineId, -} from '@kbn/slo-plugin/common/constants'; -import { - SLO_DESTINATION_INDEX_PATTERN, - SLO_SUMMARY_DESTINATION_INDEX_PATTERN, -} from '@kbn/slo-plugin/common/constants'; -import type { RoleCredentials } from '../../../../shared/services'; -import { FtrProviderContext } from '../../../ftr_provider_context'; - -export default function ({ getService }: FtrProviderContext) { - const esClient = getService('es'); - const logger = getService('log'); - const kibanaServer = getService('kibanaServer'); - const sloApi = getService('sloApi'); - const transform = getService('transform'); - const retry = getService('retry'); - - const esDeleteAllIndices = getService('esDeleteAllIndices'); - const dataViewApi = getService('dataViewApi'); - const svlUserManager = getService('svlUserManager'); - - const fetchSloSummaryPipeline = async (sloId: string, sloRevision: number) => { - try { - return await esClient.ingest.getPipeline({ - id: getSLOSummaryPipelineId(sloId, sloRevision), - }); - } catch (error) { - // The GET /_ingest/pipeline API returns an empty object on 404 Not Found. If there are no SLO - // pipelines then return an empty record of pipelines - return {}; - } - }; - - describe('delete_slo', () => { - // DATE_VIEW should match the index template: - // x-pack/packages/kbn-infra-forge/src/data_sources/composable/template.json - const DATE_VIEW = 'kbn-data-forge-fake_hosts'; - const DATA_VIEW_ID = 'data-view-id'; - let infraDataIndex: string; - let sloId: string; - let roleAuthc: RoleCredentials; - - before(async () => { - await sloApi.deleteAllSLOs(); - - infraDataIndex = await generate({ - esClient, - lookback: 'now-15m', - logger, - }); - await dataViewApi.create({ - name: DATE_VIEW, - id: DATA_VIEW_ID, - title: DATE_VIEW, - }); - await kibanaServer.savedObjects.cleanStandardList(); - roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin'); - }); - - after(async () => { - await dataViewApi.delete({ - id: DATA_VIEW_ID, - }); - await sloApi.deleteAllSLOs(); - await esDeleteAllIndices([infraDataIndex]); - await cleanup({ esClient, logger }); - await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc); - }); - - describe('non partition by SLO', () => { - it('deletes the SLO definition, transforms, ingest pipeline and data', async () => { - const createdSlo = await sloApi.create( - { - name: 'my custom name', - description: 'my custom description', - indicator: { - type: 'sli.kql.custom', - params: { - index: infraDataIndex, - good: 'system.cpu.total.norm.pct > 1', - total: 'system.cpu.total.norm.pct: *', - timestampField: '@timestamp', - }, - }, - timeWindow: { - duration: '7d', - type: 'rolling', - }, - budgetingMethod: 'occurrences', - objective: { - target: 0.999, - }, - groupBy: ALL_VALUE, - }, - roleAuthc - ); - sloId = createdSlo.id; - await sloApi.waitForSloCreated({ sloId, roleAuthc }); - - // Saved Object - const savedObject = await kibanaServer.savedObjects.find({ - type: SO_SLO_TYPE, - }); - expect(savedObject.total).to.eql(1); - expect(savedObject.saved_objects[0].attributes.id).to.eql(sloId); - const sloRevision = savedObject.saved_objects[0].attributes.revision ?? 1; - - // Transforms - const sloTransformId = getSLOTransformId(sloId, sloRevision); - const sloSummaryTransformId = getSLOSummaryTransformId(sloId, sloRevision); - await transform.api.waitForTransformToExist(sloTransformId); - await transform.api.waitForTransformToExist(sloSummaryTransformId); - - // Ingest pipeline - const pipelineResponse = await fetchSloSummaryPipeline(sloId, sloRevision); - expect(pipelineResponse[getSLOSummaryPipelineId(sloId, sloRevision)]).not.to.be(undefined); - - // RollUp and Summary data - const sloRollupData = await sloApi.waitForSloData({ - sloId, - indexName: SLO_DESTINATION_INDEX_PATTERN, - }); - const sloSummaryData = await sloApi.waitForSloData({ - sloId, - indexName: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, - }); - - expect(sloRollupData.hits.hits.length > 0).to.be(true); - expect(sloSummaryData.hits.hits.length > 0).to.be(true); - - // Delete the SLO - const response = await sloApi.waitForSloToBeDeleted({ - sloId, - roleAuthc, - }); - expect(response.status).to.be(204); - - // Saved object definition - const savedObjectAfterDelete = await kibanaServer.savedObjects.find({ - type: SO_SLO_TYPE, - }); - expect(savedObjectAfterDelete.total).to.eql(0); - - // Transforms - await transform.api.getTransform(sloTransformId, 404); - await transform.api.getTransform(sloSummaryTransformId, 404); - - await retry.waitForWithTimeout('SLO summary data is deleted', 60 * 1000, async () => { - const sloSummaryDataAfterDeletion = await sloApi.getSloData({ - sloId, - indexName: SLO_SUMMARY_DESTINATION_INDEX_PATTERN, - }); - if (sloSummaryDataAfterDeletion.hits.hits.length > 0) { - throw new Error('SLO summary data not deleted yet'); - } - return true; - }); - }); - }); - }); -} diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/slos/fetch_historical_summary.ts b/x-pack/test_serverless/api_integration/test_suites/observability/slos/fetch_historical_summary.ts deleted file mode 100644 index 2f8db3098fccf..0000000000000 --- a/x-pack/test_serverless/api_integration/test_suites/observability/slos/fetch_historical_summary.ts +++ /dev/null @@ -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 expect from '@kbn/expect'; -import { - SLO_DESTINATION_INDEX_NAME, - SLO_DESTINATION_INDEX_PATTERN, -} from '@kbn/slo-plugin/common/constants'; - -import { ALL_VALUE } from '@kbn/slo-schema'; -import moment from 'moment'; -import { RoleCredentials } from '../../../../shared/services'; -import { FtrProviderContext } from '../../../ftr_provider_context'; - -export default function ({ getService }: FtrProviderContext) { - const esClient = getService('es'); - const esDeleteAllIndices = getService('esDeleteAllIndices'); - const sloApi = getService('sloApi'); - const svlUserManager = getService('svlUserManager'); - - const SLO_ID = 'slo-fake-1'; - describe('fetch historical summary', () => { - let roleAuthc: RoleCredentials; - - before(async () => { - const now = moment().startOf('minute'); - const curr = now.clone().subtract(30, 'days'); - const end = now.clone().add(5, 'minutes'); - - const batchOperations = []; - - while (curr.isSameOrBefore(end)) { - batchOperations.push([ - { index: { _index: SLO_DESTINATION_INDEX_NAME } }, - { - '@timestamp': curr.toISOString(), - slo: { - id: SLO_ID, - revision: 1, - instanceId: ALL_VALUE, - numerator: 90, - denominator: 100, - isGoodSlice: 1, - groupings: {}, - }, - }, - ]); - curr.add(1, 'minute'); - } - - await esClient.bulk({ - index: SLO_DESTINATION_INDEX_NAME, - operations: batchOperations.flat(), - refresh: 'wait_for', - }); - - await esClient.indices.refresh({ index: SLO_DESTINATION_INDEX_NAME }); - roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin'); - }); - - after(async () => { - await esDeleteAllIndices(SLO_DESTINATION_INDEX_PATTERN); - await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc); - }); - - it('computes the historical summary for a rolling occurrences SLO', async () => { - const response = await sloApi.fetchHistoricalSummary( - { - list: [ - { - sloId: SLO_ID, - instanceId: ALL_VALUE, - timeWindow: { - duration: '7d', - type: 'rolling', - }, - budgetingMethod: 'occurrences', - objective: { - target: 0.9, - }, - groupBy: ALL_VALUE, - revision: 1, - }, - ], - }, - roleAuthc - ); - expect(response[0].sloId).to.eql(SLO_ID); - expect(response[0].instanceId).to.eql(ALL_VALUE); - const numberOfBuckets = response[0].data.length; - expect(numberOfBuckets).to.be.within(168, 170); // 7 days * 24 hours/day * 1 bucket/hour + 2 extra bucket due to histogram agg rounding - const last = response[0].data.pop(); - expect(last?.errorBudget).to.eql({ - consumed: 1, - initial: 0.1, - isEstimated: false, - remaining: 0, - }); - expect(last?.sliValue).to.eql(0.9); - expect(last?.status).to.eql('HEALTHY'); - }); - - it('computes the historical summary for a rolling timeslices SLO', async () => { - const response = await sloApi.fetchHistoricalSummary( - { - list: [ - { - sloId: SLO_ID, - instanceId: ALL_VALUE, - timeWindow: { - duration: '7d', - type: 'rolling', - }, - budgetingMethod: 'timeslices', - objective: { - target: 0.9, - timesliceTarget: 0.8, - timesliceWindow: '1m', - }, - groupBy: ALL_VALUE, - revision: 1, - }, - ], - }, - roleAuthc - ); - expect(response[0].sloId).to.eql(SLO_ID); - expect(response[0].instanceId).to.eql(ALL_VALUE); - const numberOfBuckets = response[0].data.length; - expect(numberOfBuckets).to.be.within(168, 170); // 7 days * 24 hours/day * 1 bucket/hour + 2 extra bucket due to histogram agg rounding - const last = response[0].data.pop(); - expect(last?.errorBudget).to.eql({ - consumed: 0, - initial: 0.1, - isEstimated: false, - remaining: 1, - }); - expect(last?.sliValue).to.eql(1); - expect(last?.status).to.eql('HEALTHY'); - }); - }); -} diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/slos/index.ts b/x-pack/test_serverless/api_integration/test_suites/observability/slos/index.ts deleted file mode 100644 index 8df59e6f3b624..0000000000000 --- a/x-pack/test_serverless/api_integration/test_suites/observability/slos/index.ts +++ /dev/null @@ -1,15 +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 { FtrProviderContext } from '../../../ftr_provider_context'; - -export default function ({ loadTestFile }: FtrProviderContext) { - describe('SLOs', function () { - loadTestFile(require.resolve('./create_slo')); - loadTestFile(require.resolve('./delete_slo')); - loadTestFile(require.resolve('./fetch_historical_summary')); - }); -} diff --git a/x-pack/test_serverless/tsconfig.json b/x-pack/test_serverless/tsconfig.json index e0abb7fb14819..fc52752b513b2 100644 --- a/x-pack/test_serverless/tsconfig.json +++ b/x-pack/test_serverless/tsconfig.json @@ -76,7 +76,6 @@ "@kbn/ftr-common-functional-ui-services", "@kbn/saved-objects-management-plugin", "@kbn/es", - "@kbn/infra-forge", "@kbn/reporting-common", "@kbn/es-query", "@kbn/slo-plugin",