diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/cold_start/cold_start.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/cold_start/cold_start.spec.ts new file mode 100644 index 0000000000000..0e2c89aa4336b --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/cold_start/cold_start.spec.ts @@ -0,0 +1,269 @@ +/* + * 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 { first, last, uniq } from 'lodash'; +import moment from 'moment'; +import { apm, timerange } from '@kbn/apm-synthtrace-client'; +import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; +import { + APIReturnType, + APIClientRequestParamsOf, +} from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; +import { RecursivePartial } from '@kbn/apm-plugin/typings/common'; +import { isFiniteNumber } from '@kbn/apm-plugin/common/utils/is_finite_number'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; + +type ColdStartRate = + APIReturnType<'GET /internal/apm/services/{serviceName}/transactions/charts/coldstart_rate'>; + +const dataConfig = { + serviceName: 'synth-go', + coldStartTransaction: { + name: 'GET /apple 🍎', + duration: 1000, + }, + warmStartTransaction: { + name: 'GET /banana 🍌', + duration: 2000, + }, +}; + +async function generateData({ + apmSynthtraceEsClient, + start, + end, + coldStartRate, + warmStartRate, +}: { + apmSynthtraceEsClient: ApmSynthtraceEsClient; + start: number; + end: number; + coldStartRate: number; + warmStartRate: number; +}) { + const { coldStartTransaction, warmStartTransaction, serviceName } = dataConfig; + const instance = apm + .service({ name: serviceName, environment: 'production', agentName: 'go' }) + .instance('instance-a'); + + const traceEvents = [ + timerange(start, end) + .interval('1m') + .rate(coldStartRate) + .generator((timestamp) => + instance + .transaction({ transactionName: coldStartTransaction.name }) + .defaults({ + 'faas.coldstart': true, + }) + .timestamp(timestamp) + .duration(coldStartTransaction.duration) + .success() + ), + timerange(start, end) + .interval('1m') + .rate(warmStartRate) + .generator((timestamp) => + instance + .transaction({ transactionName: warmStartTransaction.name }) + .defaults({ + 'faas.coldstart': false, + }) + .timestamp(timestamp) + .duration(warmStartTransaction.duration) + .success() + ), + ]; + + await apmSynthtraceEsClient.index(traceEvents); +} + +export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { + const apmApiClient = getService('apmApi'); + const synthtrace = getService('synthtrace'); + + const { serviceName } = dataConfig; + 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( + overrides?: RecursivePartial< + APIClientRequestParamsOf<'GET /internal/apm/services/{serviceName}/transactions/charts/coldstart_rate'>['params'] + > + ) { + return await apmApiClient.readUser({ + endpoint: 'GET /internal/apm/services/{serviceName}/transactions/charts/coldstart_rate', + params: { + path: { serviceName }, + query: { + transactionType: 'request', + environment: 'ENVIRONMENT_ALL', + start: new Date(start).toISOString(), + end: new Date(end).toISOString(), + kuery: '', + ...overrides?.query, + }, + }, + }); + } + + describe('Cold start', () => { + describe('Cold start rate when data is not loaded', () => { + it('handles empty state', async () => { + const { status, body } = await callApi(); + + expect(status).to.be(200); + expect(body.currentPeriod.transactionColdstartRate).to.empty(); + expect(body.currentPeriod.average).to.be(null); + + expect(body.previousPeriod.transactionColdstartRate).to.empty(); + expect(body.previousPeriod.average).to.be(null); + }); + }); + + describe('Cold start rate when data is generated', () => { + let apmSynthtraceEsClient: ApmSynthtraceEsClient; + + before(async () => { + apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); + }); + + describe('without comparison', () => { + let body: ColdStartRate; + let status: number; + + before(async () => { + await generateData({ + apmSynthtraceEsClient, + start, + end, + coldStartRate: 10, + warmStartRate: 30, + }); + const response = await callApi(); + body = response.body; + status = response.status; + }); + + after(() => apmSynthtraceEsClient.clean()); + + it('returns correct HTTP status', () => { + expect(status).to.be(200); + }); + + it('returns an array of transaction cold start rates', () => { + expect(body).to.have.property('currentPeriod'); + expect(body.currentPeriod.transactionColdstartRate).to.have.length(15); + expect(body.currentPeriod.transactionColdstartRate.every(({ y }) => y === 0.25)).to.be( + true + ); + }); + + it('returns correct average rate', () => { + expect(body.currentPeriod.average).to.be(0.25); + }); + + it("doesn't have data for the previous period", () => { + expect(body).to.have.property('previousPeriod'); + expect(body.previousPeriod.transactionColdstartRate).to.have.length(0); + expect(body.previousPeriod.average).to.be(null); + }); + }); + + describe('with comparison', () => { + let body: ColdStartRate; + let status: number; + + before(async () => { + const startDate = moment(start).add(6, 'minutes'); + const endDate = moment(start).add(9, 'minutes'); + const comparisonStartDate = new Date(start); + const comparisonEndDate = moment(start).add(3, 'minutes'); + + await generateData({ + apmSynthtraceEsClient, + start: startDate.valueOf(), + end: endDate.valueOf(), + coldStartRate: 10, + warmStartRate: 30, + }); + await generateData({ + apmSynthtraceEsClient, + start: comparisonStartDate.getTime(), + end: comparisonEndDate.valueOf(), + coldStartRate: 20, + warmStartRate: 20, + }); + + const response = await callApi({ + query: { + start: startDate.toISOString(), + end: endDate.subtract(1, 'seconds').toISOString(), + offset: '6m', + }, + }); + body = response.body; + status = response.status; + }); + + after(() => apmSynthtraceEsClient.clean()); + + it('returns correct HTTP status', () => { + expect(status).to.be(200); + }); + + it('returns some data', () => { + expect(body.currentPeriod.average).not.to.be(null); + expect(body.currentPeriod.transactionColdstartRate.length).to.be.greaterThan(0); + const hasCurrentPeriodData = body.currentPeriod.transactionColdstartRate.some(({ y }) => + isFiniteNumber(y) + ); + expect(hasCurrentPeriodData).to.equal(true); + + expect(body.previousPeriod.average).not.to.be(null); + expect(body.previousPeriod.transactionColdstartRate.length).to.be.greaterThan(0); + const hasPreviousPeriodData = body.previousPeriod.transactionColdstartRate.some(({ y }) => + isFiniteNumber(y) + ); + expect(hasPreviousPeriodData).to.equal(true); + }); + + it('has same start time for both periods', () => { + expect(first(body.currentPeriod.transactionColdstartRate)?.x).to.equal( + first(body.previousPeriod.transactionColdstartRate)?.x + ); + }); + + it('has same end time for both periods', () => { + expect(last(body.currentPeriod.transactionColdstartRate)?.x).to.equal( + last(body.previousPeriod.transactionColdstartRate)?.x + ); + }); + + it('returns an array of transaction cold start rates', () => { + const currentValuesUnique = uniq( + body.currentPeriod.transactionColdstartRate.map(({ y }) => y) + ); + const prevValuesUnique = uniq( + body.previousPeriod.transactionColdstartRate.map(({ y }) => y) + ); + + expect(currentValuesUnique).to.eql([0.25]); + expect(body.currentPeriod.transactionColdstartRate).to.have.length(3); + + expect(prevValuesUnique).to.eql([0.5]); + expect(body.previousPeriod.transactionColdstartRate).to.have.length(3); + }); + + it('has same average value for both periods', () => { + expect(body.currentPeriod.average).to.be(0.25); + expect(body.previousPeriod.average).to.be(0.5); + }); + }); + }); + }); +} diff --git a/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/cold_start_by_transaction_name.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/cold_start/cold_start_by_transaction_name.spec.ts similarity index 76% rename from x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/cold_start_by_transaction_name.spec.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/cold_start/cold_start_by_transaction_name.spec.ts index 7019735a05498..a2aa3a7d11546 100644 --- a/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/cold_start_by_transaction_name.spec.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/cold_start/cold_start_by_transaction_name.spec.ts @@ -7,22 +7,78 @@ import expect from '@kbn/expect'; import { first, last } from 'lodash'; import moment from 'moment'; +import { apm, timerange } from '@kbn/apm-synthtrace-client'; +import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; import { APIReturnType, APIClientRequestParamsOf, } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; import { RecursivePartial } from '@kbn/apm-plugin/typings/common'; import { isFiniteNumber } from '@kbn/apm-plugin/common/utils/is_finite_number'; -import { dataConfig, generateData } from './generate_data'; -import { FtrProviderContext } from '../../../common/ftr_provider_context'; +import type { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; type ColdStartRate = APIReturnType<'GET /internal/apm/services/{serviceName}/transactions/charts/coldstart_rate_by_transaction_name'>; -export default function ApiTest({ getService }: FtrProviderContext) { - const registry = getService('registry'); - const apmApiClient = getService('apmApiClient'); - const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); +const dataConfig = { + serviceName: 'synth-go', + transactionName: 'GET /apple 🍎', + duration: 1000, +}; + +async function generateData({ + apmSynthtraceEsClient, + start, + end, + coldStartRate, + warmStartRate, +}: { + apmSynthtraceEsClient: ApmSynthtraceEsClient; + start: number; + end: number; + coldStartRate: number; + warmStartRate: number; +}) { + const { transactionName, duration, serviceName } = dataConfig; + const instance = apm + .service({ name: serviceName, environment: 'production', agentName: 'go' }) + .instance('instance-a'); + + const traceEvents = [ + timerange(start, end) + .interval('1m') + .rate(coldStartRate) + .generator((timestamp) => + instance + .transaction({ transactionName }) + .defaults({ + 'faas.coldstart': true, + }) + .timestamp(timestamp) + .duration(duration) + .success() + ), + timerange(start, end) + .interval('1m') + .rate(warmStartRate) + .generator((timestamp) => + instance + .transaction({ transactionName }) + .defaults({ + 'faas.coldstart': false, + }) + .timestamp(timestamp) + .duration(duration) + .success() + ), + ]; + + await apmSynthtraceEsClient.index(traceEvents); +} + +export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { + const apmApiClient = getService('apmApi'); + const synthtrace = getService('synthtrace'); const { serviceName, transactionName } = dataConfig; const start = new Date('2021-01-01T00:00:00.000Z').getTime(); @@ -51,10 +107,8 @@ export default function ApiTest({ getService }: FtrProviderContext) { }); } - registry.when( - 'Cold start rate by transaction name when data is not loaded', - { config: 'basic', archives: [] }, - () => { + describe('Cold start by transaction name', () => { + describe('when data is not loaded', () => { it('handles empty state', async () => { const { status, body } = await callApi(); @@ -65,14 +119,15 @@ export default function ApiTest({ getService }: FtrProviderContext) { expect(body.previousPeriod.transactionColdstartRate).to.empty(); expect(body.previousPeriod.average).to.be(null); }); - } - ); - - // FLAKY: https://github.com/elastic/kibana/issues/177616 - registry.when( - 'Cold start rate by transaction name when data is generated', - { config: 'basic', archives: [] }, - () => { + }); + + describe('when data is generated', () => { + let apmSynthtraceEsClient: ApmSynthtraceEsClient; + + before(async () => { + apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); + }); + describe('without comparison', () => { let body: ColdStartRate; let status: number; @@ -202,6 +257,6 @@ export default function ApiTest({ getService }: FtrProviderContext) { expect(body.previousPeriod.average).to.be(0.5); }); }); - } - ); + }); + }); } diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/cold_start/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/cold_start/index.ts new file mode 100644 index 0000000000000..a5d8045f227d3 --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/cold_start/index.ts @@ -0,0 +1,15 @@ +/* + * 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('cold_start', () => { + loadTestFile(require.resolve('./cold_start.spec.ts')); + loadTestFile(require.resolve('./cold_start_by_transaction_name.spec.ts')); + }); +} diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts index 93ef6ed2764fe..3e490a621d3f9 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/index.ts @@ -15,5 +15,6 @@ export default function apmApiIntegrationTests({ loadTestFile(require.resolve('./mobile')); loadTestFile(require.resolve('./custom_dashboards')); loadTestFile(require.resolve('./dependencies')); + loadTestFile(require.resolve('./cold_start')); }); } diff --git a/x-pack/test/apm_api_integration/tests/cold_start/cold_start.spec.ts b/x-pack/test/apm_api_integration/tests/cold_start/cold_start.spec.ts deleted file mode 100644 index 7d0b2f6d8a625..0000000000000 --- a/x-pack/test/apm_api_integration/tests/cold_start/cold_start.spec.ts +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 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 { first, last, uniq } from 'lodash'; -import moment from 'moment'; -import { - APIReturnType, - APIClientRequestParamsOf, -} from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; -import { RecursivePartial } from '@kbn/apm-plugin/typings/common'; -import { isFiniteNumber } from '@kbn/apm-plugin/common/utils/is_finite_number'; -import { dataConfig, generateData } from './generate_data'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; - -type ColdStartRate = - APIReturnType<'GET /internal/apm/services/{serviceName}/transactions/charts/coldstart_rate'>; - -export default function ApiTest({ getService }: FtrProviderContext) { - const registry = getService('registry'); - const apmApiClient = getService('apmApiClient'); - const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); - - const { serviceName } = dataConfig; - 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( - overrides?: RecursivePartial< - APIClientRequestParamsOf<'GET /internal/apm/services/{serviceName}/transactions/charts/coldstart_rate'>['params'] - > - ) { - return await apmApiClient.readUser({ - endpoint: 'GET /internal/apm/services/{serviceName}/transactions/charts/coldstart_rate', - params: { - path: { serviceName }, - query: { - transactionType: 'request', - environment: 'ENVIRONMENT_ALL', - start: new Date(start).toISOString(), - end: new Date(end).toISOString(), - kuery: '', - ...overrides?.query, - }, - }, - }); - } - - registry.when( - 'Cold start rate when data is not loaded', - { config: 'basic', archives: [] }, - () => { - it('handles empty state', async () => { - const { status, body } = await callApi(); - - expect(status).to.be(200); - expect(body.currentPeriod.transactionColdstartRate).to.empty(); - expect(body.currentPeriod.average).to.be(null); - - expect(body.previousPeriod.transactionColdstartRate).to.empty(); - expect(body.previousPeriod.average).to.be(null); - }); - } - ); - - // FLAKY: https://github.com/elastic/kibana/issues/177113 - registry.when('Cold start rate when data is generated', { config: 'basic', archives: [] }, () => { - describe('without comparison', () => { - let body: ColdStartRate; - let status: number; - - before(async () => { - await generateData({ - apmSynthtraceEsClient, - start, - end, - coldStartRate: 10, - warmStartRate: 30, - }); - const response = await callApi(); - body = response.body; - status = response.status; - }); - - after(() => apmSynthtraceEsClient.clean()); - - it('returns correct HTTP status', () => { - expect(status).to.be(200); - }); - - it('returns an array of transaction cold start rates', () => { - expect(body).to.have.property('currentPeriod'); - expect(body.currentPeriod.transactionColdstartRate).to.have.length(15); - expect(body.currentPeriod.transactionColdstartRate.every(({ y }) => y === 0.25)).to.be( - true - ); - }); - - it('returns correct average rate', () => { - expect(body.currentPeriod.average).to.be(0.25); - }); - - it("doesn't have data for the previous period", () => { - expect(body).to.have.property('previousPeriod'); - expect(body.previousPeriod.transactionColdstartRate).to.have.length(0); - expect(body.previousPeriod.average).to.be(null); - }); - }); - - describe('with comparison', () => { - let body: ColdStartRate; - let status: number; - - before(async () => { - const startDate = moment(start).add(6, 'minutes'); - const endDate = moment(start).add(9, 'minutes'); - const comparisonStartDate = new Date(start); - const comparisonEndDate = moment(start).add(3, 'minutes'); - - await generateData({ - apmSynthtraceEsClient, - start: startDate.valueOf(), - end: endDate.valueOf(), - coldStartRate: 10, - warmStartRate: 30, - }); - await generateData({ - apmSynthtraceEsClient, - start: comparisonStartDate.getTime(), - end: comparisonEndDate.valueOf(), - coldStartRate: 20, - warmStartRate: 20, - }); - - const response = await callApi({ - query: { - start: startDate.toISOString(), - end: endDate.subtract(1, 'seconds').toISOString(), - offset: '6m', - }, - }); - body = response.body; - status = response.status; - }); - - after(() => apmSynthtraceEsClient.clean()); - - it('returns correct HTTP status', () => { - expect(status).to.be(200); - }); - - it('returns some data', () => { - expect(body.currentPeriod.average).not.to.be(null); - expect(body.currentPeriod.transactionColdstartRate.length).to.be.greaterThan(0); - const hasCurrentPeriodData = body.currentPeriod.transactionColdstartRate.some(({ y }) => - isFiniteNumber(y) - ); - expect(hasCurrentPeriodData).to.equal(true); - - expect(body.previousPeriod.average).not.to.be(null); - expect(body.previousPeriod.transactionColdstartRate.length).to.be.greaterThan(0); - const hasPreviousPeriodData = body.previousPeriod.transactionColdstartRate.some(({ y }) => - isFiniteNumber(y) - ); - expect(hasPreviousPeriodData).to.equal(true); - }); - - it('has same start time for both periods', () => { - expect(first(body.currentPeriod.transactionColdstartRate)?.x).to.equal( - first(body.previousPeriod.transactionColdstartRate)?.x - ); - }); - - it('has same end time for both periods', () => { - expect(last(body.currentPeriod.transactionColdstartRate)?.x).to.equal( - last(body.previousPeriod.transactionColdstartRate)?.x - ); - }); - - it('returns an array of transaction cold start rates', () => { - const currentValuesUnique = uniq( - body.currentPeriod.transactionColdstartRate.map(({ y }) => y) - ); - const prevValuesUnique = uniq( - body.previousPeriod.transactionColdstartRate.map(({ y }) => y) - ); - - expect(currentValuesUnique).to.eql([0.25]); - expect(body.currentPeriod.transactionColdstartRate).to.have.length(3); - - expect(prevValuesUnique).to.eql([0.5]); - expect(body.previousPeriod.transactionColdstartRate).to.have.length(3); - }); - - it('has same average value for both periods', () => { - expect(body.currentPeriod.average).to.be(0.25); - expect(body.previousPeriod.average).to.be(0.5); - }); - }); - }); -} diff --git a/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/generate_data.ts b/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/generate_data.ts deleted file mode 100644 index ff4d725a3d017..0000000000000 --- a/x-pack/test/apm_api_integration/tests/cold_start/cold_start_by_transaction_name/generate_data.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 const dataConfig = { - serviceName: 'synth-go', - transactionName: 'GET /apple 🍎', - duration: 1000, -}; - -export async function generateData({ - apmSynthtraceEsClient, - start, - end, - coldStartRate, - warmStartRate, -}: { - apmSynthtraceEsClient: ApmSynthtraceEsClient; - start: number; - end: number; - coldStartRate: number; - warmStartRate: number; -}) { - const { transactionName, duration, serviceName } = dataConfig; - const instance = apm - .service({ name: serviceName, environment: 'production', agentName: 'go' }) - .instance('instance-a'); - - const traceEvents = [ - timerange(start, end) - .interval('1m') - .rate(coldStartRate) - .generator((timestamp) => - instance - .transaction({ transactionName }) - .defaults({ - 'faas.coldstart': true, - }) - .timestamp(timestamp) - .duration(duration) - .success() - ), - timerange(start, end) - .interval('1m') - .rate(warmStartRate) - .generator((timestamp) => - instance - .transaction({ transactionName }) - .defaults({ - 'faas.coldstart': false, - }) - .timestamp(timestamp) - .duration(duration) - .success() - ), - ]; - - await apmSynthtraceEsClient.index(traceEvents); -} diff --git a/x-pack/test/apm_api_integration/tests/cold_start/generate_data.ts b/x-pack/test/apm_api_integration/tests/cold_start/generate_data.ts deleted file mode 100644 index 9c36e53e82632..0000000000000 --- a/x-pack/test/apm_api_integration/tests/cold_start/generate_data.ts +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 const dataConfig = { - serviceName: 'synth-go', - coldStartTransaction: { - name: 'GET /apple 🍎', - duration: 1000, - }, - warmStartTransaction: { - name: 'GET /banana 🍌', - duration: 2000, - }, -}; - -export async function generateData({ - apmSynthtraceEsClient, - start, - end, - coldStartRate, - warmStartRate, -}: { - apmSynthtraceEsClient: ApmSynthtraceEsClient; - start: number; - end: number; - coldStartRate: number; - warmStartRate: number; -}) { - const { coldStartTransaction, warmStartTransaction, serviceName } = dataConfig; - const instance = apm - .service({ name: serviceName, environment: 'production', agentName: 'go' }) - .instance('instance-a'); - - const traceEvents = [ - timerange(start, end) - .interval('1m') - .rate(coldStartRate) - .generator((timestamp) => - instance - .transaction({ transactionName: coldStartTransaction.name }) - .defaults({ - 'faas.coldstart': true, - }) - .timestamp(timestamp) - .duration(coldStartTransaction.duration) - .success() - ), - timerange(start, end) - .interval('1m') - .rate(warmStartRate) - .generator((timestamp) => - instance - .transaction({ transactionName: warmStartTransaction.name }) - .defaults({ - 'faas.coldstart': false, - }) - .timestamp(timestamp) - .duration(warmStartTransaction.duration) - .success() - ), - ]; - - await apmSynthtraceEsClient.index(traceEvents); -}