From c4a5ebf54c113726bc86825b661d40afaf221197 Mon Sep 17 00:00:00 2001 From: Ash <1849116+ashokaditya@users.noreply.github.com> Date: Thu, 7 Nov 2024 18:43:10 +0100 Subject: [PATCH] [8.x] [Data Usage] setup integration tests (#197112) (#199305) > [!Warning] > The following files were updated as a result of merge conflicts that should be reviewed > - `/x-pack/test_serverless/api_integration/test_suites/security/config.ts` > - `/x-pack/test_serverless/functional/test_suites/search/config.ts` > - `/x-pack/test_serverless/tsconfig.json` # Backport This will backport the following commits from `main` to `8.x`: - [[Data Usage] setup integration tests (#197112)](https://github.com/elastic/kibana/pull/197112) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) --------- Signed-off-by: Ash <1849116+ashokaditya@users.noreply.github.com> Co-authored-by: Sandra G Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .../common/rest_types/usage_metrics.ts | 11 +- .../routes/internal/usage_metrics_handler.ts | 17 ++- .../data_usage/server/services/autoops_api.ts | 5 +- .../data_usage/server/services/index.ts | 2 +- .../test_suites/common/data_usage/index.ts | 17 +++ .../test_suites/common/data_usage/mock_api.ts | 23 ++++ .../common/data_usage/mock_data.ts | 43 +++++++ .../common/data_usage/tests/data_streams.ts | 56 +++++++++ .../common/data_usage/tests/metrics.ts | 110 ++++++++++++++++++ .../common_configs/config.group1.ts | 1 + .../test_suites/observability/config.ts | 9 +- .../search/common_configs/config.group1.ts | 1 + .../test_suites/search/config.ts | 8 ++ .../security/common_configs/config.group1.ts | 1 + .../test_suites/security/config.ts | 8 ++ .../page_objects/svl_management_page.ts | 8 ++ .../test_suites/common/data_usage/index.ts | 14 +++ .../test_suites/common/data_usage/main.ts | 35 ++++++ .../common_configs/config.group1.ts | 1 + .../test_suites/observability/config.ts | 12 +- .../search/common_configs/config.group1.ts | 1 + .../functional/test_suites/search/config.ts | 9 +- .../security/common_configs/config.group1.ts | 1 + .../functional/test_suites/security/config.ts | 11 +- x-pack/test_serverless/tsconfig.json | 1 + 25 files changed, 392 insertions(+), 13 deletions(-) create mode 100644 x-pack/test_serverless/api_integration/test_suites/common/data_usage/index.ts create mode 100644 x-pack/test_serverless/api_integration/test_suites/common/data_usage/mock_api.ts create mode 100644 x-pack/test_serverless/api_integration/test_suites/common/data_usage/mock_data.ts create mode 100644 x-pack/test_serverless/api_integration/test_suites/common/data_usage/tests/data_streams.ts create mode 100644 x-pack/test_serverless/api_integration/test_suites/common/data_usage/tests/metrics.ts create mode 100644 x-pack/test_serverless/functional/test_suites/common/data_usage/index.ts create mode 100644 x-pack/test_serverless/functional/test_suites/common/data_usage/main.ts diff --git a/x-pack/plugins/data_usage/common/rest_types/usage_metrics.ts b/x-pack/plugins/data_usage/common/rest_types/usage_metrics.ts index 40194494854fc..853da3b3f8cbd 100644 --- a/x-pack/plugins/data_usage/common/rest_types/usage_metrics.ts +++ b/x-pack/plugins/data_usage/common/rest_types/usage_metrics.ts @@ -123,6 +123,13 @@ export const UsageMetricsAutoOpsResponseSchema = { ), }), }; -export type UsageMetricsAutoOpsResponseSchemaBody = TypeOf< +export type UsageMetricsAutoOpsResponseMetricSeries = TypeOf< typeof UsageMetricsAutoOpsResponseSchema.body ->; +>['metrics'][MetricTypes][number]; + +export type UsageMetricsAutoOpsResponseSchemaBody = Omit< + TypeOf, + 'metrics' +> & { + metrics: Partial>; +}; diff --git a/x-pack/plugins/data_usage/server/routes/internal/usage_metrics_handler.ts b/x-pack/plugins/data_usage/server/routes/internal/usage_metrics_handler.ts index 93b31033fc4fb..a714259e1e11c 100644 --- a/x-pack/plugins/data_usage/server/routes/internal/usage_metrics_handler.ts +++ b/x-pack/plugins/data_usage/server/routes/internal/usage_metrics_handler.ts @@ -6,7 +6,6 @@ */ import { RequestHandler } from '@kbn/core/server'; -import { IndicesGetDataStreamResponse } from '@elastic/elasticsearch/lib/api/types'; import { MetricTypes, UsageMetricsAutoOpsResponseSchemaBody, @@ -44,12 +43,22 @@ export const getUsageMetricsHandler = ( new CustomHttpRequestError('[request body.dataStreams]: no data streams selected', 400) ); } + let dataStreamsResponse; - const { data_streams: dataStreamsResponse }: IndicesGetDataStreamResponse = - await esClient.indices.getDataStream({ + try { + // Attempt to fetch data streams + const { data_streams: dataStreams } = await esClient.indices.getDataStream({ name: requestDsNames, expand_wildcards: 'all', }); + dataStreamsResponse = dataStreams; + } catch (error) { + return errorHandler( + logger, + response, + new CustomHttpRequestError('Failed to retrieve data streams', 400) + ); + } const metrics = await dataUsageService.getMetrics({ from, to, @@ -69,7 +78,7 @@ export const getUsageMetricsHandler = ( }; }; -function transformMetricsData( +export function transformMetricsData( data: UsageMetricsAutoOpsResponseSchemaBody ): UsageMetricsResponseSchemaBody { return { diff --git a/x-pack/plugins/data_usage/server/services/autoops_api.ts b/x-pack/plugins/data_usage/server/services/autoops_api.ts index e5ffe24c6167a..6a9de27f996f1 100644 --- a/x-pack/plugins/data_usage/server/services/autoops_api.ts +++ b/x-pack/plugins/data_usage/server/services/autoops_api.ts @@ -13,6 +13,7 @@ import type { AxiosError, AxiosRequestConfig } from 'axios'; import axios from 'axios'; import { LogMeta } from '@kbn/core/server'; import { + UsageMetricsAutoOpsResponseSchema, UsageMetricsAutoOpsResponseSchemaBody, UsageMetricsRequestBody, } from '../../common/rest_types'; @@ -134,8 +135,10 @@ export class AutoOpsAPIService { } ); + const validatedResponse = UsageMetricsAutoOpsResponseSchema.body().validate(response.data); + logger.debug(`[AutoOps API] Successfully created an autoops agent ${response}`); - return response; + return validatedResponse; } private createTlsConfig(autoopsConfig: AutoOpsConfig | undefined) { diff --git a/x-pack/plugins/data_usage/server/services/index.ts b/x-pack/plugins/data_usage/server/services/index.ts index 9ccd08861a26c..3752553e50e9f 100644 --- a/x-pack/plugins/data_usage/server/services/index.ts +++ b/x-pack/plugins/data_usage/server/services/index.ts @@ -41,7 +41,7 @@ export class DataUsageService { metricTypes, dataStreams, }); - return response.data; + return response; } catch (error) { if (error instanceof ValidationError) { throw new AutoOpsError(error.message); diff --git a/x-pack/test_serverless/api_integration/test_suites/common/data_usage/index.ts b/x-pack/test_serverless/api_integration/test_suites/common/data_usage/index.ts new file mode 100644 index 0000000000000..cf31e1885d1d5 --- /dev/null +++ b/x-pack/test_serverless/api_integration/test_suites/common/data_usage/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { FtrProviderContext } from '../../../ftr_provider_context'; + +export default function ({ loadTestFile }: FtrProviderContext) { + describe('Serverless Data Usage APIs', function () { + this.tags(['esGate']); + + loadTestFile(require.resolve('./tests/data_streams')); + loadTestFile(require.resolve('./tests/metrics')); + }); +} diff --git a/x-pack/test_serverless/api_integration/test_suites/common/data_usage/mock_api.ts b/x-pack/test_serverless/api_integration/test_suites/common/data_usage/mock_api.ts new file mode 100644 index 0000000000000..0a9438e826ef3 --- /dev/null +++ b/x-pack/test_serverless/api_integration/test_suites/common/data_usage/mock_api.ts @@ -0,0 +1,23 @@ +/* + * 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 { createServer } from '@mswjs/http-middleware'; +import { UsageMetricsAutoOpsResponseSchemaBody } from '@kbn/data-usage-plugin/common/rest_types'; +import { http, HttpResponse, StrictResponse } from 'msw'; +import { mockAutoOpsResponse } from './mock_data'; + +export const setupMockServer = () => { + const server = createServer(autoOpsHandler); + return server; +}; + +const autoOpsHandler = http.post( + '/', + async ({ request }): Promise> => { + return HttpResponse.json(mockAutoOpsResponse); + } +); diff --git a/x-pack/test_serverless/api_integration/test_suites/common/data_usage/mock_data.ts b/x-pack/test_serverless/api_integration/test_suites/common/data_usage/mock_data.ts new file mode 100644 index 0000000000000..c38cc57d2b546 --- /dev/null +++ b/x-pack/test_serverless/api_integration/test_suites/common/data_usage/mock_data.ts @@ -0,0 +1,43 @@ +/* + * 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 mockAutoOpsResponse = { + metrics: { + ingest_rate: [ + { + name: 'metrics-system.cpu-default', + data: [ + [1726858530000, 13756849], + [1726862130000, 14657904], + ], + }, + { + name: 'logs-nginx.access-default', + data: [ + [1726858530000, 12894623], + [1726862130000, 14436905], + ], + }, + ], + storage_retained: [ + { + name: 'metrics-system.cpu-default', + data: [ + [1726858530000, 12576413], + [1726862130000, 13956423], + ], + }, + { + name: 'logs-nginx.access-default', + data: [ + [1726858530000, 12894623], + [1726862130000, 14436905], + ], + }, + ], + }, +}; diff --git a/x-pack/test_serverless/api_integration/test_suites/common/data_usage/tests/data_streams.ts b/x-pack/test_serverless/api_integration/test_suites/common/data_usage/tests/data_streams.ts new file mode 100644 index 0000000000000..d805b8ccff6fe --- /dev/null +++ b/x-pack/test_serverless/api_integration/test_suites/common/data_usage/tests/data_streams.ts @@ -0,0 +1,56 @@ +/* + * 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 { SupertestWithRoleScope } from '@kbn/test-suites-xpack/api_integration/deployment_agnostic/services/role_scoped_supertest'; +import { DataStreamsResponseBodySchemaBody } from '@kbn/data-usage-plugin/common/rest_types'; +import { DATA_USAGE_DATA_STREAMS_API_ROUTE } from '@kbn/data-usage-plugin/common'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const svlDatastreamsHelpers = getService('svlDatastreamsHelpers'); + const roleScopedSupertest = getService('roleScopedSupertest'); + let supertestAdminWithCookieCredentials: SupertestWithRoleScope; + const testDataStreamName = 'test-data-stream'; + describe(`GET ${DATA_USAGE_DATA_STREAMS_API_ROUTE}`, function () { + // due to the plugin depending on yml config (xpack.dataUsage.enabled), we cannot test in MKI until it is on by default + this.tags(['skipMKI']); + before(async () => { + await svlDatastreamsHelpers.createDataStream(testDataStreamName); + supertestAdminWithCookieCredentials = await roleScopedSupertest.getSupertestWithRoleScope( + 'admin', + { + useCookieHeader: true, + withInternalHeaders: true, + } + ); + }); + after(async () => { + await svlDatastreamsHelpers.deleteDataStream(testDataStreamName); + }); + + it('returns created data streams', async () => { + const res = await supertestAdminWithCookieCredentials + .get(DATA_USAGE_DATA_STREAMS_API_ROUTE) + .set('elastic-api-version', '1'); + const dataStreams: DataStreamsResponseBodySchemaBody = res.body; + const foundStream = dataStreams.find((stream) => stream.name === testDataStreamName); + expect(foundStream?.name).to.be(testDataStreamName); + expect(foundStream?.storageSizeBytes).to.be(0); + expect(res.statusCode).to.be(200); + }); + it('returns system indices', async () => { + const res = await supertestAdminWithCookieCredentials + .get(DATA_USAGE_DATA_STREAMS_API_ROUTE) + .set('elastic-api-version', '1'); + const dataStreams: DataStreamsResponseBodySchemaBody = res.body; + const systemDataStreams = dataStreams.filter((stream) => stream.name.startsWith('.')); + expect(systemDataStreams.length).to.be.greaterThan(0); + expect(res.statusCode).to.be(200); + }); + }); +} diff --git a/x-pack/test_serverless/api_integration/test_suites/common/data_usage/tests/metrics.ts b/x-pack/test_serverless/api_integration/test_suites/common/data_usage/tests/metrics.ts new file mode 100644 index 0000000000000..8985757ab1cab --- /dev/null +++ b/x-pack/test_serverless/api_integration/test_suites/common/data_usage/tests/metrics.ts @@ -0,0 +1,110 @@ +/* + * 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 http from 'http'; + +import { SupertestWithRoleScope } from '@kbn/test-suites-xpack/api_integration/deployment_agnostic/services/role_scoped_supertest'; +import { UsageMetricsRequestBody } from '@kbn/data-usage-plugin/common/rest_types'; +import { DATA_USAGE_METRICS_API_ROUTE } from '@kbn/data-usage-plugin/common'; +import { transformMetricsData } from '@kbn/data-usage-plugin/server/routes/internal/usage_metrics_handler'; +import { FtrProviderContext } from '../../../../ftr_provider_context'; +import { setupMockServer } from '../mock_api'; +import { mockAutoOpsResponse } from '../mock_data'; + +export default function ({ getService }: FtrProviderContext) { + const svlDatastreamsHelpers = getService('svlDatastreamsHelpers'); + const roleScopedSupertest = getService('roleScopedSupertest'); + let supertestAdminWithCookieCredentials: SupertestWithRoleScope; + const mockAutoopsApiService = setupMockServer(); + describe('Metrics', function () { + let mockApiServer: http.Server; + // due to the plugin depending on yml config (xpack.dataUsage.enabled), we cannot test in MKI until it is on by default + this.tags(['skipMKI']); + + before(async () => { + mockApiServer = mockAutoopsApiService.listen(9000); + supertestAdminWithCookieCredentials = await roleScopedSupertest.getSupertestWithRoleScope( + 'admin', + { + useCookieHeader: true, + withInternalHeaders: true, + } + ); + }); + + after(() => { + mockApiServer.close(); + }); + describe(`POST ${DATA_USAGE_METRICS_API_ROUTE}`, () => { + const testDataStreamName = 'test-data-stream'; + before(async () => await svlDatastreamsHelpers.createDataStream(testDataStreamName)); + after(async () => await svlDatastreamsHelpers.deleteDataStream(testDataStreamName)); + it('returns 400 with non-existent data streams', async () => { + const requestBody: UsageMetricsRequestBody = { + from: 'now-24h/h', + to: 'now', + metricTypes: ['ingest_rate', 'storage_retained'], + dataStreams: ['invalid-data-stream'], + }; + const res = await supertestAdminWithCookieCredentials + .post(DATA_USAGE_METRICS_API_ROUTE) + .set('elastic-api-version', '1') + .send(requestBody); + expect(res.statusCode).to.be(400); + expect(res.body.message).to.be('Failed to retrieve data streams'); + }); + + it('returns 400 when requesting no data streams', async () => { + const requestBody = { + from: 'now-24h/h', + to: 'now', + metricTypes: ['ingest_rate'], + dataStreams: [], + }; + const res = await supertestAdminWithCookieCredentials + .post(DATA_USAGE_METRICS_API_ROUTE) + .set('elastic-api-version', '1') + .send(requestBody); + expect(res.statusCode).to.be(400); + expect(res.body.message).to.be('[request body.dataStreams]: no data streams selected'); + }); + + it('returns 400 when requesting an invalid metric type', async () => { + const requestBody = { + from: 'now-24h/h', + to: 'now', + metricTypes: [testDataStreamName], + dataStreams: ['datastream'], + }; + const res = await supertestAdminWithCookieCredentials + .post(DATA_USAGE_METRICS_API_ROUTE) + .set('elastic-api-version', '1') + .send(requestBody); + expect(res.statusCode).to.be(400); + expect(res.body.message).to.be( + '[request body.metricTypes]: must be one of ingest_rate, storage_retained, search_vcu, ingest_vcu, ml_vcu, index_latency, index_rate, search_latency, search_rate' + ); + }); + + it('returns 200 with valid request', async () => { + const requestBody: UsageMetricsRequestBody = { + from: 'now-24h/h', + to: 'now', + metricTypes: ['ingest_rate', 'storage_retained'], + dataStreams: [testDataStreamName], + }; + const res = await supertestAdminWithCookieCredentials + .post(DATA_USAGE_METRICS_API_ROUTE) + .set('elastic-api-version', '1') + .send(requestBody); + expect(res.statusCode).to.be(200); + expect(res.body).to.eql(transformMetricsData(mockAutoOpsResponse)); + }); + }); + }); +} diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/common_configs/config.group1.ts b/x-pack/test_serverless/api_integration/test_suites/observability/common_configs/config.group1.ts index 4d58d43ea7667..68202b5adf3ad 100644 --- a/x-pack/test_serverless/api_integration/test_suites/observability/common_configs/config.group1.ts +++ b/x-pack/test_serverless/api_integration/test_suites/observability/common_configs/config.group1.ts @@ -32,6 +32,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../common/console'), require.resolve('../../common/saved_objects_management'), require.resolve('../../common/telemetry'), + require.resolve('../../common/data_usage'), ], junit: { reportName: 'Serverless Observability API Integration Tests - Common Group 1', diff --git a/x-pack/test_serverless/api_integration/test_suites/observability/config.ts b/x-pack/test_serverless/api_integration/test_suites/observability/config.ts index 111686fd95d26..97a30d0f340f9 100644 --- a/x-pack/test_serverless/api_integration/test_suites/observability/config.ts +++ b/x-pack/test_serverless/api_integration/test_suites/observability/config.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - +import { CA_CERT_PATH, KBN_CERT_PATH, KBN_KEY_PATH } from '@kbn/dev-utils'; import { createTestConfig } from '../../config.base'; import { services as apmServices } from './apm_api_integration/common/services'; import { services as datasetQualityServices } from './dataset_quality_api_integration/common/services'; @@ -26,5 +26,12 @@ export default createTestConfig({ '--xpack.uptime.service.manifestUrl=mockDevUrl', // useful for testing (also enabled in MKI QA) '--coreApp.allowDynamicConfigOverrides=true', + '--xpack.dataUsage.enabled=true', + // dataUsage.autoops* config is set in kibana controller + '--xpack.dataUsage.autoops.enabled=true', + '--xpack.dataUsage.autoops.api.url=http://localhost:9000', + `--xpack.dataUsage.autoops.api.tls.certificate=${KBN_CERT_PATH}`, + `--xpack.dataUsage.autoops.api.tls.key=${KBN_KEY_PATH}`, + `--xpack.dataUsage.autoops.api.tls.ca=${CA_CERT_PATH}`, ], }); diff --git a/x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts b/x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts index 4167364e44793..36249651d5167 100644 --- a/x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts +++ b/x-pack/test_serverless/api_integration/test_suites/search/common_configs/config.group1.ts @@ -30,6 +30,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../common/console'), require.resolve('../../common/saved_objects_management'), require.resolve('../../common/telemetry'), + require.resolve('../../common/data_usage'), ], junit: { reportName: 'Serverless Search API Integration Tests - Common Group 1', diff --git a/x-pack/test_serverless/api_integration/test_suites/search/config.ts b/x-pack/test_serverless/api_integration/test_suites/search/config.ts index 94d7ea67c594a..9f02dc98b88c3 100644 --- a/x-pack/test_serverless/api_integration/test_suites/search/config.ts +++ b/x-pack/test_serverless/api_integration/test_suites/search/config.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { CA_CERT_PATH, KBN_CERT_PATH, KBN_KEY_PATH } from '@kbn/dev-utils'; import { createTestConfig } from '../../config.base'; export default createTestConfig({ @@ -21,5 +22,12 @@ export default createTestConfig({ kbnServerArgs: [ // useful for testing (also enabled in MKI QA) '--coreApp.allowDynamicConfigOverrides=true', + '--xpack.dataUsage.enabled=true', + // dataUsage.autoops* config is set in kibana controller + '--xpack.dataUsage.autoops.enabled=true', + '--xpack.dataUsage.autoops.api.url=http://localhost:9000', + `--xpack.dataUsage.autoops.api.tls.certificate=${KBN_CERT_PATH}`, + `--xpack.dataUsage.autoops.api.tls.key=${KBN_KEY_PATH}`, + `--xpack.dataUsage.autoops.api.tls.ca=${CA_CERT_PATH}`, ], }); diff --git a/x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts b/x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts index 406de533a909d..577b4f8ba4ee0 100644 --- a/x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts +++ b/x-pack/test_serverless/api_integration/test_suites/security/common_configs/config.group1.ts @@ -32,6 +32,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../common/console'), require.resolve('../../common/saved_objects_management'), require.resolve('../../common/telemetry'), + require.resolve('../../common/data_usage'), ], junit: { reportName: 'Serverless Security API Integration Tests - Common Group 1', diff --git a/x-pack/test_serverless/api_integration/test_suites/security/config.ts b/x-pack/test_serverless/api_integration/test_suites/security/config.ts index b97ed38960561..d53edbb561c84 100644 --- a/x-pack/test_serverless/api_integration/test_suites/security/config.ts +++ b/x-pack/test_serverless/api_integration/test_suites/security/config.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { CA_CERT_PATH, KBN_CERT_PATH, KBN_KEY_PATH } from '@kbn/dev-utils'; import { createTestConfig } from '../../config.base'; export default createTestConfig({ @@ -25,5 +26,12 @@ export default createTestConfig({ '--coreApp.allowDynamicConfigOverrides=true', `--xpack.securitySolutionServerless.cloudSecurityUsageReportingTaskInterval=5s`, `--xpack.securitySolutionServerless.usageReportingApiUrl=http://localhost:8081/api/v1/usage`, + '--xpack.dataUsage.enabled=true', + // dataUsage.autoops* config is set in kibana controller + '--xpack.dataUsage.autoops.enabled=true', + '--xpack.dataUsage.autoops.api.url=http://localhost:9000', + `--xpack.dataUsage.autoops.api.tls.certificate=${KBN_CERT_PATH}`, + `--xpack.dataUsage.autoops.api.tls.key=${KBN_KEY_PATH}`, + `--xpack.dataUsage.autoops.api.tls.ca=${CA_CERT_PATH}`, ], }); diff --git a/x-pack/test_serverless/functional/page_objects/svl_management_page.ts b/x-pack/test_serverless/functional/page_objects/svl_management_page.ts index e77e77c4fa76c..5676975a89c08 100644 --- a/x-pack/test_serverless/functional/page_objects/svl_management_page.ts +++ b/x-pack/test_serverless/functional/page_objects/svl_management_page.ts @@ -59,5 +59,13 @@ export function SvlManagementPageProvider({ getService }: FtrProviderContext) { async clickSpacesManagementCard() { await testSubjects.click('app-card-spaces'); }, + + // Data Usage card + async assertDataUsageManagementCardExists() { + await testSubjects.existOrFail('app-card-data_usage'); + }, + async clickDataUsageManagementCard() { + await testSubjects.click('app-card-data_usage'); + }, }; } diff --git a/x-pack/test_serverless/functional/test_suites/common/data_usage/index.ts b/x-pack/test_serverless/functional/test_suites/common/data_usage/index.ts new file mode 100644 index 0000000000000..dcdd23b13605f --- /dev/null +++ b/x-pack/test_serverless/functional/test_suites/common/data_usage/index.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { FtrProviderContext } from '../../../ftr_provider_context'; + +export default ({ loadTestFile }: FtrProviderContext) => { + describe('Data Usage', function () { + loadTestFile(require.resolve('./main')); + }); +}; diff --git a/x-pack/test_serverless/functional/test_suites/common/data_usage/main.ts b/x-pack/test_serverless/functional/test_suites/common/data_usage/main.ts new file mode 100644 index 0000000000000..fa6e4199bdc09 --- /dev/null +++ b/x-pack/test_serverless/functional/test_suites/common/data_usage/main.ts @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { FtrProviderContext } from '../../../ftr_provider_context'; + +export default ({ getPageObjects, getService }: FtrProviderContext) => { + const pageObjects = getPageObjects(['svlCommonPage', 'svlManagementPage', 'common']); + const testSubjects = getService('testSubjects'); + const retry = getService('retry'); + + describe('Main page', function () { + this.tags(['skipMKI']); + before(async () => { + await pageObjects.svlCommonPage.loginAsAdmin(); + await pageObjects.common.navigateToApp('management'); + await retry.waitFor('page to be visible', async () => { + return await testSubjects.exists('cards-navigation-page'); + }); + await pageObjects.svlManagementPage.assertDataUsageManagementCardExists(); + await pageObjects.svlManagementPage.clickDataUsageManagementCard(); + }); + + after(async () => {}); + + it('renders data usage page', async () => { + await retry.waitFor('page to be visible', async () => { + return await testSubjects.exists('DataUsagePage'); + }); + }); + }); +}; diff --git a/x-pack/test_serverless/functional/test_suites/observability/common_configs/config.group1.ts b/x-pack/test_serverless/functional/test_suites/observability/common_configs/config.group1.ts index c75e2aa19be75..80f2313cf28a7 100644 --- a/x-pack/test_serverless/functional/test_suites/observability/common_configs/config.group1.ts +++ b/x-pack/test_serverless/functional/test_suites/observability/common_configs/config.group1.ts @@ -22,6 +22,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../common/console'), require.resolve('../../common/painless_lab'), require.resolve('../../common/spaces'), + require.resolve('../../common/data_usage'), ], junit: { reportName: 'Serverless Observability Functional Tests - Common Group 1', diff --git a/x-pack/test_serverless/functional/test_suites/observability/config.ts b/x-pack/test_serverless/functional/test_suites/observability/config.ts index 2610af2a26149..9fffd5623f0a3 100644 --- a/x-pack/test_serverless/functional/test_suites/observability/config.ts +++ b/x-pack/test_serverless/functional/test_suites/observability/config.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - +import { CA_CERT_PATH, KBN_CERT_PATH, KBN_KEY_PATH } from '@kbn/dev-utils'; import { createTestConfig } from '../../config.base'; export default createTestConfig({ @@ -18,5 +18,13 @@ export default createTestConfig({ // include settings from project controller // https://github.com/elastic/project-controller/blob/main/internal/project/observability/config/elasticsearch.yml esServerArgs: ['xpack.ml.dfa.enabled=false'], - kbnServerArgs: [], + kbnServerArgs: [ + '--xpack.dataUsage.enabled=true', + // dataUsage.autoops* config is set in kibana controller + '--xpack.dataUsage.autoops.enabled=true', + '--xpack.dataUsage.autoops.api.url=http://localhost:9000', + `--xpack.dataUsage.autoops.api.tls.certificate=${KBN_CERT_PATH}`, + `--xpack.dataUsage.autoops.api.tls.key=${KBN_KEY_PATH}`, + `--xpack.dataUsage.autoops.api.tls.ca=${CA_CERT_PATH}`, + ], }); diff --git a/x-pack/test_serverless/functional/test_suites/search/common_configs/config.group1.ts b/x-pack/test_serverless/functional/test_suites/search/common_configs/config.group1.ts index 3b0991b3b1fe9..11e36186609ec 100644 --- a/x-pack/test_serverless/functional/test_suites/search/common_configs/config.group1.ts +++ b/x-pack/test_serverless/functional/test_suites/search/common_configs/config.group1.ts @@ -20,6 +20,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../common/reporting'), require.resolve('../../common/console'), require.resolve('../../common/spaces'), + require.resolve('../../common/data_usage'), ], junit: { reportName: 'Serverless Search Functional Tests - Common Group 1', diff --git a/x-pack/test_serverless/functional/test_suites/search/config.ts b/x-pack/test_serverless/functional/test_suites/search/config.ts index 35f6ca23f7cc8..21ea0080cba98 100644 --- a/x-pack/test_serverless/functional/test_suites/search/config.ts +++ b/x-pack/test_serverless/functional/test_suites/search/config.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - +import { CA_CERT_PATH, KBN_CERT_PATH, KBN_KEY_PATH } from '@kbn/dev-utils'; import { createTestConfig } from '../../config.base'; export default createTestConfig({ @@ -23,6 +23,13 @@ export default createTestConfig({ `--xpack.cloud.serverless.project_id=fakeprojectid`, `--xpack.cloud.base_url=https://fake-cloud.elastic.co`, `--xpack.cloud.projects_url=/projects/`, + '--xpack.dataUsage.enabled=true', + // dataUsage.autoops* config is set in kibana controller + '--xpack.dataUsage.autoops.enabled=true', + '--xpack.dataUsage.autoops.api.url=http://localhost:9000', + `--xpack.dataUsage.autoops.api.tls.certificate=${KBN_CERT_PATH}`, + `--xpack.dataUsage.autoops.api.tls.key=${KBN_KEY_PATH}`, + `--xpack.dataUsage.autoops.api.tls.ca=${CA_CERT_PATH}`, ], apps: { serverlessElasticsearch: { diff --git a/x-pack/test_serverless/functional/test_suites/security/common_configs/config.group1.ts b/x-pack/test_serverless/functional/test_suites/security/common_configs/config.group1.ts index 8adac3b9c4a6e..fc95c26547c0d 100644 --- a/x-pack/test_serverless/functional/test_suites/security/common_configs/config.group1.ts +++ b/x-pack/test_serverless/functional/test_suites/security/common_configs/config.group1.ts @@ -22,6 +22,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) { require.resolve('../../common/console'), require.resolve('../../common/painless_lab'), require.resolve('../../common/spaces'), + require.resolve('../../common/data_usage'), ], junit: { reportName: 'Serverless Security Functional Tests - Common Group 1', diff --git a/x-pack/test_serverless/functional/test_suites/security/config.ts b/x-pack/test_serverless/functional/test_suites/security/config.ts index 2f6a4b4920a25..1693a07b0e844 100644 --- a/x-pack/test_serverless/functional/test_suites/security/config.ts +++ b/x-pack/test_serverless/functional/test_suites/security/config.ts @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - +import { CA_CERT_PATH, KBN_CERT_PATH, KBN_KEY_PATH } from '@kbn/dev-utils'; import { createTestConfig } from '../../config.base'; export default createTestConfig({ @@ -18,4 +18,13 @@ export default createTestConfig({ // include settings from project controller // https://github.com/elastic/project-controller/blob/main/internal/project/security/config/elasticsearch.yml esServerArgs: ['xpack.ml.nlp.enabled=true'], + kbnServerArgs: [ + '--xpack.dataUsage.enabled=true', + // dataUsage.autoops* config is set in kibana controller + '--xpack.dataUsage.autoops.enabled=true', + '--xpack.dataUsage.autoops.api.url=http://localhost:9000', + `--xpack.dataUsage.autoops.api.tls.certificate=${KBN_CERT_PATH}`, + `--xpack.dataUsage.autoops.api.tls.key=${KBN_KEY_PATH}`, + `--xpack.dataUsage.autoops.api.tls.ca=${CA_CERT_PATH}`, + ], }); diff --git a/x-pack/test_serverless/tsconfig.json b/x-pack/test_serverless/tsconfig.json index 4f34639270fe9..e1658d3bd509f 100644 --- a/x-pack/test_serverless/tsconfig.json +++ b/x-pack/test_serverless/tsconfig.json @@ -92,6 +92,7 @@ "@kbn/security-plugin-types-common", "@kbn/core-saved-objects-import-export-server-internal", "@kbn/ai-assistant-common", + "@kbn/data-usage-plugin", "@kbn/infra-plugin", "@kbn/observability-plugin", ]