Skip to content

Commit

Permalink
Add api test for suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Oct 19, 2022
1 parent d2f0eb7 commit 137741f
Show file tree
Hide file tree
Showing 3 changed files with 332 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function getSuggestionsWithTermsAggregation({
fieldName: string;
fieldValue: string;
searchAggregatedTransactions: boolean;
serviceName: string;
serviceName?: string;
setup: Setup;
size: number;
start: number;
Expand Down
77 changes: 77 additions & 0 deletions x-pack/test/apm_api_integration/tests/suggestions/generate_data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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';
import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace';
import { times } from 'lodash';

export async function generateData({
synthtraceEsClient,
start,
end,
}: {
synthtraceEsClient: ApmSynthtraceEsClient;
start: number;
end: number;
}) {
const services = times(5).flatMap((serviceId) => {
return ['go', 'java'].flatMap((agentName) => {
return ['production', 'development', 'staging'].flatMap((environment) => {
return times(5).flatMap((envId) => {
const service = apm
.service({
name: `${agentName}-${serviceId}`,
environment: `${environment}-${envId}`,
agentName,
})
.instance('instance-a');

return service;
});
});
});
});

const transactionNames = [
'GET /api/product/:id',
'PUT /api/product/:id',
'GET /api/user/:id',
'PUT /api/user/:id',
];

const phpService = apm
.service({
name: `custom-php-service`,
environment: `custom-php-environment`,
agentName: 'php',
})
.instance('instance-a');

const docs = timerange(start, end)
.ratePerMinute(1)
.generator((timestamp) => {
const autoGeneratedDocs = services.flatMap((service) => {
return transactionNames.flatMap((transactionName) => {
return service
.transaction({ transactionName, transactionType: 'my-custom-type' })
.timestamp(timestamp)
.duration(1000);
});
});

const customDoc = phpService
.transaction({
transactionName: 'GET /api/php/memory',
transactionType: 'custom-php-type',
})
.timestamp(timestamp)
.duration(1000);

return [...autoGeneratedDocs, customDoc];
});

return await synthtraceEsClient.index(docs);
}
Loading

0 comments on commit 137741f

Please sign in to comment.