kibana/x-pack/test/profiling_api_integration/tests/has_setup.spec.ts
Cauê Marcondes 98d2766de8
[Profiling-APM] Removing Profiling dependency from APM (#166253)
This PR removes the Profiling dependency from APM, introduced on `8.10`.

- Exposes a new service in profiling-data-access plugin
- Create a new APM API that calls the new service and checks if
Profiling is initialized
- Move Locators from the Profiling plugin to the Observability-shared
plugin
- Move logic to check Profiling status (has_setup/has_data...) from
Profiling server to profiling-data-access plugin
- Create API tests, testing the status services based on different
scenarios:
  - When profiling hasn't been initialized and there's no data
  - When profiling is initialized but has no data
  - When collector integration is not installed
  - When symbolized integration is not installed
  - When APM server integration is not found

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2023-09-22 09:16:48 +01:00

357 lines
12 KiB
TypeScript

/*
* 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 { getRoutePaths } from '@kbn/profiling-plugin/common';
import { ProfilingStatus } from '@kbn/profiling-utils';
import { getBettertest } from '../common/bettertest';
import { FtrProviderContext } from '../common/ftr_provider_context';
import { deletePackagePolicy, getProfilingPackagePolicyIds } from '../utils/fleet';
import { loadProfilingData, setupProfiling } from '../utils/profiling_data';
const profilingRoutePaths = getRoutePaths();
export default function featureControlsTests({ getService }: FtrProviderContext) {
const registry = getService('registry');
const profilingApiClient = getService('profilingApiClient');
const supertest = getService('supertest');
const bettertest = getBettertest(supertest);
const logger = getService('log');
const es = getService('es');
registry.when('Profiling status check', { config: 'cloud' }, () => {
describe('Profiling is not set up and no data is loaded', () => {
describe('Admin user', () => {
let statusCheck: ProfilingStatus;
before(async () => {
const response = await profilingApiClient.adminUser({
endpoint: `GET ${profilingRoutePaths.HasSetupESResources}`,
});
statusCheck = response.body;
});
it(`has not been set up`, async () => {
expect(statusCheck.has_setup).to.be(false);
});
it(`does not have data`, async () => {
expect(statusCheck.has_data).to.be(false);
});
it(`does not have pre 8.9.1 data`, async () => {
expect(statusCheck.pre_8_9_1_data).to.be(false);
});
});
describe('Viewer user', () => {
let statusCheck: ProfilingStatus;
before(async () => {
const response = await profilingApiClient.readUser({
endpoint: `GET ${profilingRoutePaths.HasSetupESResources}`,
});
statusCheck = response.body;
});
it(`has been set up`, async () => {
expect(statusCheck.has_setup).to.be(true);
});
it(`has data`, async () => {
expect(statusCheck.has_data).to.be(true);
});
it(`does not have pre 8.9.1 data`, async () => {
expect(statusCheck.pre_8_9_1_data).to.be(false);
});
it(`is unauthorized to fully check profiling status `, async () => {
expect(statusCheck.unauthorized).to.be(true);
});
});
});
describe('Collector integration is not installed', () => {
let collectorId: string | undefined;
before(async () => {
await setupProfiling(bettertest, logger);
const response = await getProfilingPackagePolicyIds(bettertest);
collectorId = response.collectorId;
if (collectorId) {
await deletePackagePolicy(bettertest, collectorId);
}
});
it('expectes a collector integration to exist', () => {
expect(collectorId).not.to.be(undefined);
});
describe('Admin user', () => {
let statusCheck: ProfilingStatus;
before(async () => {
const response = await profilingApiClient.adminUser({
endpoint: `GET ${profilingRoutePaths.HasSetupESResources}`,
});
statusCheck = response.body;
});
it(`has not been set up`, async () => {
expect(statusCheck.has_setup).to.be(false);
});
it(`does not have data`, async () => {
expect(statusCheck.has_data).to.be(false);
});
it(`does not have pre 8.9.1 data`, async () => {
expect(statusCheck.pre_8_9_1_data).to.be(false);
});
});
describe('Viewer user', () => {
let statusCheck: ProfilingStatus;
before(async () => {
const response = await profilingApiClient.readUser({
endpoint: `GET ${profilingRoutePaths.HasSetupESResources}`,
});
statusCheck = response.body;
});
it(`has been set up`, async () => {
expect(statusCheck.has_setup).to.be(true);
});
it(`has data`, async () => {
expect(statusCheck.has_data).to.be(true);
});
it(`does not have pre 8.9.1 data`, async () => {
expect(statusCheck.pre_8_9_1_data).to.be(false);
});
it(`is unauthorized to fully check profiling status `, async () => {
expect(statusCheck.unauthorized).to.be(true);
});
});
});
describe('Symbolizer integration is not installed', () => {
let symbolizerId: string | undefined;
before(async () => {
await setupProfiling(bettertest, logger);
const response = await getProfilingPackagePolicyIds(bettertest);
symbolizerId = response.symbolizerId;
if (symbolizerId) {
await deletePackagePolicy(bettertest, symbolizerId);
}
});
it('expectes a symbolizer integration to exist', () => {
expect(symbolizerId).not.to.be(undefined);
});
describe('Admin user', () => {
let statusCheck: ProfilingStatus;
before(async () => {
const response = await profilingApiClient.adminUser({
endpoint: `GET ${profilingRoutePaths.HasSetupESResources}`,
});
statusCheck = response.body;
});
it(`has not been set up`, async () => {
expect(statusCheck.has_setup).to.be(false);
});
it(`does not have data`, async () => {
expect(statusCheck.has_data).to.be(false);
});
it(`does not have pre 8.9.1 data`, async () => {
expect(statusCheck.pre_8_9_1_data).to.be(false);
});
});
describe('Viewer user', () => {
let statusCheck: ProfilingStatus;
before(async () => {
const response = await profilingApiClient.readUser({
endpoint: `GET ${profilingRoutePaths.HasSetupESResources}`,
});
statusCheck = response.body;
});
it(`has been set up`, async () => {
expect(statusCheck.has_setup).to.be(true);
});
it(`has data`, async () => {
expect(statusCheck.has_data).to.be(true);
});
it(`does not have pre 8.9.1 data`, async () => {
expect(statusCheck.pre_8_9_1_data).to.be(false);
});
it(`is unauthorized to fully check profiling status `, async () => {
expect(statusCheck.unauthorized).to.be(true);
});
});
});
describe('APM integration is not installed', () => {
before(async () => {
await setupProfiling(bettertest, logger);
await deletePackagePolicy(bettertest, 'elastic-cloud-apm');
});
describe('Admin user', () => {
let statusCheck: ProfilingStatus;
before(async () => {
const response = await profilingApiClient.adminUser({
endpoint: `GET ${profilingRoutePaths.HasSetupESResources}`,
});
statusCheck = response.body;
});
it(`has been set up`, async () => {
expect(statusCheck.has_setup).to.be(true);
});
it(`does not have data`, async () => {
expect(statusCheck.has_data).to.be(false);
});
it(`does not have pre 8.9.1 data`, async () => {
expect(statusCheck.pre_8_9_1_data).to.be(false);
});
});
describe('Viewer user', () => {
let statusCheck: ProfilingStatus;
before(async () => {
const response = await profilingApiClient.readUser({
endpoint: `GET ${profilingRoutePaths.HasSetupESResources}`,
});
statusCheck = response.body;
});
it(`has been set up`, async () => {
expect(statusCheck.has_setup).to.be(true);
});
it(`has data`, async () => {
expect(statusCheck.has_data).to.be(true);
});
it(`does not have pre 8.9.1 data`, async () => {
expect(statusCheck.pre_8_9_1_data).to.be(false);
});
it(`is unauthorized to fully check profiling status `, async () => {
expect(statusCheck.unauthorized).to.be(true);
});
});
});
describe('Profiling is set up', () => {
before(async () => {
await setupProfiling(bettertest, logger);
});
describe('without data', () => {
describe('Admin user', () => {
let statusCheck: ProfilingStatus;
before(async () => {
const response = await profilingApiClient.adminUser({
endpoint: `GET ${profilingRoutePaths.HasSetupESResources}`,
});
statusCheck = response.body;
});
it(`has been set up`, async () => {
expect(statusCheck.has_setup).to.be(true);
});
it(`does not have data`, async () => {
expect(statusCheck.has_data).to.be(false);
});
it(`does not have pre 8.9.1 data`, async () => {
expect(statusCheck.pre_8_9_1_data).to.be(false);
});
});
describe('Viewer user', () => {
let statusCheck: ProfilingStatus;
before(async () => {
const response = await profilingApiClient.readUser({
endpoint: `GET ${profilingRoutePaths.HasSetupESResources}`,
});
statusCheck = response.body;
});
it(`has been set up`, async () => {
expect(statusCheck.has_setup).to.be(true);
});
it(`has data`, async () => {
expect(statusCheck.has_data).to.be(true);
});
it(`does not have pre 8.9.1 data`, async () => {
expect(statusCheck.pre_8_9_1_data).to.be(false);
});
it(`is unauthorized to fully check profiling status `, async () => {
expect(statusCheck.unauthorized).to.be(true);
});
});
});
describe('with data', () => {
before(async () => {
await loadProfilingData(es, logger);
});
describe('Admin user', () => {
let statusCheck: ProfilingStatus;
before(async () => {
const response = await profilingApiClient.adminUser({
endpoint: `GET ${profilingRoutePaths.HasSetupESResources}`,
});
statusCheck = response.body;
});
it(`has been set up`, async () => {
expect(statusCheck.has_setup).to.be(true);
});
it(`does not have data`, async () => {
expect(statusCheck.has_data).to.be(true);
});
it(`does not have pre 8.9.1 data`, async () => {
expect(statusCheck.pre_8_9_1_data).to.be(false);
});
});
describe('Viewer user', () => {
let statusCheck: ProfilingStatus;
before(async () => {
const response = await profilingApiClient.readUser({
endpoint: `GET ${profilingRoutePaths.HasSetupESResources}`,
});
statusCheck = response.body;
});
it(`has been set up`, async () => {
expect(statusCheck.has_setup).to.be(true);
});
it(`has data`, async () => {
expect(statusCheck.has_data).to.be(true);
});
it(`does not have pre 8.9.1 data`, async () => {
expect(statusCheck.pre_8_9_1_data).to.be(false);
});
it(`is unauthorized to fully check profiling status `, async () => {
expect(statusCheck.unauthorized).to.be(true);
});
});
});
});
});
}