-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
332 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
x-pack/test/apm_api_integration/tests/suggestions/generate_data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.