From de2af69da341815995bc9fbc9c9bb10d72570c47 Mon Sep 17 00:00:00 2001 From: iblancof Date: Tue, 12 Nov 2024 15:27:33 +0100 Subject: [PATCH 1/3] Create latency data deployment agnostic api tests --- .../apis/observability/apm/index.ts | 1 + .../apis/observability/apm/latency/index.ts | 15 ++ .../apm/latency/service_apis.spec.ts | 236 ++++++++++++++++++ .../apm/latency/service_maps.spec.ts | 147 +++++++++++ 4 files changed, 399 insertions(+) create mode 100644 x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/index.ts create mode 100644 x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/service_apis.spec.ts create mode 100644 x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/service_maps.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 a62386b536ea8..ad3d942e097ba 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 @@ -21,5 +21,6 @@ export default function apmApiIntegrationTests({ loadTestFile(require.resolve('./correlations')); loadTestFile(require.resolve('./entities')); loadTestFile(require.resolve('./cold_start')); + loadTestFile(require.resolve('./latency')); }); } diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/index.ts new file mode 100644 index 0000000000000..0b9a71293f687 --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/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('latency', () => { + loadTestFile(require.resolve('./service_apis.spec.ts')); + loadTestFile(require.resolve('./service_maps.spec.ts')); + }); +} diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/service_apis.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/service_apis.spec.ts new file mode 100644 index 0000000000000..dee5f27b7a61d --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/service_apis.spec.ts @@ -0,0 +1,236 @@ +/* + * 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 expect from '@kbn/expect'; +import { meanBy, sumBy } from 'lodash'; +import { LatencyAggregationType } from '@kbn/apm-plugin/common/latency_aggregation_types'; +import { isFiniteNumber } from '@kbn/apm-plugin/common/utils/is_finite_number'; +import { ApmDocumentType } from '@kbn/apm-plugin/common/document_type'; +import { RollupInterval } from '@kbn/apm-plugin/common/rollup'; +import { ProcessorEvent } from '@kbn/observability-plugin/common'; +import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; +import { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { + const apmApiClient = getService('apmApi'); + const synthtrace = getService('synthtrace'); + + const serviceName = 'synth-go'; + 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 getLatencyValues({ + processorEvent, + latencyAggregationType = LatencyAggregationType.avg, + useDurationSummary = false, + }: { + processorEvent: 'transaction' | 'metric'; + latencyAggregationType?: LatencyAggregationType; + useDurationSummary?: boolean; + }) { + const commonQuery = { + start: new Date(start).toISOString(), + end: new Date(end).toISOString(), + environment: 'ENVIRONMENT_ALL', + }; + const [ + serviceInventoryAPIResponse, + serviceLantencyAPIResponse, + transactionsGroupDetailsAPIResponse, + serviceInstancesAPIResponse, + ] = await Promise.all([ + apmApiClient.readUser({ + endpoint: 'GET /internal/apm/services', + params: { + query: { + ...commonQuery, + kuery: `service.name : "${serviceName}" and processor.event : "${processorEvent}"`, + probability: 1, + ...(processorEvent === ProcessorEvent.metric + ? { + documentType: ApmDocumentType.TransactionMetric, + rollupInterval: RollupInterval.OneMinute, + useDurationSummary: true, + } + : { + documentType: ApmDocumentType.TransactionEvent, + rollupInterval: RollupInterval.None, + useDurationSummary: false, + }), + }, + }, + }), + apmApiClient.readUser({ + endpoint: 'GET /internal/apm/services/{serviceName}/transactions/charts/latency', + params: { + path: { serviceName }, + query: { + ...commonQuery, + kuery: `processor.event : "${processorEvent}"`, + latencyAggregationType, + transactionType: 'request', + bucketSizeInSeconds: 60, + ...(processorEvent === ProcessorEvent.metric + ? { + documentType: ApmDocumentType.TransactionMetric, + rollupInterval: RollupInterval.OneMinute, + } + : { + documentType: ApmDocumentType.TransactionEvent, + rollupInterval: RollupInterval.None, + }), + useDurationSummary: latencyAggregationType === LatencyAggregationType.avg, + }, + }, + }), + apmApiClient.readUser({ + endpoint: `GET /internal/apm/services/{serviceName}/transactions/groups/main_statistics`, + params: { + path: { serviceName }, + query: { + ...commonQuery, + kuery: `processor.event : "${processorEvent}"`, + transactionType: 'request', + latencyAggregationType: 'avg' as LatencyAggregationType, + useDurationSummary, + ...(processorEvent === ProcessorEvent.metric + ? { + documentType: ApmDocumentType.TransactionMetric, + rollupInterval: RollupInterval.OneMinute, + } + : { + documentType: ApmDocumentType.TransactionEvent, + rollupInterval: RollupInterval.None, + }), + }, + }, + }), + apmApiClient.readUser({ + endpoint: `GET /internal/apm/services/{serviceName}/service_overview_instances/main_statistics`, + params: { + path: { serviceName }, + query: { + ...commonQuery, + kuery: `processor.event : "${processorEvent}"`, + transactionType: 'request', + latencyAggregationType: 'avg' as LatencyAggregationType, + sortField: 'throughput', + sortDirection: 'desc', + }, + }, + }), + ]); + + const serviceInventoryLatency = serviceInventoryAPIResponse.body.items[0].latency; + + const latencyChartApiMean = meanBy( + serviceLantencyAPIResponse.body.currentPeriod.latencyTimeseries.filter( + (item) => isFiniteNumber(item.y) && item.y > 0 + ), + 'y' + ); + + const transactionsGroupLatencySum = sumBy( + transactionsGroupDetailsAPIResponse.body.transactionGroups, + 'latency' + ); + + const serviceInstancesLatencySum = sumBy( + serviceInstancesAPIResponse.body.currentPeriod, + 'latency' + ); + + return { + serviceInventoryLatency, + latencyChartApiMean, + transactionsGroupLatencySum, + serviceInstancesLatencySum, + }; + } + + let latencyMetricValues: Awaited>; + let latencyTransactionValues: Awaited>; + + // FLAKY: https://github.com/elastic/kibana/issues/177387 + describe('Services APIs', () => { + let apmSynthtraceEsClient: ApmSynthtraceEsClient; + + before(async () => { + apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); + }); + + describe('when data is loaded ', () => { + const GO_PROD_RATE = 80; + const GO_DEV_RATE = 20; + const GO_PROD_DURATION = 1000; + const GO_DEV_DURATION = 500; + before(async () => { + const serviceGoProdInstance = apm + .service({ name: serviceName, environment: 'production', agentName: 'go' }) + .instance('instance-a'); + const serviceGoDevInstance = apm + .service({ name: serviceName, environment: 'development', agentName: 'go' }) + .instance('instance-b'); + + await apmSynthtraceEsClient.index([ + timerange(start, end) + .interval('1m') + .rate(GO_PROD_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: 'GET /api/product/list' }) + .duration(GO_PROD_DURATION) + .timestamp(timestamp) + ), + timerange(start, end) + .interval('1m') + .rate(GO_DEV_RATE) + .generator((timestamp) => + serviceGoDevInstance + .transaction({ transactionName: 'GET /api/product/:id' }) + .duration(GO_DEV_DURATION) + .timestamp(timestamp) + ), + ]); + }); + + after(() => apmSynthtraceEsClient.clean()); + + describe('compare latency value between service inventory, latency chart, service inventory and transactions apis', () => { + before(async () => { + [latencyTransactionValues, latencyMetricValues] = await Promise.all([ + getLatencyValues({ processorEvent: 'transaction' }), + getLatencyValues({ processorEvent: 'metric', useDurationSummary: true }), + ]); + }); + + it('returns same avg latency value for Transaction-based and Metric-based data', () => { + const expectedLatencyAvgValueMs = + ((GO_PROD_RATE * GO_PROD_DURATION + GO_DEV_RATE * GO_DEV_DURATION) / + (GO_PROD_RATE + GO_DEV_RATE)) * + 1000; + [ + latencyTransactionValues.latencyChartApiMean, + latencyTransactionValues.serviceInventoryLatency, + latencyMetricValues.latencyChartApiMean, + latencyMetricValues.serviceInventoryLatency, + ].forEach((value) => expect(value).to.be.equal(expectedLatencyAvgValueMs)); + }); + + it('returns same sum latency value for Transaction-based and Metric-based data', () => { + const expectedLatencySumValueMs = (GO_PROD_DURATION + GO_DEV_DURATION) * 1000; + [ + latencyTransactionValues.transactionsGroupLatencySum, + latencyTransactionValues.serviceInstancesLatencySum, + latencyMetricValues.transactionsGroupLatencySum, + latencyMetricValues.serviceInstancesLatencySum, + ].forEach((value) => expect(value).to.be.equal(expectedLatencySumValueMs)); + }); + }); + }); + }); +} diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/service_maps.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/service_maps.spec.ts new file mode 100644 index 0000000000000..5edd4c76648af --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/service_maps.spec.ts @@ -0,0 +1,147 @@ +/* + * 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 expect from '@kbn/expect'; +import { meanBy } from 'lodash'; +import { ApmDocumentType } from '@kbn/apm-plugin/common/document_type'; +import { RollupInterval } from '@kbn/apm-plugin/common/rollup'; +import { ProcessorEvent } from '@kbn/observability-plugin/common'; +import { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; +import { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; + +export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderContext) { + const apmApiClient = getService('apmApi'); + const synthtrace = getService('synthtrace'); + + const serviceName = 'synth-go'; + 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 getLatencyValues(processorEvent: 'transaction' | 'metric') { + const commonQuery = { + start: new Date(start).toISOString(), + end: new Date(end).toISOString(), + environment: 'ENVIRONMENT_ALL', + }; + const [serviceInventoryAPIResponse, serviceMapsNodeDetails] = await Promise.all([ + apmApiClient.readUser({ + endpoint: 'GET /internal/apm/services', + params: { + query: { + ...commonQuery, + kuery: `service.name : "${serviceName}" and processor.event : "${processorEvent}"`, + probability: 1, + ...(processorEvent === ProcessorEvent.metric + ? { + documentType: ApmDocumentType.TransactionMetric, + rollupInterval: RollupInterval.OneMinute, + useDurationSummary: true, + } + : { + documentType: ApmDocumentType.TransactionEvent, + rollupInterval: RollupInterval.None, + useDurationSummary: false, + }), + }, + }, + }), + apmApiClient.readUser({ + endpoint: `GET /internal/apm/service-map/service/{serviceName}`, + params: { + path: { serviceName }, + query: commonQuery, + }, + }), + ]); + + const serviceInventoryLatency = serviceInventoryAPIResponse.body.items[0].latency; + + const serviceMapsNodeDetailsLatency = meanBy( + serviceMapsNodeDetails.body.currentPeriod.transactionStats?.latency?.timeseries, + 'y' + ); + + return { + serviceInventoryLatency, + serviceMapsNodeDetailsLatency, + }; + } + + let latencyMetricValues: Awaited>; + let latencyTransactionValues: Awaited>; + + describe('Service Maps APIs', () => { + let apmSynthtraceEsClient: ApmSynthtraceEsClient; + + before(async () => { + apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); + }); + + describe('when data is loaded ', () => { + const GO_PROD_RATE = 80; + const GO_DEV_RATE = 20; + const GO_PROD_DURATION = 1000; + const GO_DEV_DURATION = 500; + + before(async () => { + const serviceGoProdInstance = apm + .service({ name: serviceName, environment: 'production', agentName: 'go' }) + .instance('instance-a'); + const serviceGoDevInstance = apm + .service({ name: serviceName, environment: 'development', agentName: 'go' }) + .instance('instance-b'); + + await apmSynthtraceEsClient.index([ + timerange(start, end) + .interval('1m') + .rate(GO_PROD_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ + transactionName: 'GET /api/product/list', + transactionType: 'Worker', + }) + .duration(GO_PROD_DURATION) + .timestamp(timestamp) + ), + timerange(start, end) + .interval('1m') + .rate(GO_DEV_RATE) + .generator((timestamp) => + serviceGoDevInstance + .transaction({ transactionName: 'GET /api/product/:id' }) + .duration(GO_DEV_DURATION) + .timestamp(timestamp) + ), + ]); + }); + + after(() => apmSynthtraceEsClient.clean()); + + // FLAKY: https://github.com/elastic/kibana/issues/176976 + describe('compare latency value between service inventory and service maps', () => { + before(async () => { + [latencyTransactionValues, latencyMetricValues] = await Promise.all([ + getLatencyValues('transaction'), + getLatencyValues('metric'), + ]); + }); + + it('returns same avg latency value for Transaction-based and Metric-based data', () => { + const expectedLatencyAvgValueMs = ((GO_DEV_RATE * GO_DEV_DURATION) / GO_DEV_RATE) * 1000; + + [ + latencyTransactionValues.serviceMapsNodeDetailsLatency, + latencyTransactionValues.serviceInventoryLatency, + latencyMetricValues.serviceMapsNodeDetailsLatency, + latencyMetricValues.serviceInventoryLatency, + ].forEach((value) => expect(value).to.be.equal(expectedLatencyAvgValueMs)); + }); + }); + }); + }); +} From e238bd04b137ae682b62cab7cc1c31024881e1fb Mon Sep 17 00:00:00 2001 From: iblancof Date: Tue, 12 Nov 2024 15:30:20 +0100 Subject: [PATCH 2/3] Delete latency old tests --- .../tests/latency/service_apis.spec.ts | 230 ------------------ .../tests/latency/service_maps.spec.ts | 139 ----------- 2 files changed, 369 deletions(-) delete mode 100644 x-pack/test/apm_api_integration/tests/latency/service_apis.spec.ts delete mode 100644 x-pack/test/apm_api_integration/tests/latency/service_maps.spec.ts diff --git a/x-pack/test/apm_api_integration/tests/latency/service_apis.spec.ts b/x-pack/test/apm_api_integration/tests/latency/service_apis.spec.ts deleted file mode 100644 index 35ef23c8a4430..0000000000000 --- a/x-pack/test/apm_api_integration/tests/latency/service_apis.spec.ts +++ /dev/null @@ -1,230 +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 expect from '@kbn/expect'; -import { meanBy, sumBy } from 'lodash'; -import { LatencyAggregationType } from '@kbn/apm-plugin/common/latency_aggregation_types'; -import { isFiniteNumber } from '@kbn/apm-plugin/common/utils/is_finite_number'; -import { ApmDocumentType } from '@kbn/apm-plugin/common/document_type'; -import { RollupInterval } from '@kbn/apm-plugin/common/rollup'; -import { ProcessorEvent } from '@kbn/observability-plugin/common'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; - -export default function ApiTest({ getService }: FtrProviderContext) { - const registry = getService('registry'); - const apmApiClient = getService('apmApiClient'); - const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); - - const serviceName = 'synth-go'; - 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 getLatencyValues({ - processorEvent, - latencyAggregationType = LatencyAggregationType.avg, - useDurationSummary = false, - }: { - processorEvent: 'transaction' | 'metric'; - latencyAggregationType?: LatencyAggregationType; - useDurationSummary?: boolean; - }) { - const commonQuery = { - start: new Date(start).toISOString(), - end: new Date(end).toISOString(), - environment: 'ENVIRONMENT_ALL', - }; - const [ - serviceInventoryAPIResponse, - serviceLantencyAPIResponse, - transactionsGroupDetailsAPIResponse, - serviceInstancesAPIResponse, - ] = await Promise.all([ - apmApiClient.readUser({ - endpoint: 'GET /internal/apm/services', - params: { - query: { - ...commonQuery, - kuery: `service.name : "${serviceName}" and processor.event : "${processorEvent}"`, - probability: 1, - ...(processorEvent === ProcessorEvent.metric - ? { - documentType: ApmDocumentType.TransactionMetric, - rollupInterval: RollupInterval.OneMinute, - useDurationSummary: true, - } - : { - documentType: ApmDocumentType.TransactionEvent, - rollupInterval: RollupInterval.None, - useDurationSummary: false, - }), - }, - }, - }), - apmApiClient.readUser({ - endpoint: 'GET /internal/apm/services/{serviceName}/transactions/charts/latency', - params: { - path: { serviceName }, - query: { - ...commonQuery, - kuery: `processor.event : "${processorEvent}"`, - latencyAggregationType, - transactionType: 'request', - bucketSizeInSeconds: 60, - ...(processorEvent === ProcessorEvent.metric - ? { - documentType: ApmDocumentType.TransactionMetric, - rollupInterval: RollupInterval.OneMinute, - } - : { - documentType: ApmDocumentType.TransactionEvent, - rollupInterval: RollupInterval.None, - }), - useDurationSummary: latencyAggregationType === LatencyAggregationType.avg, - }, - }, - }), - apmApiClient.readUser({ - endpoint: `GET /internal/apm/services/{serviceName}/transactions/groups/main_statistics`, - params: { - path: { serviceName }, - query: { - ...commonQuery, - kuery: `processor.event : "${processorEvent}"`, - transactionType: 'request', - latencyAggregationType: 'avg' as LatencyAggregationType, - useDurationSummary, - ...(processorEvent === ProcessorEvent.metric - ? { - documentType: ApmDocumentType.TransactionMetric, - rollupInterval: RollupInterval.OneMinute, - } - : { - documentType: ApmDocumentType.TransactionEvent, - rollupInterval: RollupInterval.None, - }), - }, - }, - }), - apmApiClient.readUser({ - endpoint: `GET /internal/apm/services/{serviceName}/service_overview_instances/main_statistics`, - params: { - path: { serviceName }, - query: { - ...commonQuery, - kuery: `processor.event : "${processorEvent}"`, - transactionType: 'request', - latencyAggregationType: 'avg' as LatencyAggregationType, - sortField: 'throughput', - sortDirection: 'desc', - }, - }, - }), - ]); - - const serviceInventoryLatency = serviceInventoryAPIResponse.body.items[0].latency; - - const latencyChartApiMean = meanBy( - serviceLantencyAPIResponse.body.currentPeriod.latencyTimeseries.filter( - (item) => isFiniteNumber(item.y) && item.y > 0 - ), - 'y' - ); - - const transactionsGroupLatencySum = sumBy( - transactionsGroupDetailsAPIResponse.body.transactionGroups, - 'latency' - ); - - const serviceInstancesLatencySum = sumBy( - serviceInstancesAPIResponse.body.currentPeriod, - 'latency' - ); - - return { - serviceInventoryLatency, - latencyChartApiMean, - transactionsGroupLatencySum, - serviceInstancesLatencySum, - }; - } - - let latencyMetricValues: Awaited>; - let latencyTransactionValues: Awaited>; - - // FLAKY: https://github.com/elastic/kibana/issues/177387 - registry.when('Services APIs', { config: 'basic', archives: [] }, () => { - describe('when data is loaded ', () => { - const GO_PROD_RATE = 80; - const GO_DEV_RATE = 20; - const GO_PROD_DURATION = 1000; - const GO_DEV_DURATION = 500; - before(async () => { - const serviceGoProdInstance = apm - .service({ name: serviceName, environment: 'production', agentName: 'go' }) - .instance('instance-a'); - const serviceGoDevInstance = apm - .service({ name: serviceName, environment: 'development', agentName: 'go' }) - .instance('instance-b'); - - await apmSynthtraceEsClient.index([ - timerange(start, end) - .interval('1m') - .rate(GO_PROD_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: 'GET /api/product/list' }) - .duration(GO_PROD_DURATION) - .timestamp(timestamp) - ), - timerange(start, end) - .interval('1m') - .rate(GO_DEV_RATE) - .generator((timestamp) => - serviceGoDevInstance - .transaction({ transactionName: 'GET /api/product/:id' }) - .duration(GO_DEV_DURATION) - .timestamp(timestamp) - ), - ]); - }); - - after(() => apmSynthtraceEsClient.clean()); - - describe('compare latency value between service inventory, latency chart, service inventory and transactions apis', () => { - before(async () => { - [latencyTransactionValues, latencyMetricValues] = await Promise.all([ - getLatencyValues({ processorEvent: 'transaction' }), - getLatencyValues({ processorEvent: 'metric', useDurationSummary: true }), - ]); - }); - - it('returns same avg latency value for Transaction-based and Metric-based data', () => { - const expectedLatencyAvgValueMs = - ((GO_PROD_RATE * GO_PROD_DURATION + GO_DEV_RATE * GO_DEV_DURATION) / - (GO_PROD_RATE + GO_DEV_RATE)) * - 1000; - [ - latencyTransactionValues.latencyChartApiMean, - latencyTransactionValues.serviceInventoryLatency, - latencyMetricValues.latencyChartApiMean, - latencyMetricValues.serviceInventoryLatency, - ].forEach((value) => expect(value).to.be.equal(expectedLatencyAvgValueMs)); - }); - - it('returns same sum latency value for Transaction-based and Metric-based data', () => { - const expectedLatencySumValueMs = (GO_PROD_DURATION + GO_DEV_DURATION) * 1000; - [ - latencyTransactionValues.transactionsGroupLatencySum, - latencyTransactionValues.serviceInstancesLatencySum, - latencyMetricValues.transactionsGroupLatencySum, - latencyMetricValues.serviceInstancesLatencySum, - ].forEach((value) => expect(value).to.be.equal(expectedLatencySumValueMs)); - }); - }); - }); - }); -} diff --git a/x-pack/test/apm_api_integration/tests/latency/service_maps.spec.ts b/x-pack/test/apm_api_integration/tests/latency/service_maps.spec.ts deleted file mode 100644 index 298fde675bc4a..0000000000000 --- a/x-pack/test/apm_api_integration/tests/latency/service_maps.spec.ts +++ /dev/null @@ -1,139 +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 expect from '@kbn/expect'; -import { meanBy } from 'lodash'; -import { ApmDocumentType } from '@kbn/apm-plugin/common/document_type'; -import { RollupInterval } from '@kbn/apm-plugin/common/rollup'; -import { ProcessorEvent } from '@kbn/observability-plugin/common'; -import { FtrProviderContext } from '../../common/ftr_provider_context'; - -export default function ApiTest({ getService }: FtrProviderContext) { - const registry = getService('registry'); - const apmApiClient = getService('apmApiClient'); - const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); - - const serviceName = 'synth-go'; - 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 getLatencyValues(processorEvent: 'transaction' | 'metric') { - const commonQuery = { - start: new Date(start).toISOString(), - end: new Date(end).toISOString(), - environment: 'ENVIRONMENT_ALL', - }; - const [serviceInventoryAPIResponse, serviceMapsNodeDetails] = await Promise.all([ - apmApiClient.readUser({ - endpoint: 'GET /internal/apm/services', - params: { - query: { - ...commonQuery, - kuery: `service.name : "${serviceName}" and processor.event : "${processorEvent}"`, - probability: 1, - ...(processorEvent === ProcessorEvent.metric - ? { - documentType: ApmDocumentType.TransactionMetric, - rollupInterval: RollupInterval.OneMinute, - useDurationSummary: true, - } - : { - documentType: ApmDocumentType.TransactionEvent, - rollupInterval: RollupInterval.None, - useDurationSummary: false, - }), - }, - }, - }), - apmApiClient.readUser({ - endpoint: `GET /internal/apm/service-map/service/{serviceName}`, - params: { - path: { serviceName }, - query: commonQuery, - }, - }), - ]); - - const serviceInventoryLatency = serviceInventoryAPIResponse.body.items[0].latency; - - const serviceMapsNodeDetailsLatency = meanBy( - serviceMapsNodeDetails.body.currentPeriod.transactionStats?.latency?.timeseries, - 'y' - ); - - return { - serviceInventoryLatency, - serviceMapsNodeDetailsLatency, - }; - } - - let latencyMetricValues: Awaited>; - let latencyTransactionValues: Awaited>; - registry.when('Service Maps APIs', { config: 'trial', archives: [] }, () => { - describe('when data is loaded ', () => { - const GO_PROD_RATE = 80; - const GO_DEV_RATE = 20; - const GO_PROD_DURATION = 1000; - const GO_DEV_DURATION = 500; - before(async () => { - const serviceGoProdInstance = apm - .service({ name: serviceName, environment: 'production', agentName: 'go' }) - .instance('instance-a'); - const serviceGoDevInstance = apm - .service({ name: serviceName, environment: 'development', agentName: 'go' }) - .instance('instance-b'); - - await apmSynthtraceEsClient.index([ - timerange(start, end) - .interval('1m') - .rate(GO_PROD_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ - transactionName: 'GET /api/product/list', - transactionType: 'Worker', - }) - .duration(GO_PROD_DURATION) - .timestamp(timestamp) - ), - timerange(start, end) - .interval('1m') - .rate(GO_DEV_RATE) - .generator((timestamp) => - serviceGoDevInstance - .transaction({ transactionName: 'GET /api/product/:id' }) - .duration(GO_DEV_DURATION) - .timestamp(timestamp) - ), - ]); - }); - - after(() => apmSynthtraceEsClient.clean()); - - // FLAKY: https://github.com/elastic/kibana/issues/176976 - describe('compare latency value between service inventory and service maps', () => { - before(async () => { - [latencyTransactionValues, latencyMetricValues] = await Promise.all([ - getLatencyValues('transaction'), - getLatencyValues('metric'), - ]); - }); - - it('returns same avg latency value for Transaction-based and Metric-based data', () => { - const expectedLatencyAvgValueMs = ((GO_DEV_RATE * GO_DEV_DURATION) / GO_DEV_RATE) * 1000; - - [ - latencyTransactionValues.serviceMapsNodeDetailsLatency, - latencyTransactionValues.serviceInventoryLatency, - latencyMetricValues.serviceMapsNodeDetailsLatency, - latencyMetricValues.serviceInventoryLatency, - ].forEach((value) => expect(value).to.be.equal(expectedLatencyAvgValueMs)); - }); - }); - }); - }); -} From 2914a6ea608492152be4305851bcfd68351f65a5 Mon Sep 17 00:00:00 2001 From: iblancof Date: Tue, 12 Nov 2024 15:38:40 +0100 Subject: [PATCH 3/3] Remove dummy line break --- .../apis/observability/apm/latency/service_maps.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/service_maps.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/service_maps.spec.ts index 5edd4c76648af..fa088e4f12dc9 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/service_maps.spec.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/latency/service_maps.spec.ts @@ -86,7 +86,6 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon const GO_DEV_RATE = 20; const GO_PROD_DURATION = 1000; const GO_DEV_DURATION = 500; - before(async () => { const serviceGoProdInstance = apm .service({ name: serviceName, environment: 'production', agentName: 'go' })