Skip to content

Commit

Permalink
[APM] Migrate inspect API tests to be deployment-agnostic (#199963)
Browse files Browse the repository at this point in the history
### How to test
Closes #198977
Part of #193245

This PR contains the changes to migrate `inspect` test folder to
deployment-agnostic testing strategy.

### How to test

- Serverless

```
node scripts/functional_tests_server --config x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts
node scripts/functional_test_runner --config x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts --grep="APM"
```

It's recommended to be run against
[MKI](https://github.com/crespocarlos/kibana/blob/main/x-pack/test_serverless/README.md#run-tests-on-mki)

- Stateful
```
node scripts/functional_tests_server --config x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts
node scripts/functional_test_runner --config x-pack/test/api_integration/deployment_agnostic/configs/stateful/oblt.stateful.config.ts --grep="APM"
```

## Checks

- [ ] (OPTIONAL, only if a test has been unskipped) Run flaky test suite
- [x] local run for serverless
- [x] local run for stateful
- [x] MKI run for serverless

(cherry picked from commit bb68f92)
  • Loading branch information
iblancof committed Nov 14, 2024
1 parent da7fdf3 commit a896a98
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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 archivesMetadata from '../../../../../../apm_api_integration/common/fixtures/es_archiver/archives_metadata';

export default archivesMetadata;
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function apmApiIntegrationTests({
loadTestFile(require.resolve('./observability_overview'));
loadTestFile(require.resolve('./latency'));
loadTestFile(require.resolve('./infrastructure'));
loadTestFile(require.resolve('./inspect'));
loadTestFile(require.resolve('./service_groups'));
});
}
Original file line number Diff line number Diff line change
@@ -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 { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';

export default function ({ loadTestFile }: DeploymentAgnosticFtrProviderContext) {
describe('inspect', () => {
loadTestFile(require.resolve('./inspect.spec.ts'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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 { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';
import { ARCHIVER_ROUTES } from '../constants/archiver';
import archives_metadata from '../constants/archives_metadata';

export default function inspectFlagTests({ getService }: DeploymentAgnosticFtrProviderContext) {
const apmApiClient = getService('apmApi');
const esArchiver = getService('esArchiver');

const archiveName = '8.0.0';
const metadata = archives_metadata['apm_8.0.0'];

describe('Inspect feature', () => {
before(async () => {
await esArchiver.load(ARCHIVER_ROUTES[archiveName]);
});
after(async () => {
await esArchiver.unload(ARCHIVER_ROUTES[archiveName]);
});

describe('when omitting `_inspect` query param', () => {
it('returns response without `_inspect`', async () => {
const { status, body } = await apmApiClient.readUser({
endpoint: 'GET /internal/apm/environments',
params: {
query: {
start: metadata.start,
end: metadata.end,
},
},
});

expect(status).to.be(200);
expect(body._inspect).to.be(undefined);
});
});

describe('when passing `_inspect` as query param', () => {
describe('elasticsearch calls made with end-user auth are returned', () => {
it('for environments', async () => {
const { status, body } = await apmApiClient.readUser({
endpoint: 'GET /internal/apm/environments',
params: {
query: {
start: metadata.start,
end: metadata.end,
_inspect: true,
},
},
});
expect(status).to.be(200);
expect(body._inspect).not.to.be.empty();

// @ts-expect-error
expect(Object.keys(body._inspect[0])).to.eql([
'id',
'json',
'name',
'response',
'startTime',
'stats',
'status',
]);
});
});

describe('elasticsearch calls made with internal user should not leak internal queries', () => {
it('for custom links', async () => {
const { status, body } = await apmApiClient.readUser({
endpoint: 'GET /internal/apm/settings/custom_links',
params: {
query: {
'service.name': 'opbeans-node',
'transaction.type': 'request',
_inspect: true,
},
},
});

expect(status).to.be(200);
expect(body._inspect).to.eql([]);
});
});
});
});
}
64 changes: 0 additions & 64 deletions x-pack/test/apm_api_integration/tests/inspect/inspect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,79 +8,15 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../common/ftr_provider_context';

import archives_metadata from '../../common/fixtures/es_archiver/archives_metadata';

export default function inspectFlagTests({ getService }: FtrProviderContext) {
const registry = getService('registry');
const apmApiClient = getService('apmApiClient');

const archiveName = 'apm_8.0.0';
const metadata = archives_metadata[archiveName];

registry.when('Inspect feature', { config: 'trial', archives: [archiveName] }, () => {
describe('when omitting `_inspect` query param', () => {
it('returns response without `_inspect`', async () => {
const { status, body } = await apmApiClient.readUser({
endpoint: 'GET /internal/apm/environments',
params: {
query: {
start: metadata.start,
end: metadata.end,
},
},
});

expect(status).to.be(200);
expect(body._inspect).to.be(undefined);
});
});

describe('when passing `_inspect` as query param', () => {
describe('elasticsearch calls made with end-user auth are returned', () => {
it('for environments', async () => {
const { status, body } = await apmApiClient.readUser({
endpoint: 'GET /internal/apm/environments',
params: {
query: {
start: metadata.start,
end: metadata.end,
_inspect: true,
},
},
});
expect(status).to.be(200);
expect(body._inspect).not.to.be.empty();

// @ts-expect-error
expect(Object.keys(body._inspect[0])).to.eql([
'id',
'json',
'name',
'response',
'startTime',
'stats',
'status',
]);
});
});

describe('elasticsearch calls made with internal user should not leak internal queries', () => {
it('for custom links', async () => {
const { status, body } = await apmApiClient.readUser({
endpoint: 'GET /internal/apm/settings/custom_links',
params: {
query: {
'service.name': 'opbeans-node',
'transaction.type': 'request',
_inspect: true,
},
},
});

expect(status).to.be(200);
expect(body._inspect).to.eql([]);
});

it('for agent configs', async () => {
const { status, body } = await apmApiClient.readUser({
endpoint: 'GET /api/apm/settings/agent-configuration 2023-10-31',
Expand Down

0 comments on commit a896a98

Please sign in to comment.