diff --git a/x-pack/test/api_integration/services/index.ts b/x-pack/test/api_integration/services/index.ts index d135c43e2302..75cc2b451ea2 100644 --- a/x-pack/test/api_integration/services/index.ts +++ b/x-pack/test/api_integration/services/index.ts @@ -13,7 +13,7 @@ import { LegacyEsProvider } from './legacy_es'; import { EsSupertestWithoutAuthProvider } from './es_supertest_without_auth'; // @ts-ignore not ts yet import { SupertestWithoutAuthProvider } from './supertest_without_auth'; -// @ts-ignore not ts yet + import { UsageAPIProvider } from './usage_api'; import { InfraOpsGraphQLClientProvider, diff --git a/x-pack/test/api_integration/services/usage_api.js b/x-pack/test/api_integration/services/usage_api.js deleted file mode 100644 index 57ae1d152f70..000000000000 --- a/x-pack/test/api_integration/services/usage_api.js +++ /dev/null @@ -1,28 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -export function UsageAPIProvider({ getService }) { - const supertest = getService('supertest'); - const supertestNoAuth = getService('supertestWithoutAuth'); - - return { - async getUsageStatsNoAuth() { - const { body } = await supertestNoAuth - .get('/api/stats?extended=true') - .set('kbn-xsrf', 'xxx') - .expect(401); - return body.usage; - }, - - async getUsageStats() { - const { body } = await supertest - .get('/api/stats?extended=true') - .set('kbn-xsrf', 'xxx') - .expect(200); - return body.usage; - }, - }; -} diff --git a/x-pack/test/api_integration/services/usage_api.ts b/x-pack/test/api_integration/services/usage_api.ts new file mode 100644 index 000000000000..ef6f10f2d4f4 --- /dev/null +++ b/x-pack/test/api_integration/services/usage_api.ts @@ -0,0 +1,52 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { FtrProviderContext } from '../ftr_provider_context'; +import { TelemetryCollectionManagerPlugin } from '../../../../src/plugins/telemetry_collection_manager/server/plugin'; + +export function UsageAPIProvider({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + const supertestNoAuth = getService('supertestWithoutAuth'); + + return { + async getUsageStatsNoAuth(): Promise { + const { body } = await supertestNoAuth + .get('/api/stats?extended=true') + .set('kbn-xsrf', 'xxx') + .expect(401); + return body.usage; + }, + + /** + * Public stats API: it returns the usage in camelCase format + */ + async getUsageStats() { + const { body } = await supertest + .get('/api/stats?extended=true') + .set('kbn-xsrf', 'xxx') + .expect(200); + return body.usage; + }, + + /** + * Retrieve the stats via the private telemetry API: + * It returns the usage in as a string encrypted blob or the plain payload if `unencrypted: false` + * + * @param payload Request parameters to retrieve the telemetry stats + */ + async getTelemetryStats(payload: { + unencrypted?: boolean; + timeRange: { min: Date; max: Date }; + }): Promise { + const { body } = await supertest + .post('/api/telemetry/v2/clusters/_stats') + .set('kbn-xsrf', 'xxx') + .send(payload) + .expect(200); + return body; + }, + }; +} diff --git a/x-pack/test/reporting_api_integration/reporting/usage.ts b/x-pack/test/reporting_api_integration/reporting/usage.ts index 25bebaa6abcb..24e68b3917d6 100644 --- a/x-pack/test/reporting_api_integration/reporting/usage.ts +++ b/x-pack/test/reporting_api_integration/reporting/usage.ts @@ -19,7 +19,7 @@ export default function ({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const kibanaServer = getService('kibanaServer'); const reportingAPI = getService('reportingAPI'); - const usageAPI = getService('usageAPI' as any); // NOTE Usage API service is not Typescript + const usageAPI = getService('usageAPI'); describe('reporting usage', () => { before(async () => { diff --git a/x-pack/test/reporting_api_integration/services.ts b/x-pack/test/reporting_api_integration/services.ts index 85f5a98c69b2..f98d8246fc01 100644 --- a/x-pack/test/reporting_api_integration/services.ts +++ b/x-pack/test/reporting_api_integration/services.ts @@ -9,6 +9,7 @@ import * as Rx from 'rxjs'; import { filter, first, mapTo, switchMap, timeout } from 'rxjs/operators'; import { indexTimestamp } from '../../plugins/reporting/server/lib/store/index_timestamp'; import { services as xpackServices } from '../functional/services'; +import { services as apiIntegrationServices } from '../api_integration/services'; import { FtrProviderContext } from './ftr_provider_context'; interface PDFAppCounts { @@ -185,5 +186,6 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) { export const services = { ...xpackServices, + usageAPI: apiIntegrationServices.usageAPI, reportingAPI: ReportingAPIProvider, };