From f6567f4fdb011aa17f483c4091625d85a2269c98 Mon Sep 17 00:00:00 2001 From: Carlos Crespo Date: Tue, 29 Oct 2024 17:51:41 +0100 Subject: [PATCH] Make infra API tests deployment agnostic --- .github/CODEOWNERS | 4 +- .../api_integration/apis/logs_ui/index.ts | 3 + ...analysis_validation_log_entry_datasets.ts} | 0 .../log_entry_highlights.ts | 0 .../{metrics_ui => logs_ui}/log_summary.ts | 0 .../api_integration/apis/metrics_ui/config.ts | 16 --- .../apis/metrics_ui/helpers.ts | 87 ------------ .../apis/metrics_ui/http_source.ts | 61 -------- .../apis/metrics_ui/ip_to_hostname.ts | 45 ------ .../apis/metrics_ui/metrics_alerting.ts | 130 ----------------- .../apis/observability/infra/index.ts} | 14 +- .../apis/observability/infra}/infra.ts | 59 ++++---- .../observability/infra/infra_asset_count.ts} | 53 ++++--- .../infra}/infra_custom_dashboards.ts | 76 +++++----- .../infra}/inventory_threshold_alert.ts | 8 +- .../observability/infra/ip_to_hostname.ts | 51 +++++++ .../apis/observability/infra}/metadata.ts | 52 ++++--- .../infra}/metric_threshold_alert.ts | 130 ++++++++++++++++- .../observability/infra}/metrics_explorer.ts | 11 +- .../infra}/metrics_overview_top.ts | 33 +++-- .../infra}/metrics_process_list.ts | 30 ++-- .../infra}/metrics_process_list_chart.ts | 29 ++-- .../apis/observability/infra/node_details.ts} | 30 ++-- .../apis/observability/infra}/services.ts | 111 +++++++++++++-- .../apis/observability/infra}/snapshot.ts | 47 ++++--- .../apis/observability/infra}/sources.ts | 99 +++++++------ .../observability/infra/utils}/constants.ts | 0 .../infra/utils}/create_fake_logger.ts | 0 .../configs/serverless/oblt.index.ts | 1 + .../serverless/oblt.serverless.config.ts | 1 + .../configs/stateful/oblt.index.ts | 1 + .../services/apm_synthtrace_kibana_client.ts | 4 +- .../deployment_agnostic/services/index.ts | 2 + .../services/role_scoped_supertest.ts | 6 +- x-pack/test/common/services/index.ts | 2 - .../es_archives/infra/alerts/mappings.json | 12 -- .../observability/config.feature_flags.ts | 1 - .../observability/index.feature_flags.ts | 1 - .../observability/infra/constants.ts | 19 --- .../test_suites/observability/infra/index.ts | 22 --- .../test_suites/observability/infra/infra.ts | 129 ----------------- .../observability/infra/metadata.ts | 132 ------------------ .../observability/infra/processes.ts | 67 --------- .../observability/infra/snapshot.ts | 91 ------------ 44 files changed, 604 insertions(+), 1066 deletions(-) rename x-pack/test/api_integration/apis/{metrics_ui/infra_log_analysis_validation_log_entry_datasets.ts => logs_ui/log_analysis_validation_log_entry_datasets.ts} (100%) rename x-pack/test/api_integration/apis/{metrics_ui => logs_ui}/log_entry_highlights.ts (100%) rename x-pack/test/api_integration/apis/{metrics_ui => logs_ui}/log_summary.ts (100%) delete mode 100644 x-pack/test/api_integration/apis/metrics_ui/config.ts delete mode 100644 x-pack/test/api_integration/apis/metrics_ui/helpers.ts delete mode 100644 x-pack/test/api_integration/apis/metrics_ui/http_source.ts delete mode 100644 x-pack/test/api_integration/apis/metrics_ui/ip_to_hostname.ts delete mode 100644 x-pack/test/api_integration/apis/metrics_ui/metrics_alerting.ts rename x-pack/test/api_integration/{apis/metrics_ui/index.js => deployment_agnostic/apis/observability/infra/index.ts} (69%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra}/infra.ts (89%) rename x-pack/{test_serverless/api_integration/test_suites/observability/infra/asset_count.ts => test/api_integration/deployment_agnostic/apis/observability/infra/infra_asset_count.ts} (64%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra}/infra_custom_dashboards.ts (84%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra}/inventory_threshold_alert.ts (98%) create mode 100644 x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/ip_to_hostname.ts rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra}/metadata.ts (88%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra}/metric_threshold_alert.ts (90%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra}/metrics_explorer.ts (96%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra}/metrics_overview_top.ts (73%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra}/metrics_process_list.ts (58%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra}/metrics_process_list_chart.ts (58%) rename x-pack/test/api_integration/{apis/metrics_ui/metrics.ts => deployment_agnostic/apis/observability/infra/node_details.ts} (77%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra}/services.ts (56%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra}/snapshot.ts (95%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra}/sources.ts (70%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra/utils}/constants.ts (100%) rename x-pack/test/api_integration/{apis/metrics_ui => deployment_agnostic/apis/observability/infra/utils}/create_fake_logger.ts (100%) rename x-pack/test/{common => api_integration/deployment_agnostic}/services/apm_synthtrace_kibana_client.ts (90%) delete mode 100644 x-pack/test_serverless/api_integration/test_suites/observability/infra/constants.ts delete mode 100644 x-pack/test_serverless/api_integration/test_suites/observability/infra/index.ts delete mode 100644 x-pack/test_serverless/api_integration/test_suites/observability/infra/infra.ts delete mode 100644 x-pack/test_serverless/api_integration/test_suites/observability/infra/metadata.ts delete mode 100644 x-pack/test_serverless/api_integration/test_suites/observability/infra/processes.ts delete mode 100644 x-pack/test_serverless/api_integration/test_suites/observability/infra/snapshot.ts diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1451c647f658e..512b4e114a9a4 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1023,7 +1023,6 @@ packages/kbn-zod-helpers @elastic/security-detection-rule-management # The #CC# prefix delineates Code Coverage, # used for the 'team' designator within Kibana Stats -/x-pack/test/api_integration/apis/metrics_ui @elastic/obs-ux-logs-team @elastic/obs-ux-infra_services-team x-pack/test_serverless/api_integration/test_suites/common/platform_security @elastic/kibana-security # Observability Entities Team (@elastic/obs-entities) @@ -1151,7 +1150,7 @@ x-pack/test/observability_ai_assistant_api_integration @elastic/obs-ai-assistant x-pack/test/observability_ai_assistant_functional @elastic/obs-ai-assistant x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai-assistant -# Infra Monitoring +# Infra Obs ## This plugin mostly contains the codebase for the infra services, but also includes some code for the Logs UI app. ## To keep @elastic/obs-ux-logs-team as codeowner of the plugin manifest without requiring a review for all the other code changes ## the priority on codeownership will be as follow: @@ -1181,6 +1180,7 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai /x-pack/plugins/observability_solution/infra/server/services @elastic/obs-ux-infra_services-team /x-pack/plugins/observability_solution/infra/server/usage @elastic/obs-ux-infra_services-team /x-pack/plugins/observability_solution/infra/server/utils @elastic/obs-ux-infra_services-team +/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra @elastic/obs-ux-logs-team ## Logs UI code exceptions -> @elastic/obs-ux-logs-team /x-pack/test_serverless/functional/page_objects/svl_oblt_onboarding_stream_log_file.ts @elastic/obs-ux-logs-team diff --git a/x-pack/test/api_integration/apis/logs_ui/index.ts b/x-pack/test/api_integration/apis/logs_ui/index.ts index 625ff24ce25cd..694698d41f3b6 100644 --- a/x-pack/test/api_integration/apis/logs_ui/index.ts +++ b/x-pack/test/api_integration/apis/logs_ui/index.ts @@ -11,5 +11,8 @@ export default function ({ loadTestFile }: FtrProviderContext) { describe('Logs UI routes', () => { loadTestFile(require.resolve('./log_views')); loadTestFile(require.resolve('./log_threshold_alert')); + loadTestFile(require.resolve('./log_entry_highlights')); + loadTestFile(require.resolve('./log_summary')); + loadTestFile(require.resolve('./log_analysis_validation_log_entry_datasets')); }); } diff --git a/x-pack/test/api_integration/apis/metrics_ui/infra_log_analysis_validation_log_entry_datasets.ts b/x-pack/test/api_integration/apis/logs_ui/log_analysis_validation_log_entry_datasets.ts similarity index 100% rename from x-pack/test/api_integration/apis/metrics_ui/infra_log_analysis_validation_log_entry_datasets.ts rename to x-pack/test/api_integration/apis/logs_ui/log_analysis_validation_log_entry_datasets.ts diff --git a/x-pack/test/api_integration/apis/metrics_ui/log_entry_highlights.ts b/x-pack/test/api_integration/apis/logs_ui/log_entry_highlights.ts similarity index 100% rename from x-pack/test/api_integration/apis/metrics_ui/log_entry_highlights.ts rename to x-pack/test/api_integration/apis/logs_ui/log_entry_highlights.ts diff --git a/x-pack/test/api_integration/apis/metrics_ui/log_summary.ts b/x-pack/test/api_integration/apis/logs_ui/log_summary.ts similarity index 100% rename from x-pack/test/api_integration/apis/metrics_ui/log_summary.ts rename to x-pack/test/api_integration/apis/logs_ui/log_summary.ts diff --git a/x-pack/test/api_integration/apis/metrics_ui/config.ts b/x-pack/test/api_integration/apis/metrics_ui/config.ts deleted file mode 100644 index c737db9499836..0000000000000 --- a/x-pack/test/api_integration/apis/metrics_ui/config.ts +++ /dev/null @@ -1,16 +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('.')], - }; -} diff --git a/x-pack/test/api_integration/apis/metrics_ui/helpers.ts b/x-pack/test/api_integration/apis/metrics_ui/helpers.ts deleted file mode 100644 index 427909e10ac94..0000000000000 --- a/x-pack/test/api_integration/apis/metrics_ui/helpers.ts +++ /dev/null @@ -1,87 +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 { apm, timerange } from '@kbn/apm-synthtrace-client'; - -// generates traces, metrics for services -export function generateServicesData({ - from, - to, - instanceCount = 1, - servicesPerHost = 1, -}: { - from: string; - to: string; - instanceCount?: number; - servicesPerHost?: number; -}) { - const range = timerange(from, to); - const services = Array(instanceCount) - .fill(null) - .flatMap((_, hostIdx) => - Array(servicesPerHost) - .fill(null) - .map((__, serviceIdx) => - apm - .service({ - name: `service-${hostIdx}-${serviceIdx}`, - environment: 'production', - agentName: 'nodejs', - }) - .instance(`host-${hostIdx}`) - ) - ); - return range - .interval('1m') - .rate(1) - .generator((timestamp, index) => - services.map((service) => - service - .transaction({ transactionName: 'GET /foo' }) - .timestamp(timestamp) - .duration(500) - .success() - ) - ); -} -// generates error logs only for services -export function generateServicesLogsOnlyData({ - from, - to, - instanceCount = 1, - servicesPerHost = 1, -}: { - from: string; - to: string; - instanceCount?: number; - servicesPerHost?: number; -}) { - const range = timerange(from, to); - const services = Array(instanceCount) - .fill(null) - .flatMap((_, hostIdx) => - Array(servicesPerHost) - .fill(null) - .map((__, serviceIdx) => - apm - .service({ - name: `service-${hostIdx}-${serviceIdx}`, - environment: 'production', - agentName: 'go', - }) - .instance(`host-${hostIdx}`) - ) - ); - return range - .interval('1m') - .rate(1) - .generator((timestamp, index) => - services.map((service) => - service.error({ message: 'error', type: 'My Type' }).timestamp(timestamp) - ) - ); -} diff --git a/x-pack/test/api_integration/apis/metrics_ui/http_source.ts b/x-pack/test/api_integration/apis/metrics_ui/http_source.ts deleted file mode 100644 index 1b298d79b8aa1..0000000000000 --- a/x-pack/test/api_integration/apis/metrics_ui/http_source.ts +++ /dev/null @@ -1,61 +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 { SourceResponse } from '@kbn/infra-plugin/server/lib/sources'; -import { FtrProviderContext } from '../../ftr_provider_context'; - -export default function ({ getService }: FtrProviderContext) { - const esArchiver = getService('esArchiver'); - const supertest = getService('supertest'); - const fetchSource = async (): Promise => { - const response = await supertest - .get('/api/metrics/source/default') - .set('kbn-xsrf', 'xxx') - .expect(200); - return response.body; - }; - const fetchHasData = async (): Promise<{ hasData: boolean } | undefined> => { - const response = await supertest - .get(`/api/metrics/source/default/hasData`) - .set('kbn-xsrf', 'xxx') - .expect(200); - return response.body; - }; - - describe('Source API via HTTP', () => { - describe('8.0.0', () => { - before(() => - esArchiver.load('x-pack/test/functional/es_archives/infra/8.0.0/logs_and_metrics') - ); - after(() => - esArchiver.unload('x-pack/test/functional/es_archives/infra/8.0.0/logs_and_metrics') - ); - describe('/api/metrics/source/default', () => { - it('should just work', async () => { - const resp = fetchSource(); - return resp.then((data) => { - expect(data).to.have.property('source'); - expect(data?.source.configuration.metricAlias).to.equal('metrics-*,metricbeat-*'); - expect(data?.source).to.have.property('status'); - expect(data?.source.status?.metricIndicesExist).to.equal(true); - }); - }); - }); - describe('/api/metrics/source/default/hasData', () => { - it('should just work', async () => { - const resp = fetchHasData(); - return resp.then((data) => { - expect(data).to.have.property('hasData'); - expect(data?.hasData).to.be(true); - }); - }); - }); - }); - }); -} diff --git a/x-pack/test/api_integration/apis/metrics_ui/ip_to_hostname.ts b/x-pack/test/api_integration/apis/metrics_ui/ip_to_hostname.ts deleted file mode 100644 index 3a3e6172cdfcc..0000000000000 --- a/x-pack/test/api_integration/apis/metrics_ui/ip_to_hostname.ts +++ /dev/null @@ -1,45 +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 { FtrProviderContext } from '../../ftr_provider_context'; - -export default function ipToHostNameTest({ getService }: FtrProviderContext) { - const supertest = getService('supertest'); - const esArchiver = getService('esArchiver'); - - describe('Ip to Host API', () => { - before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs')); - after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/metrics_and_logs')); - - it('should basically work', async () => { - const postBody = { - index_pattern: 'metricbeat-*', - ip: '10.128.0.7', - }; - const response = await supertest - .post('/api/infra/ip_to_host') - .set('kbn-xsrf', 'xxx') - .send(postBody) - .expect(200); - - expect(response.body).to.have.property('host', 'demo-stack-mysql-01'); - }); - - it('should return 404 for invalid ip', async () => { - const postBody = { - index_pattern: 'metricbeat-*', - ip: '192.168.1.1', - }; - return supertest - .post('/api/infra/ip_to_host') - .set('kbn-xsrf', 'xxx') - .send(postBody) - .expect(404); - }); - }); -} diff --git a/x-pack/test/api_integration/apis/metrics_ui/metrics_alerting.ts b/x-pack/test/api_integration/apis/metrics_ui/metrics_alerting.ts deleted file mode 100644 index a091a912f8cb5..0000000000000 --- a/x-pack/test/api_integration/apis/metrics_ui/metrics_alerting.ts +++ /dev/null @@ -1,130 +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 moment from 'moment'; -import { MetricExpressionParams } from '@kbn/infra-plugin/common/alerting/metrics'; -import { getElasticsearchMetricQuery } from '@kbn/infra-plugin/server/lib/alerting/metric_threshold/lib/metric_query'; -import { COMPARATORS } from '@kbn/alerting-comparators'; -import { FtrProviderContext } from '../../ftr_provider_context'; - -export default function ({ getService }: FtrProviderContext) { - const client = getService('es'); - const index = 'test-index'; - const getSearchParams = (aggType: string) => - ({ - aggType, - timeUnit: 'm', - threshold: [0], - comparator: COMPARATORS.GREATER_THAN_OR_EQUALS, - timeSize: 5, - ...(aggType !== 'count' ? { metric: 'test.metric' } : {}), - } as MetricExpressionParams); - describe('Metrics Threshold Alerts', () => { - before(async () => { - await client.index({ - index, - body: {}, - }); - }); - const aggs = ['avg', 'min', 'max', 'rate', 'cardinality', 'count']; - - describe('querying the entire infrastructure', () => { - for (const aggType of aggs) { - it(`should work with the ${aggType} aggregator`, async () => { - const timeframe = { - start: moment().subtract(25, 'minutes').valueOf(), - end: moment().valueOf(), - }; - const searchBody = getElasticsearchMetricQuery( - getSearchParams(aggType), - timeframe, - 100, - true - ); - const result = await client.search({ - index, - body: searchBody, - }); - - expect(result.hits).to.be.ok(); - if (aggType !== 'count') { - expect(result.aggregations).to.be.ok(); - } - }); - } - it('should work with a filterQuery', async () => { - const timeframe = { - start: moment().subtract(25, 'minutes').valueOf(), - end: moment().valueOf(), - }; - const searchBody = getElasticsearchMetricQuery( - getSearchParams('avg'), - timeframe, - 100, - true, - void 0, - '{"bool":{"should":[{"match_phrase":{"agent.hostname":"foo"}}],"minimum_should_match":1}}' - ); - const result = await client.search({ - index, - body: searchBody, - }); - - expect(result.hits).to.be.ok(); - expect(result.aggregations).to.be.ok(); - }); - }); - describe('querying with a groupBy parameter', () => { - for (const aggType of aggs) { - it(`should work with the ${aggType} aggregator`, async () => { - const timeframe = { - start: moment().subtract(25, 'minutes').valueOf(), - end: moment().valueOf(), - }; - const searchBody = getElasticsearchMetricQuery( - getSearchParams(aggType), - timeframe, - 100, - true, - void 0, - 'agent.id' - ); - const result = await client.search({ - index, - body: searchBody, - }); - - expect(result.hits).to.be.ok(); - expect(result.aggregations).to.be.ok(); - }); - } - it('should work with a filterQuery', async () => { - const timeframe = { - start: moment().subtract(25, 'minutes').valueOf(), - end: moment().valueOf(), - }; - const searchBody = getElasticsearchMetricQuery( - getSearchParams('avg'), - timeframe, - 100, - true, - void 0, - 'agent.id', - '{"bool":{"should":[{"match_phrase":{"agent.hostname":"foo"}}],"minimum_should_match":1}}' - ); - const result = await client.search({ - index, - body: searchBody, - }); - - expect(result.hits).to.be.ok(); - expect(result.aggregations).to.be.ok(); - }); - }); - }); -} diff --git a/x-pack/test/api_integration/apis/metrics_ui/index.js b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/index.ts similarity index 69% rename from x-pack/test/api_integration/apis/metrics_ui/index.js rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/index.ts index 9e203ac5a3ada..7ac34f97db954 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/index.js +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/index.ts @@ -5,26 +5,24 @@ * 2.0. */ -export default function ({ loadTestFile }) { - describe('MetricsUI Endpoints', () => { +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; + +export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) { + describe('Infrastructure', () => { loadTestFile(require.resolve('./metadata')); - loadTestFile(require.resolve('./log_entry_highlights')); - loadTestFile(require.resolve('./log_summary')); - loadTestFile(require.resolve('./metrics')); + loadTestFile(require.resolve('./node_details')); loadTestFile(require.resolve('./sources')); loadTestFile(require.resolve('./snapshot')); - loadTestFile(require.resolve('./metrics_alerting')); loadTestFile(require.resolve('./metrics_explorer')); loadTestFile(require.resolve('./ip_to_hostname')); - loadTestFile(require.resolve('./http_source')); loadTestFile(require.resolve('./metric_threshold_alert')); loadTestFile(require.resolve('./metrics_overview_top')); loadTestFile(require.resolve('./metrics_process_list')); loadTestFile(require.resolve('./metrics_process_list_chart')); - loadTestFile(require.resolve('./infra_log_analysis_validation_log_entry_datasets')); loadTestFile(require.resolve('./infra')); loadTestFile(require.resolve('./inventory_threshold_alert')); loadTestFile(require.resolve('./services')); loadTestFile(require.resolve('./infra_custom_dashboards')); + loadTestFile(require.resolve('./infra_asset_count')); }); } diff --git a/x-pack/test/api_integration/apis/metrics_ui/infra.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/infra.ts similarity index 89% rename from x-pack/test/api_integration/apis/metrics_ui/infra.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/infra.ts index 457955354be62..7f85fb16bf364 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/infra.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/infra.ts @@ -6,22 +6,22 @@ */ import expect from '@kbn/expect'; - import { GetInfraMetricsRequestBodyPayloadClient, GetInfraMetricsResponsePayload, } from '@kbn/infra-plugin/common/http_api/infra'; -import { DATES } from './constants'; -import { FtrProviderContext } from '../../ftr_provider_context'; +import type { SupertestWithRoleScopeType } from '../../../services'; +import { DATES } from './utils/constants'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; const ENDPOINT = '/api/metrics/infra/host'; const normalizeNewLine = (text: string) => { return text.replaceAll(/(\s{2,}|\\n\\s)/g, ' '); }; -export default function ({ getService }: FtrProviderContext) { +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const esArchiver = getService('esArchiver'); - const supertest = getService('supertest'); + const roleScopedSupertest = getService('roleScopedSupertest'); const basePayload: GetInfraMetricsRequestBodyPayloadClient = { limit: 10, @@ -40,29 +40,34 @@ export default function ({ getService }: FtrProviderContext) { query: { bool: { must_not: [], filter: [], should: [], must: [] } }, }; - const makeRequest = async ({ - body, - invalidBody, - expectedHTTPCode, - }: { - body?: GetInfraMetricsRequestBodyPayloadClient; - invalidBody?: any; - expectedHTTPCode: number; - }) => { - return supertest - .post(ENDPOINT) - .set('kbn-xsrf', 'xxx') - .send(body ?? invalidBody) - .expect(expectedHTTPCode); - }; - describe('Hosts', () => { - before(() => - esArchiver.load('x-pack/test/functional/es_archives/infra/8.0.0/logs_and_metrics') - ); - after(() => - esArchiver.unload('x-pack/test/functional/es_archives/infra/8.0.0/logs_and_metrics') - ); + let supertestWithAdminScope: SupertestWithRoleScopeType; + + const makeRequest = async ({ + body, + invalidBody, + expectedHTTPCode, + }: { + body?: GetInfraMetricsRequestBodyPayloadClient; + invalidBody?: any; + expectedHTTPCode: number; + }) => { + return supertestWithAdminScope + .post(ENDPOINT) + .send(body ?? invalidBody) + .expect(expectedHTTPCode); + }; + + before(async () => { + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); + await esArchiver.load('x-pack/test/functional/es_archives/infra/8.0.0/logs_and_metrics'); + }); + after(async () => { + await esArchiver.unload('x-pack/test/functional/es_archives/infra/8.0.0/logs_and_metrics'); + await supertestWithAdminScope.destroy(); + }); describe('fetch hosts', () => { it('should return metrics for a host', async () => { diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/infra/asset_count.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/infra_asset_count.ts similarity index 64% rename from x-pack/test_serverless/api_integration/test_suites/observability/infra/asset_count.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/infra_asset_count.ts index 99ee61ccf2b67..adedf9aa5bd06 100644 --- a/x-pack/test_serverless/api_integration/test_suites/observability/infra/asset_count.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/infra_asset_count.ts @@ -11,10 +11,10 @@ import type { GetInfraAssetCountResponsePayload, GetInfraAssetCountRequestParamsPayload, } from '@kbn/infra-plugin/common/http_api'; -import type { RoleCredentials } from '../../../../shared/services'; +import type { SupertestWithRoleScopeType } from '../../../services'; import type { FtrProviderContext } from '../../../ftr_provider_context'; -import { DATES, ARCHIVE_NAME } from './constants'; +import { DATES, ARCHIVE_NAME } from './utils/constants'; const timeRange = { from: DATES.serverlessTestingHostDateString.min, @@ -23,40 +23,39 @@ const timeRange = { export default function ({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); - const supertestWithoutAuth = getService('supertestWithoutAuth'); + const roleScopedSupertest = getService('roleScopedSupertest'); const svlUserManager = getService('svlUserManager'); const svlCommonApi = getService('svlCommonApi'); - const fetchHostsCount = async ({ - params, - body, - roleAuthc, - }: { - params: GetInfraAssetCountRequestParamsPayload; - body: GetInfraAssetCountRequestBodyPayloadClient; - roleAuthc: RoleCredentials; - }): Promise => { - const { assetType } = params; - const response = await supertestWithoutAuth - .post(`/api/infra/${assetType}/count`) - .set(svlCommonApi.getInternalRequestHeader()) - .set(roleAuthc.apiKeyHeader) - .send(body) - .expect(200); - return response.body; - }; - describe('API /api/infra/{assetType}/count', () => { - let roleAuthc: RoleCredentials; + let supertestWithAdminScope: SupertestWithRoleScopeType; + + const fetchHostsCount = async ({ + params, + body, + }: { + params: GetInfraAssetCountRequestParamsPayload; + body: GetInfraAssetCountRequestBodyPayloadClient; + }): Promise => { + const { assetType } = params; + const response = await supertestWithAdminScope + .post(`/api/infra/${assetType}/count`) + .send(body) + .expect(200); + return response.body; + }; + describe('works', () => { describe('with host', () => { before(async () => { - roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin'); - return esArchiver.load(ARCHIVE_NAME); + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); + await esArchiver.load(ARCHIVE_NAME); }); after(async () => { - await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc); - return esArchiver.unload(ARCHIVE_NAME); + await esArchiver.unload(ARCHIVE_NAME); + await supertestWithAdminScope.destroy(); }); it('received data', async () => { diff --git a/x-pack/test/api_integration/apis/metrics_ui/infra_custom_dashboards.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/infra_custom_dashboards.ts similarity index 84% rename from x-pack/test/api_integration/apis/metrics_ui/infra_custom_dashboards.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/infra_custom_dashboards.ts index 2ed6607630060..140b0540c7d71 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/infra_custom_dashboards.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/infra_custom_dashboards.ts @@ -10,18 +10,31 @@ import { InfraCustomDashboard } from '@kbn/infra-plugin/common/custom_dashboards import { InfraSaveCustomDashboardsRequestPayload } from '@kbn/infra-plugin/common/http_api/custom_dashboards_api'; import { INFRA_CUSTOM_DASHBOARDS_SAVED_OBJECT_TYPE } from '@kbn/infra-plugin/server/saved_objects'; import { enableInfrastructureAssetCustomDashboards } from '@kbn/observability-plugin/common'; -import { FtrProviderContext } from '../../ftr_provider_context'; +import type { SupertestWithRoleScopeType } from '../../../services'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; const getCustomDashboardsUrl = (assetType: string, dashboardSavedObjectId?: string) => dashboardSavedObjectId ? `/api/infra/${assetType}/custom-dashboards/${dashboardSavedObjectId}` : `/api/infra/${assetType}/custom-dashboards`; -export default function ({ getService }: FtrProviderContext) { - const supertest = getService('supertest'); +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { + const roleScopedSupertest = getService('roleScopedSupertest'); const kibanaServer = getService('kibanaServer'); describe('Infra Custom Dashboards API', () => { + let supertestWithAdminScope: SupertestWithRoleScopeType; + + before(async () => { + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); + }); + + after(async () => { + await supertestWithAdminScope.destroy(); + }); + beforeEach(async () => { await kibanaServer.savedObjects.clean({ types: [INFRA_CUSTOM_DASHBOARDS_SAVED_OBJECT_TYPE], @@ -34,7 +47,7 @@ export default function ({ getService }: FtrProviderContext) { [enableInfrastructureAssetCustomDashboards]: false, }); - await supertest.get(getCustomDashboardsUrl('host')).expect(403); + await supertestWithAdminScope.get(getCustomDashboardsUrl('host')).expect(403); }); it('responds with an error when trying to request a custom dashboard for unsupported asset type', async () => { @@ -42,7 +55,9 @@ export default function ({ getService }: FtrProviderContext) { [enableInfrastructureAssetCustomDashboards]: false, }); - await supertest.get(getCustomDashboardsUrl('unsupported-asset-type')).expect(400); + await supertestWithAdminScope + .get(getCustomDashboardsUrl('unsupported-asset-type')) + .expect(400); }); it('responds with an empty configuration if custom dashboard saved object does not exist', async () => { @@ -53,7 +68,10 @@ export default function ({ getService }: FtrProviderContext) { types: [INFRA_CUSTOM_DASHBOARDS_SAVED_OBJECT_TYPE], }); - const response = await supertest.get(getCustomDashboardsUrl('host')).expect(200); + const response = await supertestWithAdminScope + .get(getCustomDashboardsUrl('host')) + + .expect(200); expect(response.body).to.be.eql([]); }); @@ -73,7 +91,9 @@ export default function ({ getService }: FtrProviderContext) { overwrite: true, }); - const response = await supertest.get(getCustomDashboardsUrl('host')).expect(200); + const response = await supertestWithAdminScope + .get(getCustomDashboardsUrl('host')) + .expect(200); expect(response.body).to.have.length(1); expect(response.body[0]).to.have.property('dashboardFilterAssetIdEnabled', true); @@ -92,9 +112,8 @@ export default function ({ getService }: FtrProviderContext) { [enableInfrastructureAssetCustomDashboards]: false, }); - await supertest + await supertestWithAdminScope .post(getCustomDashboardsUrl('host')) - .set('kbn-xsrf', 'xxx') .send(payload) .expect(403); }); @@ -108,9 +127,8 @@ export default function ({ getService }: FtrProviderContext) { [enableInfrastructureAssetCustomDashboards]: true, }); - await supertest + await supertestWithAdminScope .post(getCustomDashboardsUrl('unsupported-asset-type')) - .set('kbn-xsrf', 'xxx') .send(payload) .expect(400); }); @@ -127,9 +145,8 @@ export default function ({ getService }: FtrProviderContext) { types: [INFRA_CUSTOM_DASHBOARDS_SAVED_OBJECT_TYPE], }); - const response = await supertest + const response = await supertestWithAdminScope .post(getCustomDashboardsUrl('host')) - .set('kbn-xsrf', 'xxx') .send(payload) .expect(200); @@ -161,9 +178,8 @@ export default function ({ getService }: FtrProviderContext) { overwrite: true, }); - const response = await supertest + const response = await supertestWithAdminScope .post(getCustomDashboardsUrl('host')) - .set('kbn-xsrf', 'xxx') .send(payload) .expect(400); @@ -184,9 +200,8 @@ export default function ({ getService }: FtrProviderContext) { [enableInfrastructureAssetCustomDashboards]: false, }); - await supertest + await supertestWithAdminScope .put(getCustomDashboardsUrl('host', '123')) - .set('kbn-xsrf', 'xxx') .send(payload) .expect(403); }); @@ -201,9 +216,8 @@ export default function ({ getService }: FtrProviderContext) { [enableInfrastructureAssetCustomDashboards]: true, }); - await supertest + await supertestWithAdminScope .put(getCustomDashboardsUrl('host', '000')) - .set('kbn-xsrf', 'xxx') .send(payload) .expect(404); }); @@ -238,12 +252,13 @@ export default function ({ getService }: FtrProviderContext) { dashboardSavedObjectId: '123', dashboardFilterAssetIdEnabled: false, }; - const updateResponse = await supertest + const updateResponse = await supertestWithAdminScope .put(getCustomDashboardsUrl('host', existingDashboardSavedObject.id)) - .set('kbn-xsrf', 'xxx') .send(payload) .expect(200); - const getResponse = await supertest.get(getCustomDashboardsUrl('host')).expect(200); + const getResponse = await supertestWithAdminScope + .get(getCustomDashboardsUrl('host')) + .expect(200); expect(updateResponse.body).to.be.eql({ ...payload, @@ -267,10 +282,7 @@ export default function ({ getService }: FtrProviderContext) { [enableInfrastructureAssetCustomDashboards]: false, }); - await supertest - .delete(getCustomDashboardsUrl('host', '123')) - .set('kbn-xsrf', 'xxx') - .expect(403); + await supertestWithAdminScope.delete(getCustomDashboardsUrl('host', '123')).expect(403); }); it('responds with an error when trying to delete not existing dashboard', async () => { @@ -278,10 +290,7 @@ export default function ({ getService }: FtrProviderContext) { [enableInfrastructureAssetCustomDashboards]: true, }); - await supertest - .delete(getCustomDashboardsUrl('host', '000')) - .set('kbn-xsrf', 'xxx') - .expect(404); + await supertestWithAdminScope.delete(getCustomDashboardsUrl('host', '000')).expect(404); }); it('deletes an existing dashboard', async () => { @@ -301,12 +310,13 @@ export default function ({ getService }: FtrProviderContext) { overwrite: true, }); - await supertest + await supertestWithAdminScope .delete(getCustomDashboardsUrl('host', existingDashboardSavedObject.id)) - .set('kbn-xsrf', 'xxx') .expect(200); - const afterDeleteResponse = await supertest.get(getCustomDashboardsUrl('host')).expect(200); + const afterDeleteResponse = await supertestWithAdminScope + .get(getCustomDashboardsUrl('host')) + .expect(200); expect(afterDeleteResponse.body).to.be.eql([]); }); diff --git a/x-pack/test/api_integration/apis/metrics_ui/inventory_threshold_alert.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/inventory_threshold_alert.ts similarity index 98% rename from x-pack/test/api_integration/apis/metrics_ui/inventory_threshold_alert.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/inventory_threshold_alert.ts index 4a60158c77e80..a57df6c06d426 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/inventory_threshold_alert.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/inventory_threshold_alert.ts @@ -11,11 +11,11 @@ import { InventoryItemType, SnapshotMetricType } from '@kbn/metrics-data-access- import { evaluateCondition } from '@kbn/infra-plugin/server/lib/alerting/inventory_metric_threshold/evaluate_condition'; import { InfraSource } from '@kbn/infra-plugin/server/lib/sources'; import { COMPARATORS } from '@kbn/alerting-comparators'; -import { FtrProviderContext } from '../../ftr_provider_context'; -import { DATES } from './constants'; -import { createFakeLogger } from './create_fake_logger'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; +import { DATES } from './utils/constants'; +import { createFakeLogger } from './utils/create_fake_logger'; -export default function ({ getService }: FtrProviderContext) { +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const esArchiver = getService('esArchiver'); const esClient = getService('es'); const log = getService('log'); diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/ip_to_hostname.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/ip_to_hostname.ts new file mode 100644 index 0000000000000..d75c16aacd7cb --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/ip_to_hostname.ts @@ -0,0 +1,51 @@ +/* + * 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 type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; +import type { SupertestWithRoleScopeType } from '../../../services'; + +export default function ipToHostNameTest({ getService }: DeploymentAgnosticFtrProviderContext) { + const roleScopedSupertest = getService('roleScopedSupertest'); + const esArchiver = getService('esArchiver'); + + describe('API /api/infra/ip_to_host', () => { + let supertestWithAdminScope: SupertestWithRoleScopeType; + + before(async () => { + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); + await esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs'); + }); + after(async () => { + await esArchiver.unload('x-pack/test/functional/es_archives/infra/metrics_and_logs'); + await supertestWithAdminScope.destroy(); + }); + + it('should basically work', async () => { + const postBody = { + index_pattern: 'metricbeat-*', + ip: '10.128.0.7', + }; + const response = await supertestWithAdminScope + .post('/api/infra/ip_to_host') + .send(postBody) + .expect(200); + + expect(response.body).to.have.property('host', 'demo-stack-mysql-01'); + }); + + it('should return 404 for invalid ip', async () => { + const postBody = { + index_pattern: 'metricbeat-*', + ip: '192.168.1.1', + }; + return supertestWithAdminScope.post('/api/infra/ip_to_host').send(postBody).expect(404); + }); + }); +} diff --git a/x-pack/test/api_integration/apis/metrics_ui/metadata.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metadata.ts similarity index 88% rename from x-pack/test/api_integration/apis/metrics_ui/metadata.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metadata.ts index 3432e834b6ea1..e6f2b6ef625ab 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/metadata.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metadata.ts @@ -10,9 +10,10 @@ import { InfraMetadata, InfraMetadataRequest, } from '@kbn/infra-plugin/common/http_api/metadata_api'; -import { FtrProviderContext } from '../../ftr_provider_context'; +import type { SupertestWithRoleScopeType } from '../../../services'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; -import { DATES } from './constants'; +import { DATES } from './utils/constants'; const timeRange700 = { from: DATES['7.0.0'].hosts.min, @@ -29,22 +30,35 @@ const timeRange800withAws = { to: DATES[`8.0.0`].logs_and_metrics_with_aws.max, }; -export default function ({ getService }: FtrProviderContext) { +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const esArchiver = getService('esArchiver'); - const supertest = getService('supertest'); - const fetchMetadata = async (body: InfraMetadataRequest): Promise => { - const response = await supertest - .post('/api/infra/metadata') - .set('kbn-xsrf', 'xxx') - .send(body) - .expect(200); - return response.body; - }; + const roleScopedSupertest = getService('roleScopedSupertest'); + + describe('API /api/infra/metadata', () => { + let supertestWithAdminScope: SupertestWithRoleScopeType; + + const fetchMetadata = async ( + body: InfraMetadataRequest + ): Promise => { + const response = await supertestWithAdminScope + .post('/api/infra/metadata') + .send(body) + .expect(200); + return response.body; + }; + + before(async () => { + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); + }); + after(async () => { + await supertestWithAdminScope.destroy(); + }); - describe('metadata', () => { describe('7.0.0', () => { - before(async () => esArchiver.load('x-pack/test/functional/es_archives/infra/7.0.0/hosts')); - after(async () => esArchiver.unload('x-pack/test/functional/es_archives/infra/7.0.0/hosts')); + before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/7.0.0/hosts')); + after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/7.0.0/hosts')); it('hosts', async () => { const metadata = await fetchMetadata({ @@ -63,8 +77,8 @@ export default function ({ getService }: FtrProviderContext) { }); describe('6.6.0', () => { - before(async () => esArchiver.load('x-pack/test/functional/es_archives/infra/6.6.0/docker')); - after(async () => esArchiver.unload('x-pack/test/functional/es_archives/infra/6.6.0/docker')); + before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/6.6.0/docker')); + after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/6.6.0/docker')); it('docker', async () => { const metadata = await fetchMetadata({ @@ -86,8 +100,8 @@ export default function ({ getService }: FtrProviderContext) { describe('cloud and host information', () => { const archiveName = 'x-pack/test/functional/es_archives/infra/8.0.0/logs_and_metrics_with_aws'; - before(async () => esArchiver.load(archiveName)); - after(async () => esArchiver.unload(archiveName)); + before(() => esArchiver.load(archiveName)); + after(() => esArchiver.unload(archiveName)); it('host', async () => { const metadata = await fetchMetadata({ diff --git a/x-pack/test/api_integration/apis/metrics_ui/metric_threshold_alert.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metric_threshold_alert.ts similarity index 90% rename from x-pack/test/api_integration/apis/metrics_ui/metric_threshold_alert.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metric_threshold_alert.ts index 96aa8f91a2c9c..5838ca6d7a1f0 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/metric_threshold_alert.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metric_threshold_alert.ts @@ -11,6 +11,7 @@ import { Aggregators, CountMetricExpressionParams, CustomMetricExpressionParams, + MetricExpressionParams, NonCountMetricExpressionParams, } from '@kbn/infra-plugin/common/alerting/metrics'; import { InfraSource } from '@kbn/infra-plugin/common/source_configuration/source_configuration'; @@ -19,12 +20,14 @@ import { evaluateRule, } from '@kbn/infra-plugin/server/lib/alerting/metric_threshold/lib/evaluate_rule'; import { COMPARATORS } from '@kbn/alerting-comparators'; -import { FtrProviderContext } from '../../ftr_provider_context'; -import { DATES } from './constants'; -import { createFakeLogger } from './create_fake_logger'; +import { getElasticsearchMetricQuery } from '@kbn/infra-plugin/server/lib/alerting/metric_threshold/lib/metric_query'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; +import { DATES } from './utils/constants'; +import { createFakeLogger } from './utils/create_fake_logger'; const { gauge, rate } = DATES['alert-test-data']; -export default function ({ getService }: FtrProviderContext) { + +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const esArchiver = getService('esArchiver'); const esClient = getService('es'); const log = getService('log'); @@ -76,7 +79,10 @@ export default function ({ getService }: FtrProviderContext) { ], }; - describe('Metric Threshold Alerts Executor', () => { + describe('Metric Threshold Alerts Executor', function () { + // Metric Threshold rule is not enabled in serverless + this.tags('skipSvlOblt'); + describe('with 10K plus docs', () => { before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/ten_thousand_plus')); after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/ten_thousand_plus')); @@ -1341,5 +1347,119 @@ export default function ({ getService }: FtrProviderContext) { }); }); }); + describe('getElasticsearchMetricQuery', () => { + const index = 'test-index'; + const getSearchParams = (aggType: string) => + ({ + aggType, + timeUnit: 'm', + threshold: [0], + comparator: COMPARATORS.GREATER_THAN_OR_EQUALS, + timeSize: 5, + ...(aggType !== 'count' ? { metric: 'test.metric' } : {}), + } as MetricExpressionParams); + + before(async () => { + await esClient.index({ + index, + body: {}, + }); + }); + const aggs = ['avg', 'min', 'max', 'rate', 'cardinality', 'count']; + + describe('querying the entire infrastructure', () => { + for (const aggType of aggs) { + it(`should work with the ${aggType} aggregator`, async () => { + const timeframe = { + start: moment().subtract(25, 'minutes').valueOf(), + end: moment().valueOf(), + }; + const searchBody = getElasticsearchMetricQuery( + getSearchParams(aggType), + timeframe, + 100, + true + ); + const result = await esClient.search({ + index, + body: searchBody, + }); + + expect(result.hits).to.be.ok(); + if (aggType !== 'count') { + expect(result.aggregations).to.be.ok(); + } + }); + } + it('should work with a filterQuery', async () => { + const timeframe = { + start: moment().subtract(25, 'minutes').valueOf(), + end: moment().valueOf(), + }; + const searchBody = getElasticsearchMetricQuery( + getSearchParams('avg'), + timeframe, + 100, + true, + void 0, + '{"bool":{"should":[{"match_phrase":{"agent.hostname":"foo"}}],"minimum_should_match":1}}' + ); + const result = await esClient.search({ + index, + body: searchBody, + }); + + expect(result.hits).to.be.ok(); + expect(result.aggregations).to.be.ok(); + }); + }); + describe('querying with a groupBy parameter', () => { + for (const aggType of aggs) { + it(`should work with the ${aggType} aggregator`, async () => { + const timeframe = { + start: moment().subtract(25, 'minutes').valueOf(), + end: moment().valueOf(), + }; + const searchBody = getElasticsearchMetricQuery( + getSearchParams(aggType), + timeframe, + 100, + true, + void 0, + 'agent.id' + ); + const result = await esClient.search({ + index, + body: searchBody, + }); + + expect(result.hits).to.be.ok(); + expect(result.aggregations).to.be.ok(); + }); + } + it('should work with a filterQuery', async () => { + const timeframe = { + start: moment().subtract(25, 'minutes').valueOf(), + end: moment().valueOf(), + }; + const searchBody = getElasticsearchMetricQuery( + getSearchParams('avg'), + timeframe, + 100, + true, + void 0, + 'agent.id', + '{"bool":{"should":[{"match_phrase":{"agent.hostname":"foo"}}],"minimum_should_match":1}}' + ); + const result = await esClient.search({ + index, + body: searchBody, + }); + + expect(result.hits).to.be.ok(); + expect(result.aggregations).to.be.ok(); + }); + }); + }); }); } diff --git a/x-pack/test/api_integration/apis/metrics_ui/metrics_explorer.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metrics_explorer.ts similarity index 96% rename from x-pack/test/api_integration/apis/metrics_ui/metrics_explorer.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metrics_explorer.ts index 7257e8583ab8a..b182f51dd1ef6 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/metrics_explorer.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metrics_explorer.ts @@ -10,16 +10,19 @@ import { first } from 'lodash'; import moment from 'moment'; import { metricsExplorerResponseRT } from '@kbn/infra-plugin/common/http_api/metrics_explorer'; import { decodeOrThrow } from '@kbn/io-ts-utils'; -import { DATES } from './constants'; -import { FtrProviderContext } from '../../ftr_provider_context'; +import { DATES } from './utils/constants'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; const { min, max } = DATES['7.0.0'].hosts; -export default function ({ getService }: FtrProviderContext) { +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const supertest = getService('supertest'); const esArchiver = getService('esArchiver'); - describe('Metrics Explorer API', () => { + describe('Metrics Explorer API', function () { + // Metrics Explorer is not enabled in serverless + this.tags('skipSvlOblt'); + describe('with data', () => { before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/7.0.0/hosts')); after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/7.0.0/hosts')); diff --git a/x-pack/test/api_integration/apis/metrics_ui/metrics_overview_top.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metrics_overview_top.ts similarity index 73% rename from x-pack/test/api_integration/apis/metrics_ui/metrics_overview_top.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metrics_overview_top.ts index ae80772bc2d03..8411d0e9d664d 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/metrics_overview_top.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metrics_overview_top.ts @@ -11,24 +11,32 @@ import { TopNodesResponseRT, } from '@kbn/infra-plugin/common/http_api/overview_api'; import { decodeOrThrow } from '@kbn/io-ts-utils'; -import { FtrProviderContext } from '../../ftr_provider_context'; -import { DATES } from './constants'; +import type { SupertestWithRoleScopeType } from '../../../services'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; +import { DATES } from './utils/constants'; -export default function ({ getService }: FtrProviderContext) { +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const esArchiver = getService('esArchiver'); - const supertest = getService('supertest'); + const roleScopedSupertest = getService('roleScopedSupertest'); describe('API /metrics/overview/top', () => { - before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/7.0.0/hosts')); - after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/7.0.0/hosts')); + let supertestWithAdminScope: SupertestWithRoleScopeType; + + before(async () => { + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); + await esArchiver.load('x-pack/test/functional/es_archives/infra/7.0.0/hosts'); + }); + after(async () => { + await esArchiver.unload('x-pack/test/functional/es_archives/infra/7.0.0/hosts'); + await supertestWithAdminScope.destroy(); + }); it('works', async () => { const { min, max } = DATES['7.0.0'].hosts; - const response = await supertest + const response = await supertestWithAdminScope .post('/api/metrics/overview/top') - .set({ - 'kbn-xsrf': 'some-xsrf-token', - }) .send( TopNodesRequestRT.encode({ sourceId: 'default', @@ -59,11 +67,8 @@ export default function ({ getService }: FtrProviderContext) { it('should return correct sorted calculations', async () => { const { min, max } = DATES['8.0.0'].hosts_and_netowrk; - const response = await supertest + const response = await supertestWithAdminScope .post('/api/metrics/overview/top') - .set({ - 'kbn-xsrf': 'some-xsrf-token', - }) .send( TopNodesRequestRT.encode({ sourceId: 'default', diff --git a/x-pack/test/api_integration/apis/metrics_ui/metrics_process_list.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metrics_process_list.ts similarity index 58% rename from x-pack/test/api_integration/apis/metrics_ui/metrics_process_list.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metrics_process_list.ts index 99e0116977e76..7b49950ef9963 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/metrics_process_list.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metrics_process_list.ts @@ -11,24 +11,30 @@ import { ProcessListAPIResponseRT, } from '@kbn/infra-plugin/common/http_api/host_details/process_list'; import { decodeOrThrow } from '@kbn/io-ts-utils'; -import { FtrProviderContext } from '../../ftr_provider_context'; +import type { SupertestWithRoleScopeType } from '../../../services'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; -export default function ({ getService }: FtrProviderContext) { +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const esArchiver = getService('esArchiver'); - const supertest = getService('supertest'); - describe('API /metrics/process_list', () => { - before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/8.0.0/metrics_and_apm')); - after(() => - esArchiver.unload('x-pack/test/functional/es_archives/infra/8.0.0/metrics_and_apm') - ); + const roleScopedSupertest = getService('roleScopedSupertest'); + + describe('API /api/metrics/process_list', () => { + let supertestWithAdminScope: SupertestWithRoleScopeType; + before(async () => { + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); + await esArchiver.load('x-pack/test/functional/es_archives/infra/8.0.0/metrics_and_apm'); + }); + after(async () => { + await esArchiver.unload('x-pack/test/functional/es_archives/infra/8.0.0/metrics_and_apm'); + await supertestWithAdminScope.destroy(); + }); it('works', async () => { - const response = await supertest + const response = await supertestWithAdminScope .post('/api/metrics/process_list') - .set({ - 'kbn-xsrf': 'some-xsrf-token', - }) .send( ProcessListAPIRequestRT.encode({ hostTerm: { diff --git a/x-pack/test/api_integration/apis/metrics_ui/metrics_process_list_chart.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metrics_process_list_chart.ts similarity index 58% rename from x-pack/test/api_integration/apis/metrics_ui/metrics_process_list_chart.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metrics_process_list_chart.ts index d0065bcc67420..a1b453d5b074a 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/metrics_process_list_chart.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/metrics_process_list_chart.ts @@ -11,24 +11,31 @@ import { ProcessListAPIChartResponseRT, } from '@kbn/infra-plugin/common/http_api/host_details/process_list'; import { decodeOrThrow } from '@kbn/io-ts-utils'; -import { FtrProviderContext } from '../../ftr_provider_context'; +import type { SupertestWithRoleScopeType } from '../../../services'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; -export default function ({ getService }: FtrProviderContext) { +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const esArchiver = getService('esArchiver'); - const supertest = getService('supertest'); + + const roleScopedSupertest = getService('roleScopedSupertest'); describe('API /metrics/process_list/chart', () => { - before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/8.0.0/metrics_and_apm')); - after(() => - esArchiver.unload('x-pack/test/functional/es_archives/infra/8.0.0/metrics_and_apm') - ); + let supertestWithAdminScope: SupertestWithRoleScopeType; + + before(async () => { + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); + await esArchiver.load('x-pack/test/functional/es_archives/infra/8.0.0/metrics_and_apm'); + }); + after(async () => { + await esArchiver.unload('x-pack/test/functional/es_archives/infra/8.0.0/metrics_and_apm'); + await supertestWithAdminScope.destroy(); + }); it('works', async () => { - const response = await supertest + const response = await supertestWithAdminScope .post('/api/metrics/process_list/chart') - .set({ - 'kbn-xsrf': 'some-xsrf-token', - }) .send( ProcessListAPIChartRequestRT.encode({ hostTerm: { diff --git a/x-pack/test/api_integration/apis/metrics_ui/metrics.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/node_details.ts similarity index 77% rename from x-pack/test/api_integration/apis/metrics_ui/metrics.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/node_details.ts index 9acdd82abc085..e492e0dc9723d 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/metrics.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/node_details.ts @@ -7,13 +7,13 @@ import expect from '@kbn/expect'; import { first, last } from 'lodash'; - import { InfraTimerangeInput } from '@kbn/infra-plugin/common/http_api/snapshot_api'; import { InventoryMetric } from '@kbn/metrics-data-access-plugin/common'; import { NodeDetailsMetricDataResponse } from '@kbn/infra-plugin/common/http_api/node_details_api'; -import { FtrProviderContext } from '../../ftr_provider_context'; +import type { SupertestWithRoleScopeType } from '../../../services'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; -import { DATES } from './constants'; +import { DATES } from './utils/constants'; const { min, max } = DATES['8.0.0'].pods_only; @@ -26,21 +26,31 @@ interface NodeDetailsRequest { cloudId?: string; } -export default function ({ getService }: FtrProviderContext) { +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const esArchiver = getService('esArchiver'); - const supertest = getService('supertest'); + const roleScopedSupertest = getService('roleScopedSupertest'); + + describe('API /api/metrics/node_details', () => { + let supertestWithAdminScope: SupertestWithRoleScopeType; - describe('metrics', () => { - before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/8.0.0/pods_only')); - after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/8.0.0/pods_only')); + before(async () => { + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); + await esArchiver.load('x-pack/test/functional/es_archives/infra/8.0.0/pods_only'); + }); + after(async () => { + await esArchiver.unload('x-pack/test/functional/es_archives/infra/8.0.0/pods_only'); + await supertestWithAdminScope.destroy(); + }); const fetchNodeDetails = async ( body: NodeDetailsRequest, expectedStatusCode = 200 ): Promise => { - const response = await supertest + const response = await supertestWithAdminScope .post('/api/metrics/node_details') - .set('kbn-xsrf', 'xxx') + .send(body) .expect(expectedStatusCode); return response.body; diff --git a/x-pack/test/api_integration/apis/metrics_ui/services.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/services.ts similarity index 56% rename from x-pack/test/api_integration/apis/metrics_ui/services.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/services.ts index 785d9f5741296..78724219975b4 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/services.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/services.ts @@ -9,22 +9,107 @@ import expect from '@kbn/expect'; import { ServicesAPIResponseRT } from '@kbn/infra-plugin/common/http_api/host_details'; import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; import { decodeOrThrow } from '@kbn/io-ts-utils'; -import { FtrProviderContext } from '../../ftr_provider_context'; -import { generateServicesData, generateServicesLogsOnlyData } from './helpers'; -import { getApmSynthtraceEsClient } from '../../../common/utils/synthtrace/apm_es_client'; +import { apm, timerange } from '@kbn/apm-synthtrace-client'; +import type { SupertestWithRoleScopeType } from '../../../services'; +import { getApmSynthtraceEsClient } from '../../../../../common/utils/synthtrace/apm_es_client'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; const SERVICES_ENDPOINT = '/api/infra/services'; -export default function ({ getService }: FtrProviderContext) { - const supertest = getService('supertest'); +export function generateServicesData({ + from, + to, + instanceCount = 1, + servicesPerHost = 1, +}: { + from: string; + to: string; + instanceCount?: number; + servicesPerHost?: number; +}) { + const range = timerange(from, to); + const services = Array(instanceCount) + .fill(null) + .flatMap((_, hostIdx) => + Array(servicesPerHost) + .fill(null) + .map((__, serviceIdx) => + apm + .service({ + name: `service-${hostIdx}-${serviceIdx}`, + environment: 'production', + agentName: 'nodejs', + }) + .instance(`host-${hostIdx}`) + ) + ); + return range + .interval('1m') + .rate(1) + .generator((timestamp) => + services.map((service) => + service + .transaction({ transactionName: 'GET /foo' }) + .timestamp(timestamp) + .duration(500) + .success() + ) + ); +} +// generates error logs only for services +export function generateServicesLogsOnlyData({ + from, + to, + instanceCount = 1, + servicesPerHost = 1, +}: { + from: string; + to: string; + instanceCount?: number; + servicesPerHost?: number; +}) { + const range = timerange(from, to); + const services = Array(instanceCount) + .fill(null) + .flatMap((_, hostIdx) => + Array(servicesPerHost) + .fill(null) + .map((__, serviceIdx) => + apm + .service({ + name: `service-${hostIdx}-${serviceIdx}`, + environment: 'production', + agentName: 'go', + }) + .instance(`host-${hostIdx}`) + ) + ); + return range + .interval('1m') + .rate(1) + .generator((timestamp) => + services.map((service) => + service.error({ message: 'error', type: 'My Type' }).timestamp(timestamp) + ) + ); +} + +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { + const roleScopedSupertest = getService('roleScopedSupertest'); const apmSynthtraceKibanaClient = getService('apmSynthtraceKibanaClient'); const esClient = getService('es'); describe('GET /infra/services', () => { let synthtraceApmClient: ApmSynthtraceEsClient; + let supertestWithAdminScope: SupertestWithRoleScopeType; + const from = new Date(Date.now() - 1000 * 60 * 2).toISOString(); const to = new Date().toISOString(); before(async () => { + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); + const version = (await apmSynthtraceKibanaClient.installApmPackage()).version; synthtraceApmClient = await getApmSynthtraceEsClient({ client: esClient, @@ -33,6 +118,7 @@ export default function ({ getService }: FtrProviderContext) { }); after(async () => { await apmSynthtraceKibanaClient.uninstallApmPackage(); + await supertestWithAdminScope.destroy(); }); describe('with transactions', () => { @@ -50,11 +136,8 @@ export default function ({ getService }: FtrProviderContext) { 'host.name': 'some-host', }); - const response = await supertest + const response = await supertestWithAdminScope .get(SERVICES_ENDPOINT) - .set({ - 'kbn-xsrf': 'some-xsrf-token', - }) .query({ filters, from, @@ -69,7 +152,7 @@ export default function ({ getService }: FtrProviderContext) { const filters = JSON.stringify({ 'host.name': 'host-0', }); - const response = await supertest + const response = await supertestWithAdminScope .get(SERVICES_ENDPOINT) .set({ 'kbn-xsrf': 'some-xsrf-token', @@ -87,11 +170,9 @@ export default function ({ getService }: FtrProviderContext) { 'host.name': 'host-0', 'agent.name': 'nodejs', }); - await supertest + await supertestWithAdminScope .get(SERVICES_ENDPOINT) - .set({ - 'kbn-xsrf': 'some-xsrf-token', - }) + .query({ filters, from, @@ -113,7 +194,7 @@ export default function ({ getService }: FtrProviderContext) { const filters = JSON.stringify({ 'host.name': 'host-0', }); - const response = await supertest + const response = await supertestWithAdminScope .get(SERVICES_ENDPOINT) .set({ 'kbn-xsrf': 'some-xsrf-token', diff --git a/x-pack/test/api_integration/apis/metrics_ui/snapshot.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/snapshot.ts similarity index 95% rename from x-pack/test/api_integration/apis/metrics_ui/snapshot.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/snapshot.ts index 8b70c5c32e9fb..0b32cf5b8ce8c 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/snapshot.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/snapshot.ts @@ -7,31 +7,42 @@ import expect from '@kbn/expect'; import { first, last } from 'lodash'; - import { SnapshotNodeResponse, SnapshotMetricInput, SnapshotRequest, } from '@kbn/infra-plugin/common/http_api/snapshot_api'; -import { FtrProviderContext } from '../../ftr_provider_context'; -import { DATES } from './constants'; +import type { SupertestWithRoleScopeType } from '../../../services'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; +import { DATES } from './utils/constants'; -export default function ({ getService }: FtrProviderContext) { +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const esArchiver = getService('esArchiver'); - const supertest = getService('supertest'); - const fetchSnapshot = async ( - body: SnapshotRequest, - expectedStatusCode = 200 - ): Promise => { - const response = await supertest - .post('/api/metrics/snapshot') - .set('kbn-xsrf', 'xxx') - .send(body) - .expect(expectedStatusCode); - return response.body; - }; - - describe('waffle nodes', () => { + const roleScopedSupertest = getService('roleScopedSupertest'); + + describe('POST /api/metrics/snapshot', () => { + let supertestWithAdminScope: SupertestWithRoleScopeType; + + const fetchSnapshot = async ( + body: SnapshotRequest, + expectedStatusCode = 200 + ): Promise => { + const response = await supertestWithAdminScope + .post('/api/metrics/snapshot') + .send(body) + .expect(expectedStatusCode); + return response.body; + }; + + before(async () => { + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); + }); + after(async () => { + await supertestWithAdminScope.destroy(); + }); + describe('6.6.0', () => { const { min, max } = DATES['6.6.0'].docker; before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/6.6.0/docker')); diff --git a/x-pack/test/api_integration/apis/metrics_ui/sources.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/sources.ts similarity index 70% rename from x-pack/test/api_integration/apis/metrics_ui/sources.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/sources.ts index 8418c8c0087f1..a2f7d7ca591ad 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/sources.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/sources.ts @@ -6,43 +6,53 @@ */ import expect from '@kbn/expect'; - import { MetricsSourceConfigurationResponse, PartialMetricsSourceConfigurationProperties, metricsSourceConfigurationResponseRT, } from '@kbn/infra-plugin/common/metrics_sources'; -import { FtrProviderContext } from '../../ftr_provider_context'; +import type { SupertestWithRoleScopeType } from '../../../services'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; + +const SOURCE_API_URL = '/api/metrics/source'; +const SOURCE_ID = 'default'; -export default function ({ getService }: FtrProviderContext) { +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { const esArchiver = getService('esArchiver'); - const supertest = getService('supertest'); - const SOURCE_API_URL = '/api/metrics/source'; - const SOURCE_ID = 'default'; + const roleScopedSupertest = getService('roleScopedSupertest'); const kibanaServer = getService('kibanaServer'); - describe('sources', () => { + describe('API /api/metrics/source', () => { + let supertestWithAdminScope: SupertestWithRoleScopeType; + + const patchRequest = async ( + body: PartialMetricsSourceConfigurationProperties, + expectedHttpStatusCode = 200 + ): Promise => { + const response = await supertestWithAdminScope + .patch(`${SOURCE_API_URL}/${SOURCE_ID}`) + .send(body) + .expect(expectedHttpStatusCode); + return response.body; + }; + before(async () => { + supertestWithAdminScope = await roleScopedSupertest.getSupertestWithRoleScope('admin', { + withInternalHeaders: true, + }); await esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs'); await kibanaServer.savedObjects.cleanStandardList(); }); after(async () => { await esArchiver.unload('x-pack/test/functional/es_archives/infra/metrics_and_logs'); - await kibanaServer.savedObjects.cleanStandardList(); + await supertestWithAdminScope.destroy(); }); - const patchRequest = async ( - body: PartialMetricsSourceConfigurationProperties - ): Promise => { - const response = await supertest - .patch(`${SOURCE_API_URL}/${SOURCE_ID}`) - .set('kbn-xsrf', 'xxx') - .send(body) - .expect(200); - return response.body; - }; + beforeEach(async () => { + await kibanaServer.savedObjects.cleanStandardList(); + }); - describe('patch request', () => { + describe('PATCH /api/metrics/source/{sourceId}', () => { it('applies all top-level field updates to an existing source', async () => { const creationResponse = await patchRequest({ name: 'NAME', @@ -108,41 +118,50 @@ export default function ({ getService }: FtrProviderContext) { it('validates anomalyThreshold is between range 1-100', async () => { // create config with bad request - await supertest - .patch(`${SOURCE_API_URL}/${SOURCE_ID}`) - .set('kbn-xsrf', 'xxx') - .send({ name: 'NAME', anomalyThreshold: -20 }) - .expect(400); + await patchRequest({ name: 'NAME', anomalyThreshold: -20 }, 400); + // create config with good request - await supertest - .patch(`${SOURCE_API_URL}/${SOURCE_ID}`) + await patchRequest({ name: 'NAME', anomalyThreshold: 20 }); + await patchRequest({ anomalyThreshold: -2 }, 400); + await patchRequest({ anomalyThreshold: 101 }, 400); + }); + }); + + describe('GET /api/metrics/source/{sourceId}', () => { + it('should just work', async () => { + const { body } = await supertestWithAdminScope + .get('/api/metrics/source/default') .set('kbn-xsrf', 'xxx') - .send({ name: 'NAME', anomalyThreshold: 20 }) .expect(200); - await supertest - .patch(`${SOURCE_API_URL}/${SOURCE_ID}`) - .set('kbn-xsrf', 'xxx') - .send({ anomalyThreshold: -2 }) - .expect(400); - await supertest - .patch(`${SOURCE_API_URL}/${SOURCE_ID}`) - .set('kbn-xsrf', 'xxx') - .send({ anomalyThreshold: 101 }) - .expect(400); + expect(body).to.have.property('source'); + expect(body?.source.configuration.metricAlias).to.equal('metrics-*,metricbeat-*'); + expect(body?.source).to.have.property('status'); + expect(body?.source.status?.metricIndicesExist).to.equal(true); + }); + }); + + describe('GET /api/metrics/source/{sourceId}/hasData', () => { + it('should just work', async () => { + const { body } = await supertestWithAdminScope + .get(`/api/metrics/source/default/hasData`) + + .expect(200); + + expect(body).to.have.property('hasData'); + expect(body?.hasData).to.be(true); }); }); - describe('has data', () => { + describe('GET /api/metrics/source/hasData', () => { const makeRequest = async (params?: { modules?: string[]; expectedHttpStatusCode?: number; }) => { const { modules, expectedHttpStatusCode = 200 } = params ?? {}; - return supertest + return supertestWithAdminScope .get(`${SOURCE_API_URL}/hasData`) .query(modules ? { modules } : '') - .set('kbn-xsrf', 'xxx') .expect(expectedHttpStatusCode); }; diff --git a/x-pack/test/api_integration/apis/metrics_ui/constants.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/utils/constants.ts similarity index 100% rename from x-pack/test/api_integration/apis/metrics_ui/constants.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/utils/constants.ts diff --git a/x-pack/test/api_integration/apis/metrics_ui/create_fake_logger.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/utils/create_fake_logger.ts similarity index 100% rename from x-pack/test/api_integration/apis/metrics_ui/create_fake_logger.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/infra/utils/create_fake_logger.ts diff --git a/x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.index.ts b/x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.index.ts index d9ee2daa42aac..f2c5db3840af8 100644 --- a/x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.index.ts +++ b/x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.index.ts @@ -19,5 +19,6 @@ export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) loadTestFile(require.resolve('../../apis/painless_lab')); loadTestFile(require.resolve('../../apis/saved_objects_management')); loadTestFile(require.resolve('../../apis/observability/slo')); + loadTestFile(require.resolve('../../apis/observability/infra')); }); } diff --git a/x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts b/x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts index 245663416243f..6437d5ea55de3 100644 --- a/x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts +++ b/x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts @@ -10,6 +10,7 @@ import { createServerlessTestConfig } from '../../default_configs/serverless.con export default createServerlessTestConfig({ serverlessProject: 'oblt', testFiles: [require.resolve('./oblt.index.ts')], + suiteTags: { exclude: ['skipSvlOblt'] }, junit: { reportName: 'Serverless Observability - Deployment-agnostic API Integration Tests', }, diff --git a/x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.index.ts b/x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.index.ts index a467264698e57..06eaa9cc217b1 100644 --- a/x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.index.ts +++ b/x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.index.ts @@ -13,5 +13,6 @@ export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) loadTestFile(require.resolve('../../apis/observability/alerting')); loadTestFile(require.resolve('../../apis/observability/dataset_quality')); loadTestFile(require.resolve('../../apis/observability/slo')); + loadTestFile(require.resolve('../../apis/observability/infra')); }); } diff --git a/x-pack/test/common/services/apm_synthtrace_kibana_client.ts b/x-pack/test/api_integration/deployment_agnostic/services/apm_synthtrace_kibana_client.ts similarity index 90% rename from x-pack/test/common/services/apm_synthtrace_kibana_client.ts rename to x-pack/test/api_integration/deployment_agnostic/services/apm_synthtrace_kibana_client.ts index 63bbd917f93ea..88bd2f615fc46 100644 --- a/x-pack/test/common/services/apm_synthtrace_kibana_client.ts +++ b/x-pack/test/api_integration/deployment_agnostic/services/apm_synthtrace_kibana_client.ts @@ -11,10 +11,12 @@ import { ApmSynthtraceKibanaClient, createLogger, LogLevel } from '@kbn/apm-synt const getKibanaServerUrlWithAuth = () => { const kibanaServerUrl = url.format(kbnTestConfig.getUrlParts() as url.UrlObject); + + const { username, password } = kbnTestConfig.getUrlParts(); const kibanaServerUrlWithAuth = url .format({ ...url.parse(kibanaServerUrl), - auth: `elastic:${kbnTestConfig.getUrlParts().password}`, + auth: `${username}:${password}`, }) .slice(0, -1); return kibanaServerUrlWithAuth; diff --git a/x-pack/test/api_integration/deployment_agnostic/services/index.ts b/x-pack/test/api_integration/deployment_agnostic/services/index.ts index bea63ea216c93..a7b07081c03ec 100644 --- a/x-pack/test/api_integration/deployment_agnostic/services/index.ts +++ b/x-pack/test/api_integration/deployment_agnostic/services/index.ts @@ -13,6 +13,7 @@ import { PackageApiProvider } from './package_api'; import { RoleScopedSupertestProvider, SupertestWithRoleScope } from './role_scoped_supertest'; import { SloApiProvider } from './slo_api'; import { LogsSynthtraceEsClientProvider } from './logs_synthtrace_es_client'; +import { ApmSynthtraceKibanaClientProvider } from './apm_synthtrace_kibana_client'; export type { InternalRequestHeader, @@ -30,6 +31,7 @@ export const services = { sloApi: SloApiProvider, roleScopedSupertest: RoleScopedSupertestProvider, logsSynthtraceEsClient: LogsSynthtraceEsClientProvider, + apmSynthtraceKibanaClient: ApmSynthtraceKibanaClientProvider, // create a new deployment-agnostic service and load here }; diff --git a/x-pack/test/api_integration/deployment_agnostic/services/role_scoped_supertest.ts b/x-pack/test/api_integration/deployment_agnostic/services/role_scoped_supertest.ts index 41853cadbe86c..35c8bde01f0a6 100644 --- a/x-pack/test/api_integration/deployment_agnostic/services/role_scoped_supertest.ts +++ b/x-pack/test/api_integration/deployment_agnostic/services/role_scoped_supertest.ts @@ -83,7 +83,7 @@ export class SupertestWithRoleScope { return agent; } - private request(method: 'post' | 'get' | 'put' | 'delete', url: string): Test { + private request(method: 'post' | 'get' | 'put' | 'delete' | 'patch', url: string): Test { if (!this.authValue) { throw new Error('Instance has been destroyed and cannot be used for making requests.'); } @@ -106,6 +106,10 @@ export class SupertestWithRoleScope { delete(url: string) { return this.request('delete', url); } + + patch(url: string) { + return this.request('patch', url); + } } /** diff --git a/x-pack/test/common/services/index.ts b/x-pack/test/common/services/index.ts index edf64c828e944..724404c618d15 100644 --- a/x-pack/test/common/services/index.ts +++ b/x-pack/test/common/services/index.ts @@ -11,7 +11,6 @@ import { commonFunctionalUIServices } from '@kbn/ftr-common-functional-ui-servic import { InfraLogViewsServiceProvider } from './infra_log_views'; import { SpacesServiceProvider } from './spaces'; import { BsearchSecureService } from './bsearch_secure'; -import { ApmSynthtraceKibanaClientProvider } from './apm_synthtrace_kibana_client'; import { InfraSynthtraceKibanaClientProvider } from './infra_synthtrace_kibana_client'; export const services = { @@ -21,6 +20,5 @@ export const services = { supertest: kibanaApiIntegrationServices.supertest, spaces: SpacesServiceProvider, secureBsearch: BsearchSecureService, - apmSynthtraceKibanaClient: ApmSynthtraceKibanaClientProvider, infraSynthtraceKibanaClient: InfraSynthtraceKibanaClientProvider, }; diff --git a/x-pack/test/functional/es_archives/infra/alerts/mappings.json b/x-pack/test/functional/es_archives/infra/alerts/mappings.json index 5f9441a669f89..7088e3c666719 100644 --- a/x-pack/test/functional/es_archives/infra/alerts/mappings.json +++ b/x-pack/test/functional/es_archives/infra/alerts/mappings.json @@ -266,10 +266,6 @@ }, "settings": { "index": { - "lifecycle": { - "name": ".alerts-ilm-policy", - "rollover_alias": ".alerts-observability.apm.alerts-default" - }, "number_of_replicas": "1", "number_of_shards": "1" } @@ -521,10 +517,6 @@ }, "settings": { "index": { - "lifecycle": { - "name": ".alerts-ilm-policy", - "rollover_alias": ".alerts-observability.logs.alerts-default" - }, "number_of_replicas": "1", "number_of_shards": "1" } @@ -776,10 +768,6 @@ }, "settings": { "index": { - "lifecycle": { - "name": ".alerts-ilm-policy", - "rollover_alias": ".alerts-observability.metrics.alerts-default" - }, "number_of_replicas": "1", "number_of_shards": "1" } diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/config.feature_flags.ts b/x-pack/test_serverless/api_integration/test_suites/observability/config.feature_flags.ts index 3668b6742c828..a78f876361480 100644 --- a/x-pack/test_serverless/api_integration/test_suites/observability/config.feature_flags.ts +++ b/x-pack/test_serverless/api_integration/test_suites/observability/config.feature_flags.ts @@ -21,7 +21,6 @@ export default createTestConfig({ services, // add feature flags kbnServerArgs: [ - '--xpack.infra.enabled=true', '--xpack.security.roleManagementEnabled=true', // needed to check composite feautures in /observability/platform_security/authorization.ts ], // load tests in the index file diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/index.feature_flags.ts b/x-pack/test_serverless/api_integration/test_suites/observability/index.feature_flags.ts index 3cd47636831f3..7ed6ca9517ac4 100644 --- a/x-pack/test_serverless/api_integration/test_suites/observability/index.feature_flags.ts +++ b/x-pack/test_serverless/api_integration/test_suites/observability/index.feature_flags.ts @@ -10,7 +10,6 @@ import { FtrProviderContext } from '../../ftr_provider_context'; export default function ({ loadTestFile }: FtrProviderContext) { describe('Serverless observability API - feature flags', function () { loadTestFile(require.resolve('./custom_threshold_rule')); - loadTestFile(require.resolve('./infra')); loadTestFile(require.resolve('./platform_security')); }); } diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/infra/constants.ts b/x-pack/test_serverless/api_integration/test_suites/observability/infra/constants.ts deleted file mode 100644 index 368ff72a388c2..0000000000000 --- a/x-pack/test_serverless/api_integration/test_suites/observability/infra/constants.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. - */ - -export const DATES = { - serverlessTestingHost: { - min: 1679873400139, - max: 1680027672003, - }, - serverlessTestingHostDateString: { - min: '2023-03-26T23:30:00.139Z', - max: '2023-03-28T23:30:00.139Z', - }, -}; - -export const ARCHIVE_NAME = 'x-pack/test/functional/es_archives/infra/serverless_testing_host'; diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/infra/index.ts b/x-pack/test_serverless/api_integration/test_suites/observability/infra/index.ts deleted file mode 100644 index 6db6e330c3022..0000000000000 --- a/x-pack/test_serverless/api_integration/test_suites/observability/infra/index.ts +++ /dev/null @@ -1,22 +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 type { FtrProviderContext } from '../../../ftr_provider_context'; - -export default function ({ loadTestFile }: FtrProviderContext) { - describe('Infra UI', function () { - // all these tests are failing on MKI: - // Error: expected 200 "OK", got 404 "Not Found" - this.tags(['failsOnMKI']); - - loadTestFile(require.resolve('./metadata')); - loadTestFile(require.resolve('./snapshot')); - loadTestFile(require.resolve('./processes')); - loadTestFile(require.resolve('./infra')); - loadTestFile(require.resolve('./asset_count')); - }); -} diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/infra/infra.ts b/x-pack/test_serverless/api_integration/test_suites/observability/infra/infra.ts deleted file mode 100644 index c4cbfd45663b1..0000000000000 --- a/x-pack/test_serverless/api_integration/test_suites/observability/infra/infra.ts +++ /dev/null @@ -1,129 +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 type { - GetInfraMetricsRequestBodyPayloadClient, - GetInfraMetricsResponsePayload, -} from '@kbn/infra-plugin/common/http_api'; -import type { RoleCredentials } from '../../../../shared/services'; -import type { FtrProviderContext } from '../../../ftr_provider_context'; - -import { DATES, ARCHIVE_NAME } from './constants'; - -const timeRange = { - from: DATES.serverlessTestingHostDateString.min, - to: DATES.serverlessTestingHostDateString.max, -}; - -export default function ({ getService }: FtrProviderContext) { - const esArchiver = getService('esArchiver'); - const supertestWithoutAuth = getService('supertestWithoutAuth'); - const svlUserManager = getService('svlUserManager'); - const svlCommonApi = getService('svlCommonApi'); - - const fetchInfraHosts = async ( - body: GetInfraMetricsRequestBodyPayloadClient, - roleAuthc: RoleCredentials - ): Promise => { - const response = await supertestWithoutAuth - .post('/api/metrics/infra/host') - .set(svlCommonApi.getInternalRequestHeader()) - .set(roleAuthc.apiKeyHeader) - .send(body) - .expect(200); - return response.body; - }; - - describe('API /metrics/infra/host', () => { - let roleAuthc: RoleCredentials; - describe('works', () => { - describe('with host asset', () => { - before(async () => { - roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin'); - return esArchiver.load(ARCHIVE_NAME); - }); - after(async () => { - await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc); - return esArchiver.unload(ARCHIVE_NAME); - }); - - it('received data', async () => { - const infraHosts = await fetchInfraHosts( - { - limit: 100, - metrics: ['rxV2', 'txV2', 'memory', 'cpuV2', 'diskSpaceUsage', 'memoryFree'], - query: { - bool: { - must: [], - filter: [], - should: [], - must_not: [], - }, - }, - from: timeRange.from, - to: timeRange.to, - }, - roleAuthc - ); - - if (infraHosts) { - const { nodes } = infraHosts; - expect(nodes.length).to.equal(1); - const firstNode = nodes[0]; - expect(firstNode).to.eql({ - metadata: [ - { - name: 'host.os.name', - value: 'macOS', - }, - { - name: 'cloud.provider', - value: null, - }, - { - name: 'host.ip', - value: '192.168.1.79', - }, - ], - metrics: [ - { - name: 'rxV2', - value: 17886.18845261874, - }, - { - name: 'txV2', - value: 18216.85858680644, - }, - { - name: 'memory', - value: 0.9490000000000001, - }, - { - name: 'cpuV2', - value: 0.124, - }, - { - name: 'diskSpaceUsage', - value: null, - }, - { - name: 'memoryFree', - value: 1753829376, - }, - ], - hasSystemMetrics: true, - name: 'serverless-host', - }); - } else { - throw new Error('Hosts response should not be empty'); - } - }); - }); - }); - }); -} diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/infra/metadata.ts b/x-pack/test_serverless/api_integration/test_suites/observability/infra/metadata.ts deleted file mode 100644 index c50fe1bcb4928..0000000000000 --- a/x-pack/test_serverless/api_integration/test_suites/observability/infra/metadata.ts +++ /dev/null @@ -1,132 +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 type { - InfraMetadata, - InfraMetadataRequest, -} from '@kbn/infra-plugin/common/http_api/metadata_api'; -import type { RoleCredentials } from '../../../../shared/services'; -import type { FtrProviderContext } from '../../../ftr_provider_context'; - -import { DATES, ARCHIVE_NAME } from './constants'; - -const timeRange = { - from: DATES.serverlessTestingHost.min, - to: DATES.serverlessTestingHost.max, -}; - -export default function ({ getService }: FtrProviderContext) { - const esArchiver = getService('esArchiver'); - const supertestWithoutAuth = getService('supertestWithoutAuth'); - const svlUserManager = getService('svlUserManager'); - const svlCommonApi = getService('svlCommonApi'); - - const fetchMetadata = async ( - body: InfraMetadataRequest, - roleAuthc: RoleCredentials - ): Promise => { - const response = await supertestWithoutAuth - .post('/api/infra/metadata') - .set(svlCommonApi.getInternalRequestHeader()) - .set(roleAuthc.apiKeyHeader) - .send(body) - .expect(200); - return response.body; - }; - - describe('API /infra/metadata', () => { - let roleAuthc: RoleCredentials; - describe('works', () => { - describe('Host asset type', () => { - before(async () => { - roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin'); - await esArchiver.load(ARCHIVE_NAME); - }); - after(async () => { - await esArchiver.unload(ARCHIVE_NAME); - await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc); - }); - it('with serverless existing host', async () => { - const metadata = await fetchMetadata( - { - sourceId: 'default', - nodeId: 'serverless-host', - nodeType: 'host', - timeRange, - }, - roleAuthc - ); - - if (metadata) { - expect(metadata.features.length).to.be(4); - expect(metadata.name).to.equal('serverless-host'); - expect(metadata.hasSystemIntegration).to.equal(true); - expect(new Date(metadata.info?.timestamp ?? '')?.getTime()).to.be.above(timeRange.from); - expect(new Date(metadata.info?.timestamp ?? '')?.getTime()).to.be.below(timeRange.to); - expect(metadata.info?.agent).to.eql({ - ephemeral_id: '64624d22-1eeb-4267-ac92-b11a1d09c0ba', - id: '3ce5be59-af6a-4668-8f6d-90282a3f820e', - name: 'serverless-host', - type: 'metricbeat', - version: '8.5.0', - }); - expect(metadata.info?.host).to.eql({ - hostname: 'serverless-host', - os: { - build: '22D68', - family: 'darwin', - kernel: '22.3.0', - name: 'macOS', - platform: 'darwin', - type: 'macos', - version: '13.2.1', - }, - id: '47B6A5A5-3134-516A-831B-A9BCA597470C', - ip: [ - 'fe80::3cdd:4bff:fe37:4ce2', - 'fe80::3cdd:4bff:fe37:4ce3', - 'fe80::3cdd:4bff:fe37:4ce1', - 'fe80::bcd0:74ff:fe6e:f2d2', - 'fe80::10cb:77ec:4d5f:e2c7', - 'fd00::47e:cfa4:41d8:c1f6', - '192.168.1.79', - '2003:cd:373d:9600:1f:71d7:cd48:92d4', - '2003:cd:373d:9600:98e0:7ccf:7d02:9ca', - '2003:cd:373d:9600:58a5:f02:405:6cd8', - '2003:cd:373d:9600:f068:9ad1:7ed4:d706', - 'fe80::1ca7:1dff:fe98:2d66', - 'fe80::1ca7:1dff:fe98:2d66', - 'fe80::564c:747a:5670:520c', - 'fe80::205d:bb00:46bf:10e1', - 'fe80::ce81:b1c:bd2c:69e', - ], - mac: [ - '1E-A7-1D-98-2D-66', - '36-5D-68-05-71-00', - '36-5D-68-05-71-04', - '36-5D-68-05-71-08', - '3E-DD-4B-37-4C-C1', - '3E-DD-4B-37-4C-C2', - '3E-DD-4B-37-4C-C3', - '3E-DD-4B-37-4C-E1', - '3E-DD-4B-37-4C-E2', - '3E-DD-4B-37-4C-E3', - 'BC-D0-74-6E-F2-D2', - 'BE-D0-74-6E-F2-D2', - ], - name: 'serverless-host', - architecture: 'arm64', - }); - } else { - throw new Error('Metadata should never be empty'); - } - }); - }); - }); - }); -} diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/infra/processes.ts b/x-pack/test_serverless/api_integration/test_suites/observability/infra/processes.ts deleted file mode 100644 index da811f1482bad..0000000000000 --- a/x-pack/test_serverless/api_integration/test_suites/observability/infra/processes.ts +++ /dev/null @@ -1,67 +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 { - ProcessListAPIRequestRT, - ProcessListAPIResponseRT, -} from '@kbn/infra-plugin/common/http_api/host_details/process_list'; -import { decodeOrThrow } from '@kbn/io-ts-utils'; -import type { RoleCredentials } from '../../../../shared/services'; - -import type { FtrProviderContext } from '../../../ftr_provider_context'; -import { DATES, ARCHIVE_NAME } from './constants'; - -export default function ({ getService }: FtrProviderContext) { - const esArchiver = getService('esArchiver'); - const supertestWithoutAuth = getService('supertestWithoutAuth'); - const svlUserManager = getService('svlUserManager'); - const svlCommonApi = getService('svlCommonApi'); - - describe('API /metrics/process_list', () => { - let roleAuthc: RoleCredentials; - before(async () => { - roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin'); - await esArchiver.load(ARCHIVE_NAME); - }); - after(async () => { - await esArchiver.unload(ARCHIVE_NAME); - await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc); - }); - - it('works', async () => { - const response = await supertestWithoutAuth - .post('/api/metrics/process_list') - .set(svlCommonApi.getInternalRequestHeader()) - .set(roleAuthc.apiKeyHeader) - .send( - ProcessListAPIRequestRT.encode({ - hostTerm: { - 'host.name': 'serverless-host', - }, - sourceId: 'default', - to: DATES.serverlessTestingHost.max, - sortBy: { - name: 'cpu', - isAscending: false, - }, - searchFilter: [ - { - match_all: {}, - }, - ], - }) - ) - .expect(200); - - const { processList, summary } = decodeOrThrow(ProcessListAPIResponseRT)(response.body); - - expect(processList.length).to.be(3); - expect(summary.total).to.be(313); - }); - }); -} diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/infra/snapshot.ts b/x-pack/test_serverless/api_integration/test_suites/observability/infra/snapshot.ts deleted file mode 100644 index 21d902213a08c..0000000000000 --- a/x-pack/test_serverless/api_integration/test_suites/observability/infra/snapshot.ts +++ /dev/null @@ -1,91 +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 type { - SnapshotNodeResponse, - SnapshotRequest, -} from '@kbn/infra-plugin/common/http_api/snapshot_api'; -import type { RoleCredentials } from '../../../../shared/services'; -import type { FtrProviderContext } from '../../../ftr_provider_context'; - -import { DATES, ARCHIVE_NAME } from './constants'; - -export default function ({ getService }: FtrProviderContext) { - const esArchiver = getService('esArchiver'); - const supertestWithoutAuth = getService('supertestWithoutAuth'); - const svlUserManager = getService('svlUserManager'); - const svlCommonApi = getService('svlCommonApi'); - - const fetchSnapshot = async ( - body: SnapshotRequest, - roleAuthc: RoleCredentials - ): Promise => { - const response = await supertestWithoutAuth - .post('/api/metrics/snapshot') - .set(svlCommonApi.getInternalRequestHeader()) - .set(roleAuthc.apiKeyHeader) - .send(body) - .expect(200); - return response.body; - }; - - describe('API /metrics/snapshot', () => { - let roleAuthc: RoleCredentials; - - describe('Snapshot nodes', () => { - const { min, max } = DATES.serverlessTestingHost; - before(async () => { - roleAuthc = await svlUserManager.createM2mApiKeyWithRoleScope('admin'); - await esArchiver.load(ARCHIVE_NAME); - }); - after(async () => { - await esArchiver.unload(ARCHIVE_NAME); - await svlUserManager.invalidateM2mApiKeyWithRoleScope(roleAuthc); - }); - - it('should work', async () => { - const snapshot = await fetchSnapshot( - { - sourceId: 'default', - timerange: { - to: max, - from: min, - interval: '10m', - }, - metrics: [{ type: 'cpu' }], - nodeType: 'host', - groupBy: [], - includeTimeseries: false, - }, - roleAuthc - ); - - if (!snapshot) { - return; - } - - expect(snapshot).to.have.property('nodes'); - - const { nodes } = snapshot; - expect(nodes.length).to.equal(1); - if (snapshot) { - const firstNode = nodes[0]; - expect(firstNode).to.have.property('path'); - expect(firstNode.path.length).to.equal(1); - expect(firstNode.path[0]).to.eql({ - value: 'serverless-host', - label: 'serverless-host', - ip: '192.168.1.79', - os: 'macOS', - cloudProvider: null, - }); - } - }); - }); - }); -}