[API Integration Tests] usageApi service to expose the private telemetry API (#70057)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
585b3f7e3d
commit
56aac44ac3
5 changed files with 56 additions and 30 deletions
|
@ -13,7 +13,7 @@ import { LegacyEsProvider } from './legacy_es';
|
||||||
import { EsSupertestWithoutAuthProvider } from './es_supertest_without_auth';
|
import { EsSupertestWithoutAuthProvider } from './es_supertest_without_auth';
|
||||||
// @ts-ignore not ts yet
|
// @ts-ignore not ts yet
|
||||||
import { SupertestWithoutAuthProvider } from './supertest_without_auth';
|
import { SupertestWithoutAuthProvider } from './supertest_without_auth';
|
||||||
// @ts-ignore not ts yet
|
|
||||||
import { UsageAPIProvider } from './usage_api';
|
import { UsageAPIProvider } from './usage_api';
|
||||||
import {
|
import {
|
||||||
InfraOpsGraphQLClientProvider,
|
InfraOpsGraphQLClientProvider,
|
||||||
|
|
|
@ -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;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
52
x-pack/test/api_integration/services/usage_api.ts
Normal file
52
x-pack/test/api_integration/services/usage_api.ts
Normal file
|
@ -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<undefined> {
|
||||||
|
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<TelemetryCollectionManagerPlugin['getStats']> {
|
||||||
|
const { body } = await supertest
|
||||||
|
.post('/api/telemetry/v2/clusters/_stats')
|
||||||
|
.set('kbn-xsrf', 'xxx')
|
||||||
|
.send(payload)
|
||||||
|
.expect(200);
|
||||||
|
return body;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ export default function ({ getService }: FtrProviderContext) {
|
||||||
const esArchiver = getService('esArchiver');
|
const esArchiver = getService('esArchiver');
|
||||||
const kibanaServer = getService('kibanaServer');
|
const kibanaServer = getService('kibanaServer');
|
||||||
const reportingAPI = getService('reportingAPI');
|
const reportingAPI = getService('reportingAPI');
|
||||||
const usageAPI = getService('usageAPI' as any); // NOTE Usage API service is not Typescript
|
const usageAPI = getService('usageAPI');
|
||||||
|
|
||||||
describe('reporting usage', () => {
|
describe('reporting usage', () => {
|
||||||
before(async () => {
|
before(async () => {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import * as Rx from 'rxjs';
|
||||||
import { filter, first, mapTo, switchMap, timeout } from 'rxjs/operators';
|
import { filter, first, mapTo, switchMap, timeout } from 'rxjs/operators';
|
||||||
import { indexTimestamp } from '../../plugins/reporting/server/lib/store/index_timestamp';
|
import { indexTimestamp } from '../../plugins/reporting/server/lib/store/index_timestamp';
|
||||||
import { services as xpackServices } from '../functional/services';
|
import { services as xpackServices } from '../functional/services';
|
||||||
|
import { services as apiIntegrationServices } from '../api_integration/services';
|
||||||
import { FtrProviderContext } from './ftr_provider_context';
|
import { FtrProviderContext } from './ftr_provider_context';
|
||||||
|
|
||||||
interface PDFAppCounts {
|
interface PDFAppCounts {
|
||||||
|
@ -185,5 +186,6 @@ export function ReportingAPIProvider({ getService }: FtrProviderContext) {
|
||||||
|
|
||||||
export const services = {
|
export const services = {
|
||||||
...xpackServices,
|
...xpackServices,
|
||||||
|
usageAPI: apiIntegrationServices.usageAPI,
|
||||||
reportingAPI: ReportingAPIProvider,
|
reportingAPI: ReportingAPIProvider,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue