diff --git a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_details.spec.ts b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_details.spec.ts index be0f1be8df99b..a9ec2199c8b23 100644 --- a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_details.spec.ts +++ b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_details.spec.ts @@ -13,6 +13,7 @@ import { APIClientRequestParamsOf, } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; import { RecursivePartial } from '@kbn/apm-plugin/typings/common'; +import { keyBy } from 'lodash'; import { FtrProviderContext } from '../../common/ftr_provider_context'; type StorageDetails = APIReturnType<'GET /internal/apm/services/{serviceName}/storage_details'>; @@ -113,32 +114,18 @@ export default function ApiTest({ getService }: FtrProviderContext) { it('returns correct stats for processor events', async () => { const { status, body } = await callApi(); expect(status).to.be(200); - expect(body.processorEventStats).to.have.length(4); - const transactionStats = body.processorEventStats.find( - ({ processorEvent }) => processorEvent === ProcessorEvent.transaction - ); - expect(transactionStats?.docs).to.be(3); - expect(transactionStats?.size).to.be.greaterThan(0); - - const spanStats = body.processorEventStats.find( - ({ processorEvent }) => processorEvent === ProcessorEvent.span - ); - expect(spanStats?.docs).to.be(6); - expect(spanStats?.size).to.be.greaterThan(0); - - const errorStats = body.processorEventStats.find( - ({ processorEvent }) => processorEvent === ProcessorEvent.error - ); - expect(errorStats?.docs).to.be(9); - expect(errorStats?.size).to.be.greaterThan(0); - - const metricStats = body.processorEventStats.find( - ({ processorEvent }) => processorEvent === ProcessorEvent.metric - ); - expect(metricStats?.docs).to.be.greaterThan(0); - expect(metricStats?.size).to.be.greaterThan(0); + const stats = keyBy(body.processorEventStats, 'processorEvent'); + + expect(stats[ProcessorEvent.transaction]?.docs).to.be(3); + expect(stats[ProcessorEvent.transaction]?.size).to.be.greaterThan(0); + expect(stats[ProcessorEvent.span]?.docs).to.be(6); + expect(stats[ProcessorEvent.span]?.size).to.be.greaterThan(0); + expect(stats[ProcessorEvent.error]?.docs).to.be(9); + expect(stats[ProcessorEvent.error]?.size).to.be.greaterThan(0); + expect(stats[ProcessorEvent.metric]?.docs).to.be.greaterThan(0); + expect(stats[ProcessorEvent.metric]?.size).to.be.greaterThan(0); }); it('returns empty stats when there is no matching environment', async () => { diff --git a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer.spec.ts b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer.spec.ts index bfa537b8f2d61..dc2429a5b8b3a 100644 --- a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer.spec.ts +++ b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer.spec.ts @@ -9,6 +9,7 @@ import { IndexLifecyclePhaseSelectOption } from '@kbn/apm-plugin/common/storage_ import { apm, timerange } from '@kbn/apm-synthtrace'; import { APIClientRequestParamsOf } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; import { RecursivePartial } from '@kbn/apm-plugin/typings/common'; +import { keyBy } from 'lodash'; import { FtrProviderContext } from '../../common/ftr_provider_context'; export default function ApiTest({ getService }: FtrProviderContext) { @@ -109,18 +110,16 @@ export default function ApiTest({ getService }: FtrProviderContext) { expect(body.serviceStatistics).to.have.length(2); - const goServiceStats = body.serviceStatistics.find( - ({ serviceName }) => serviceName === 'opbeans-go' - ); + const stats = keyBy(body.serviceStatistics, 'serviceName'); + + const goServiceStats = stats[goServiceName]; expect(goServiceStats?.environments).to.have.length(1); expect(goServiceStats?.environments).to.contain('production'); expect(goServiceStats?.agentName).to.be('go'); expect(goServiceStats?.size).to.be.greaterThan(0); expect(goServiceStats?.sampling).to.be(1); - const nodeServiceStats = body.serviceStatistics.find( - ({ serviceName }) => serviceName === 'opbeans-node' - ); + const nodeServiceStats = stats[nodeServiceName]; expect(nodeServiceStats?.environments).to.have.length(2); expect(nodeServiceStats?.environments).to.contain('staging'); expect(nodeServiceStats?.environments).to.contain('dev'); diff --git a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer_summary_stats.spec.ts b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer_summary_stats.spec.ts index 64d39dcab141f..afde7d243c227 100644 --- a/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer_summary_stats.spec.ts +++ b/x-pack/test/apm_api_integration/tests/storage_explorer/storage_explorer_summary_stats.spec.ts @@ -10,6 +10,7 @@ import { apm, timerange } from '@kbn/apm-synthtrace'; import { APIClientRequestParamsOf } from '@kbn/apm-plugin/public/services/rest/create_call_apm_api'; import { RecursivePartial } from '@kbn/apm-plugin/typings/common'; import { FtrProviderContext } from '../../common/ftr_provider_context'; +import { roundNumber } from '../../utils'; export default function ApiTest({ getService }: FtrProviderContext) { const registry = getService('registry'); @@ -98,7 +99,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { expect(status).to.be(200); expect(body.numberOfServices).to.be(2); - expect(Math.round(body.tracesPerMinute)).to.be(2); + expect(roundNumber(body.tracesPerMinute)).to.be(2); expect(body.estimatedSize).to.be.greaterThan(0); expect(body.dailyDataGeneration).to.be.greaterThan(0); }); @@ -112,7 +113,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { expect(status).to.be(200); expect(body.numberOfServices).to.be(1); - expect(Math.round(body.tracesPerMinute)).to.be(1); + expect(roundNumber(body.tracesPerMinute)).to.be(1); expect(body.estimatedSize).to.be.greaterThan(0); expect(body.dailyDataGeneration).to.be.greaterThan(0); }); @@ -140,7 +141,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { expect(status).to.be(200); expect(body.numberOfServices).to.be(1); - expect(Math.round(body.tracesPerMinute)).to.be(1); + expect(roundNumber(body.tracesPerMinute)).to.be(1); expect(body.estimatedSize).to.be.greaterThan(0); expect(body.dailyDataGeneration).to.be.greaterThan(0); });