[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:
Alejandro Fernández Haro 2020-06-30 20:14:59 +01:00 committed by GitHub
parent 585b3f7e3d
commit 56aac44ac3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 30 deletions

View file

@ -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,

View file

@ -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;
},
};
}

View 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;
},
};
}

View file

@ -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 () => {

View file

@ -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,
};