Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate /diagnostics and /service_nodes to be deployment agnostic #199645

Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
30d377a
Migrate /test/apm_api_integration/tests/diagnostics to be deployment-…
miloszmarcinkowski Nov 11, 2024
11c847e
Merge remote-tracking branch 'upstream/main' into 198967-apm-migrate-…
miloszmarcinkowski Nov 11, 2024
fefc157
Merge remote-tracking branch 'upstream/main' into 198967-apm-migrate-…
miloszmarcinkowski Nov 11, 2024
3f29f99
unskip tests
miloszmarcinkowski Nov 12, 2024
b2d307a
filter out apm index templates
miloszmarcinkowski Nov 12, 2024
dd0a870
type check fix
miloszmarcinkowski Nov 12, 2024
9e7b6fe
Merge remote-tracking branch 'upstream/main' into 198967-apm-migrate-…
miloszmarcinkowski Nov 13, 2024
11ce02a
Migrate /test/apm_api_integration/tests/service_nodes to be deploymen…
miloszmarcinkowski Nov 13, 2024
8f8ef6c
Merge branch '198985-apm-migrate-testapm_api_integrationtestsservice_…
miloszmarcinkowski Nov 13, 2024
ec4c5cc
Correct describe block title
miloszmarcinkowski Nov 13, 2024
b9a4a03
Merge branch 'main' into 198967-apm-migrate-testapm_api_integrationte…
miloszmarcinkowski Nov 14, 2024
2bd7dae
remove duplicated apm package instalation
miloszmarcinkowski Nov 14, 2024
28c1ba6
convert to Type-Only imports in `apm/*` tests
miloszmarcinkowski Nov 14, 2024
7a56f8c
adjust index_pattern_settings.spec.ts to work in all testing environm…
miloszmarcinkowski Nov 14, 2024
50d8fba
Merge remote-tracking branch 'upstream/main' into 198967-apm-migrate-…
miloszmarcinkowski Nov 14, 2024
2e2d110
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ import expect from '@kbn/expect';
import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { APIReturnType } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import { sumBy } from 'lodash';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit.

Suggested change
import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated all /apm/* tests by adding type-only imports.

import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
const registry = getService('registry');
const apmApiClient = getService('apmApiClient');
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const apmApiClient = getService('apmApi');
const es = getService('es');
const apmSynthtraceEsClient = getService('apmSynthtraceEsClient');
const synthtrace = getService('synthtrace');

const start = new Date('2021-01-01T00:00:00.000Z').getTime();
const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1;

// FLAKY: https://github.com/elastic/kibana/issues/177144
registry.when('Diagnostics: APM Events', { config: 'basic', archives: [] }, () => {
describe('Diagnostics: APM Events', () => {
describe('When there is no data', () => {
before(async () => {
// delete APM data streams
Expand All @@ -38,10 +37,13 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

describe('When data is ingested', () => {
let apmSynthtraceEsClient: ApmSynthtraceEsClient;

before(async () => {
const instance = apm
.service({ name: 'synth-go', environment: 'production', agentName: 'go' })
.instance('instance-a');
apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient();

await apmSynthtraceEsClient.index(
timerange(start, end)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@

import expect from '@kbn/expect';
import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
const registry = getService('registry');
const apmApiClient = getService('apmApiClient');
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const apmApiClient = getService('apmApi');
const es = getService('es');
const apmSynthtraceEsClient = getService('apmSynthtraceEsClient');
const synthtraceKibanaClient = getService('synthtraceKibanaClient');
const synthtrace = getService('synthtrace');

const start = new Date('2021-01-01T00:00:00.000Z').getTime();
const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1;

// FLAKY: https://github.com/elastic/kibana/issues/177245
registry.when('Diagnostics: Data streams', { config: 'basic', archives: [] }, () => {
describe('Diagnostics: Data streams', () => {
describe('When there is no data', () => {
before(async () => {
// delete APM data streams
Expand All @@ -45,9 +43,13 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

describe('When data is ingested', () => {
let apmSynthtraceEsClient: ApmSynthtraceEsClient;

before(async () => {
const latestVersion = await synthtraceKibanaClient.fetchLatestApmPackageVersion();
await synthtraceKibanaClient.installApmPackage(latestVersion);
apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient();
const apmSynthtraceKibanaClient = synthtrace.apmSynthtraceKibanaClient;
const latestVersion = await apmSynthtraceKibanaClient.fetchLatestApmPackageVersion();
await apmSynthtraceKibanaClient.installApmPackage(latestVersion);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createApmSynthtraceEsClient already installs the latest apm package version. Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review. Those were remainings from the old test and I didn't notice that apm packge is installed in createApmSynthtraceEsClient. Updated!


const instance = apm
.service({ name: 'synth-go', environment: 'production', agentName: 'go' })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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('diagnostics', () => {
loadTestFile(require.resolve('./apm_events.spec.ts'));
loadTestFile(require.resolve('./data_streams.spec.ts'));
loadTestFile(require.resolve('./index_pattern_settings.spec.ts'));
loadTestFile(require.resolve('./index_templates.spec.ts'));
loadTestFile(require.resolve('./indices.spec.ts'));
loadTestFile(require.resolve('./privileges.spec.ts'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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 { apm, timerange } from '@kbn/apm-synthtrace-client';
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import { uniq } from 'lodash';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';

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

const start = new Date('2021-01-01T00:00:00.000Z').getTime();
const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1;

describe('Diagnostics: Index pattern settings', () => {
describe('When data is ingested', () => {
let apmSynthtraceEsClient: ApmSynthtraceEsClient;

before(async () => {
apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient();
const apmSynthtraceKibanaClient = synthtrace.apmSynthtraceKibanaClient;
const latestVersion = await apmSynthtraceKibanaClient.fetchLatestApmPackageVersion();
await apmSynthtraceKibanaClient.installApmPackage(latestVersion);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


const instance = apm
.service({ name: 'synth-go', environment: 'production', agentName: 'go' })
.instance('instance-a');
await apmSynthtraceEsClient.index(
timerange(start, end)
.interval('1m')
.rate(30)
.generator((timestamp) =>
instance
.transaction({ transactionName: 'GET /users' })
.timestamp(timestamp)
.duration(100)
.success()
)
);
});

after(() => apmSynthtraceEsClient.clean());

it('returns APM index templates', async () => {
const apmIndexTemplatesPatterns = ['apm', 'otel'];

const { status, body } = await apmApiClient.adminUser({
endpoint: 'GET /internal/apm/diagnostics',
});
expect(status).to.be(200);

const uniqueTemplateNames = uniq(
body.indexTemplatesByIndexPattern.flatMap(({ indexTemplates }) => {
return indexTemplates?.map(({ templateName }) => templateName);
})
);

const apmTemplateNames = uniqueTemplateNames.filter((templateName) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We filter out only apm and otel index templates for the test, otherwise they differ on serverless and test fails

apmIndexTemplatesPatterns.some((pattern) => templateName.includes(pattern))
);

expect(apmTemplateNames).to.eql([
'logs-apm.error@template',
'logs-apm.app@template',
'logs-otel@template',
'metrics-apm.service_transaction.1m@template',
'metrics-apm.transaction.10m@template',
'metrics-apm.service_summary.10m@template',
'metrics-apm.internal@template',
'metrics-apm.service_destination.1m@template',
'metrics-apm.service_summary.60m@template',
'metrics-apm.service_summary.1m@template',
'metrics-apm.transaction.1m@template',
'metrics-apm.service_destination.60m@template',
'metrics-apm.service_transaction.60m@template',
'metrics-apm.service_destination.10m@template',
'metrics-apm.service_transaction.10m@template',
'metrics-apm.transaction.60m@template',
'metrics-apm.app@template',
'metrics-otel@template',
'metrics-service_transaction.10m.otel@template',
'metrics-transaction.10m.otel@template',
'metrics-service_summary.1m.otel@template',
'metrics-service_transaction.60m.otel@template',
'metrics-service_summary.60m.otel@template',
'metrics-service_summary.10m.otel@template',
'metrics-transaction.1m.otel@template',
'metrics-transaction.60m.otel@template',
'metrics-service_transaction.1m.otel@template',
'traces-apm.rum@template',
'traces-apm@template',
'traces-apm.sampled@template',
'traces-otel@template',
]);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,25 @@

import expect from '@kbn/expect';
import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { getApmIndexTemplateNames } from '@kbn/apm-plugin/server/routes/diagnostics/helpers/get_apm_index_template_names';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
const registry = getService('registry');
const apmApiClient = getService('apmApiClient');
const es = getService('es');
const apmSynthtraceEsClient = getService('apmSynthtraceEsClient');
const synthtraceKibanaClient = getService('synthtraceKibanaClient');
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const apmApiClient = getService('apmApi');
const synthtrace = getService('synthtrace');

const start = new Date('2021-01-01T00:00:00.000Z').getTime();
const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1;

registry.when.skip('Diagnostics: Index Templates', { config: 'basic', archives: [] }, () => {
describe('When there is no data', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When default index templates are deleted, they get recreated automatically. Introduced here: elastic/elasticsearch#97546

This means we can't perform check against empty response anymore.

before(async () => {
// delete APM index templates
await es.indices.deleteIndexTemplate({
name: Object.values(getApmIndexTemplateNames()).flat(),
});
});

it('verifies that none of the default APM index templates exists`', async () => {
const { status, body } = await apmApiClient.adminUser({
endpoint: 'GET /internal/apm/diagnostics',
});
expect(status).to.be(200);
const noApmIndexTemplateExists = body.apmIndexTemplates.every(
({ exists }) => exists === false
);
expect(noApmIndexTemplateExists).to.eql(true);
});
});

describe('Diagnostics: Index Templates', () => {
describe('When data is ingested', () => {
let apmSynthtraceEsClient: ApmSynthtraceEsClient;

before(async () => {
const latestVersion = await synthtraceKibanaClient.fetchLatestApmPackageVersion();
await synthtraceKibanaClient.installApmPackage(latestVersion);
apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient();
const apmSynthtraceKibanaClient = synthtrace.apmSynthtraceKibanaClient;
const latestVersion = await apmSynthtraceKibanaClient.fetchLatestApmPackageVersion();
await apmSynthtraceKibanaClient.installApmPackage(latestVersion);

const instance = apm
.service({ name: 'synth-go', environment: 'production', agentName: 'go' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
import expect from '@kbn/expect';
import { apm, timerange } from '@kbn/apm-synthtrace-client';
import { omit } from 'lodash';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';

export default function ApiTest({ getService }: FtrProviderContext) {
const registry = getService('registry');
const apmApiClient = getService('apmApiClient');
const apmSynthtraceEsClient = getService('apmSynthtraceEsClient');
export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) {
const apmApiClient = getService('apmApi');
const synthtrace = getService('synthtrace');
const es = getService('es');
const synthtraceKibanaClient = getService('synthtraceKibanaClient');

const start = new Date('2021-01-01T00:00:00.000Z').getTime();
const end = new Date('2021-01-01T00:15:00.000Z').getTime() - 1;

// FLAKY: https://github.com/elastic/kibana/pull/177039
registry.when.skip('Diagnostics: Indices', { config: 'basic', archives: [] }, () => {
let apmSynthtraceEsClient: ApmSynthtraceEsClient;

describe('Diagnostics: Indices', () => {
describe.skip('When there is no data', () => {
it('returns empty response`', async () => {
const { status, body } = await apmApiClient.adminUser({
Expand All @@ -39,6 +39,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const instance = apm
.service({ name: 'synth-go', environment: 'production', agentName: 'go' })
.instance('instance-a');
apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient();

await apmSynthtraceEsClient.index(
timerange(start, end)
Expand Down Expand Up @@ -92,8 +93,9 @@ export default function ApiTest({ getService }: FtrProviderContext) {

after(async () => {
await es.indices.delete({ index: 'traces-apm-default' });
const latestVersion = await synthtraceKibanaClient.fetchLatestApmPackageVersion();
await synthtraceKibanaClient.installApmPackage(latestVersion);
const apmSynthtraceKibanaClient = synthtrace.apmSynthtraceKibanaClient;
const latestVersion = await apmSynthtraceKibanaClient.fetchLatestApmPackageVersion();
await apmSynthtraceKibanaClient.installApmPackage(latestVersion);
await apmSynthtraceEsClient.clean();
});

Expand Down Expand Up @@ -136,8 +138,9 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});

after(async () => {
const latestVersion = await synthtraceKibanaClient.fetchLatestApmPackageVersion();
await synthtraceKibanaClient.installApmPackage(latestVersion);
const apmSynthtraceKibanaClient = synthtrace.apmSynthtraceKibanaClient;
const latestVersion = await apmSynthtraceKibanaClient.fetchLatestApmPackageVersion();
await apmSynthtraceKibanaClient.installApmPackage(latestVersion);
await apmSynthtraceEsClient.clean();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@

import { APIReturnType } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context';

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

registry.when('Diagnostics: Privileges', { config: 'basic', archives: [] }, () => {
describe('Diagnostics: Privileges', () => {
describe('superuser', () => {
let body: APIReturnType<'GET /internal/apm/diagnostics'>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ export default function apmApiIntegrationTests({
loadTestFile(require.resolve('./latency'));
loadTestFile(require.resolve('./infrastructure'));
loadTestFile(require.resolve('./service_groups'));
loadTestFile(require.resolve('./diagnostics'));
loadTestFile(require.resolve('./service_nodes'));
});
}
Loading