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

[ObsUX][APM] Migrate APM infra tests to agnostic deployment tests #199775

Merged
Changes from 1 commit
Commits
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
Next Next commit
Migrate APM infra tests to agnostic deployment tests
MiriamAparicio committed Nov 12, 2024

Unverified

This user has not yet uploaded their public signing key.
commit a699cf016f40c760239cbc38d0fff52c2edc452c
Original file line number Diff line number Diff line change
@@ -20,5 +20,6 @@ export default function apmApiIntegrationTests({
loadTestFile(require.resolve('./correlations'));
loadTestFile(require.resolve('./entities'));
loadTestFile(require.resolve('./cold_start'));
loadTestFile(require.resolve('./infrastructure'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 { apm, timerange } from '@kbn/apm-synthtrace-client';
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';

export async function generateData({
apmSynthtraceEsClient,
start,
end,
}: {
apmSynthtraceEsClient: ApmSynthtraceEsClient;
start: number;
end: number;
}) {
const serviceRunsInContainerInstance = apm
.service({ name: 'synth-go', environment: 'production', agentName: 'go' })
.instance('instance-a');

const serviceInstance = apm
.service({ name: 'synth-java', environment: 'production', agentName: 'java' })
.instance('instance-b');

await apmSynthtraceEsClient.index(
timerange(start, end)
.interval('1m')
.generator((timestamp) => {
return [
serviceRunsInContainerInstance
.transaction({ transactionName: 'GET /apple 🍎' })
.defaults({
'container.id': 'foo',
'host.hostname': 'bar',
'kubernetes.pod.name': 'baz',
})
.timestamp(timestamp)
.duration(1000)
.success(),
serviceInstance
.transaction({ transactionName: 'GET /banana 🍌' })
.defaults({
'host.hostname': 'bar',
})
.timestamp(timestamp)
.duration(1000)
.success(),
];
})
);
}
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('infrastructure', () => {
loadTestFile(require.resolve('./infrastructure_attributes.spec.ts'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
MiriamAparicio marked this conversation as resolved.
Show resolved Hide resolved
* 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 type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import { generateData } from './generate_data';
import { 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;

async function callApi(serviceName: string) {
const response = await apmApiClient.readUser({
endpoint: 'GET /internal/apm/services/{serviceName}/infrastructure_attributes',
params: {
path: {
serviceName,
},
query: {
start: new Date(start).toISOString(),
end: new Date(end).toISOString(),
environment: 'ENVIRONMENT_ALL',
kuery: '',
},
},
});
return response;
}

describe('Infrastructure APM API', () => {
describe('Infrastructure attributes when data is not loaded', () => {
it('handles the empty state', async () => {
const response = await callApi('synth-go');
expect(response.status).to.be(200);
expect(response.body.containerIds.length).to.be(0);
expect(response.body.hostNames.length).to.be(0);
expect(response.body.podNames.length).to.be(0);
});
});

describe('Infrastructure attributes', () => {
describe('when data is loaded', () => {
let apmSynthtraceEsClient: ApmSynthtraceEsClient;
beforeEach(async () => {
MiriamAparicio marked this conversation as resolved.
Show resolved Hide resolved
apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient();
await generateData({ start, end, apmSynthtraceEsClient });
});

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

describe('when service runs in container', () => {
it('returns arrays of container ids and pod names', async () => {
const response = await callApi('synth-go');
expect(response.status).to.be(200);
expect(response.body.containerIds.length).to.be(1);
expect(response.body.hostNames.length).to.be(1);
expect(response.body.podNames.length).to.be(1);
});
});

describe('when service does NOT run in container', () => {
it('returns array of host names', async () => {
const response = await callApi('synth-java');
expect(response.status).to.be(200);
expect(response.body.containerIds.length).to.be(0);
expect(response.body.hostNames.length).to.be(1);
expect(response.body.podNames.length).to.be(0);
});
});
});
});
});
}