mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 19:13:14 -04:00
## Summary Moving synthtrace clients init inside kbn-journeys: esArchiver does not always solve the issue with data generation. We already have afew journeys using Synthtrace instead and expect more to come. In order to simplify the process of creating new journeys, this PR moves Synthtrace client initialisation into kbn-journey package and exposes a way to define client type, generator function & its input arguments: ``` import { Journey, SynthtraceOptions } from '@kbn/journeys'; import { subj } from '@kbn/test-subj-selector'; import { generateApmData } from '../synthtrace_data/apm_data'; export const journey = new Journey({ synthtrace: { type: 'apm', generator: generateApmData, options: { from: new Date(Date.now() - 1000 * 60 * 15), to: new Date(Date.now() + 1000 * 60 * 15), }, }, }) ``` PR also needs review from teams who use Synthtrace to understand if the implementation is matching expectations. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
80 lines
2.7 KiB
TypeScript
80 lines
2.7 KiB
TypeScript
/*
|
|
* 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, httpExitSpan, timerange } from '@kbn/apm-synthtrace-client';
|
|
import { Readable } from 'stream';
|
|
|
|
export function generateApmData({ from, to }: { from: Date; to: Date }) {
|
|
const range = timerange(from.toISOString(), to.toISOString());
|
|
const transactionName = '240rpm/75% 1000ms';
|
|
|
|
const synthRum = apm
|
|
.service({ name: 'synth-rum', environment: 'production', agentName: 'rum-js' })
|
|
.instance('my-instance');
|
|
const synthNode = apm
|
|
.service({ name: 'synth-node', environment: 'production', agentName: 'nodejs' })
|
|
.instance('my-instance');
|
|
const synthGo = apm
|
|
.service({ name: 'synth-go', environment: 'production', agentName: 'go' })
|
|
.instance('my-instance');
|
|
|
|
const data = range.interval('1m').generator((timestamp) => {
|
|
return synthRum
|
|
.transaction({ transactionName })
|
|
.duration(400)
|
|
.timestamp(timestamp)
|
|
.children(
|
|
// synth-rum -> synth-node
|
|
synthRum
|
|
.span(
|
|
httpExitSpan({
|
|
spanName: 'GET /api/products/top',
|
|
destinationUrl: 'http://synth-node:3000',
|
|
})
|
|
)
|
|
.duration(300)
|
|
.timestamp(timestamp)
|
|
|
|
.children(
|
|
// synth-node
|
|
synthNode
|
|
.transaction({ transactionName: 'Initial transaction in synth-node' })
|
|
.duration(300)
|
|
.timestamp(timestamp)
|
|
.children(
|
|
synthNode
|
|
// synth-node -> synth-go
|
|
.span(
|
|
httpExitSpan({
|
|
spanName: 'GET synth-go:3000',
|
|
destinationUrl: 'http://synth-go:3000',
|
|
})
|
|
)
|
|
.timestamp(timestamp)
|
|
.duration(400)
|
|
|
|
.children(
|
|
// synth-go
|
|
synthGo
|
|
|
|
.transaction({ transactionName: 'Initial transaction in synth-go' })
|
|
.timestamp(timestamp)
|
|
.duration(200)
|
|
.children(
|
|
synthGo
|
|
.span({ spanName: 'custom_operation', spanType: 'custom' })
|
|
.timestamp(timestamp)
|
|
.duration(100)
|
|
.success()
|
|
)
|
|
)
|
|
)
|
|
)
|
|
);
|
|
});
|
|
|
|
return Readable.from(Array.from(data).flatMap((event) => event.serialize()));
|
|
}
|