From fffa198521d8d49ec35dc155459b78772a40c14e Mon Sep 17 00:00:00 2001 From: "miriam.aparicio" Date: Mon, 11 Nov 2024 16:28:30 +0000 Subject: [PATCH 1/2] Migrate error_rate tests to agnostic deployment tests --- .../observability/apm/error_rate/index.ts | 15 ++ .../apm}/error_rate/service_apis.spec.ts | 184 +++++++++--------- .../apm/error_rate/service_maps.spec.ts | 165 ++++++++++++++++ .../apis/observability/apm/index.ts | 1 + .../tests/error_rate/service_maps.spec.ts | 163 ---------------- 5 files changed, 274 insertions(+), 254 deletions(-) create mode 100644 x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/index.ts rename x-pack/test/{apm_api_integration/tests => api_integration/deployment_agnostic/apis/observability/apm}/error_rate/service_apis.spec.ts (57%) create mode 100644 x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_maps.spec.ts delete mode 100644 x-pack/test/apm_api_integration/tests/error_rate/service_maps.spec.ts diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/index.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/index.ts new file mode 100644 index 0000000000000..a3dd89f0ddb1a --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/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('error_rate', () => { + loadTestFile(require.resolve('./service_apis.spec.ts')); + loadTestFile(require.resolve('./service_maps.spec.ts')); + }); +} diff --git a/x-pack/test/apm_api_integration/tests/error_rate/service_apis.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_apis.spec.ts similarity index 57% rename from x-pack/test/apm_api_integration/tests/error_rate/service_apis.spec.ts rename to x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_apis.spec.ts index 2ab6b1bb97a5e..4db7224418b8b 100644 --- a/x-pack/test/apm_api_integration/tests/error_rate/service_apis.spec.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_apis.spec.ts @@ -5,6 +5,7 @@ * 2.0. */ import { apm, timerange } from '@kbn/apm-synthtrace-client'; +import type { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; import expect from '@kbn/expect'; import { mean, meanBy, sumBy } from 'lodash'; import { LatencyAggregationType } from '@kbn/apm-plugin/common/latency_aggregation_types'; @@ -12,12 +13,16 @@ 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'; +import { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; -export default function ApiTest({ getService }: FtrProviderContext) { - const registry = getService('registry'); - const apmApiClient = getService('apmApiClient'); - const apmSynthtraceEsClient = getService('apmSynthtraceEsClient'); +const GO_PROD_LIST_RATE = 75; +const GO_PROD_LIST_ERROR_RATE = 25; +const GO_PROD_ID_RATE = 50; +const GO_PROD_ID_ERROR_RATE = 50; + +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(); @@ -151,96 +156,93 @@ export default function ApiTest({ getService }: FtrProviderContext) { let errorRateMetricValues: Awaited>; let errorTransactionValues: Awaited>; - // FLAKY: https://github.com/elastic/kibana/issues/177321 - registry.when('Services APIs', { config: 'basic', archives: [] }, () => { - describe('when data is loaded ', () => { - const GO_PROD_LIST_RATE = 75; - const GO_PROD_LIST_ERROR_RATE = 25; - const GO_PROD_ID_RATE = 50; - const GO_PROD_ID_ERROR_RATE = 50; + describe('when data is loaded ', () => { + let apmSynthtraceEsClient: ApmSynthtraceEsClient; + + before(async () => { + const serviceGoProdInstance = apm + .service({ name: serviceName, environment: 'production', agentName: 'go' }) + .instance('instance-a'); + + const transactionNameProductList = 'GET /api/product/list'; + const transactionNameProductId = 'GET /api/product/:id'; + + apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); + + await apmSynthtraceEsClient.index([ + timerange(start, end) + .interval('1m') + .rate(GO_PROD_LIST_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: transactionNameProductList }) + .timestamp(timestamp) + .duration(1000) + .success() + ), + timerange(start, end) + .interval('1m') + .rate(GO_PROD_LIST_ERROR_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: transactionNameProductList }) + .duration(1000) + .timestamp(timestamp) + .failure() + ), + timerange(start, end) + .interval('1m') + .rate(GO_PROD_ID_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: transactionNameProductId }) + .timestamp(timestamp) + .duration(1000) + .success() + ), + timerange(start, end) + .interval('1m') + .rate(GO_PROD_ID_ERROR_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: transactionNameProductId }) + .duration(1000) + .timestamp(timestamp) + .failure() + ), + ]); + }); + + after(() => apmSynthtraceEsClient.clean()); + + describe('compare error rate value between service inventory, error rate chart, service inventory and transactions apis', () => { before(async () => { - const serviceGoProdInstance = apm - .service({ name: serviceName, environment: 'production', agentName: 'go' }) - .instance('instance-a'); - - const transactionNameProductList = 'GET /api/product/list'; - const transactionNameProductId = 'GET /api/product/:id'; - - await apmSynthtraceEsClient.index([ - timerange(start, end) - .interval('1m') - .rate(GO_PROD_LIST_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: transactionNameProductList }) - .timestamp(timestamp) - .duration(1000) - .success() - ), - timerange(start, end) - .interval('1m') - .rate(GO_PROD_LIST_ERROR_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: transactionNameProductList }) - .duration(1000) - .timestamp(timestamp) - .failure() - ), - timerange(start, end) - .interval('1m') - .rate(GO_PROD_ID_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: transactionNameProductId }) - .timestamp(timestamp) - .duration(1000) - .success() - ), - timerange(start, end) - .interval('1m') - .rate(GO_PROD_ID_ERROR_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: transactionNameProductId }) - .duration(1000) - .timestamp(timestamp) - .failure() - ), + [errorTransactionValues, errorRateMetricValues] = await Promise.all([ + getErrorRateValues({ processorEvent: 'transaction' }), + getErrorRateValues({ processorEvent: 'metric' }), ]); }); - after(() => apmSynthtraceEsClient.clean()); - - describe('compare error rate value between service inventory, error rate chart, service inventory and transactions apis', () => { - before(async () => { - [errorTransactionValues, errorRateMetricValues] = await Promise.all([ - getErrorRateValues({ processorEvent: 'transaction' }), - getErrorRateValues({ processorEvent: 'metric' }), - ]); - }); - - it('returns same avg error rate value for Transaction-based and Metric-based data', () => { - [ - errorTransactionValues.serviceInventoryErrorRate, - errorTransactionValues.errorRateChartApiMean, - errorTransactionValues.serviceInstancesErrorRateSum, - errorRateMetricValues.serviceInventoryErrorRate, - errorRateMetricValues.errorRateChartApiMean, - errorRateMetricValues.serviceInstancesErrorRateSum, - ].forEach((value) => - expect(value).to.be.equal(mean([GO_PROD_LIST_ERROR_RATE, GO_PROD_ID_ERROR_RATE]) / 100) - ); - }); - - it('returns same sum error rate value for Transaction-based and Metric-based data', () => { - [ - errorTransactionValues.transactionsGroupErrorRateSum, - errorRateMetricValues.transactionsGroupErrorRateSum, - ].forEach((value) => - expect(value).to.be.equal((GO_PROD_LIST_ERROR_RATE + GO_PROD_ID_ERROR_RATE) / 100) - ); - }); + it('returns same avg error rate value for Transaction-based and Metric-based data', () => { + [ + errorTransactionValues.serviceInventoryErrorRate, + errorTransactionValues.errorRateChartApiMean, + errorTransactionValues.serviceInstancesErrorRateSum, + errorRateMetricValues.serviceInventoryErrorRate, + errorRateMetricValues.errorRateChartApiMean, + errorRateMetricValues.serviceInstancesErrorRateSum, + ].forEach((value) => + expect(value).to.be.equal(mean([GO_PROD_LIST_ERROR_RATE, GO_PROD_ID_ERROR_RATE]) / 100) + ); + }); + + it('returns same sum error rate value for Transaction-based and Metric-based data', () => { + [ + errorTransactionValues.transactionsGroupErrorRateSum, + errorRateMetricValues.transactionsGroupErrorRateSum, + ].forEach((value) => + expect(value).to.be.equal((GO_PROD_LIST_ERROR_RATE + GO_PROD_ID_ERROR_RATE) / 100) + ); }); }); }); diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_maps.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_maps.spec.ts new file mode 100644 index 0000000000000..579abd2d368a3 --- /dev/null +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_maps.spec.ts @@ -0,0 +1,165 @@ +/* + * 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 { ApmSynthtraceEsClient } from '@kbn/apm-synthtrace'; +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 { DeploymentAgnosticFtrProviderContext } from '../../../../ftr_provider_context'; + +const GO_PROD_LIST_RATE = 75; +const GO_PROD_LIST_ERROR_RATE = 25; +const GO_PROD_ID_RATE = 50; +const GO_PROD_ID_ERROR_RATE = 50; + +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 getErrorRateValues(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 serviceInventoryErrorRate = + serviceInventoryAPIResponse.body.items[0].transactionErrorRate; + + const serviceMapsNodeDetailsErrorRate = meanBy( + serviceMapsNodeDetails.body.currentPeriod.failedTransactionsRate?.timeseries, + 'y' + ); + + return { + serviceInventoryErrorRate, + serviceMapsNodeDetailsErrorRate, + }; + } + + let errorRateMetricValues: Awaited>; + let errorTransactionValues: Awaited>; + + describe('when data is loaded ', () => { + let apmSynthtraceEsClient: ApmSynthtraceEsClient; + before(async () => { + const serviceGoProdInstance = apm + .service({ name: serviceName, environment: 'production', agentName: 'go' }) + .instance('instance-a'); + + const transactionNameProductList = 'GET /api/product/list'; + const transactionNameProductId = 'GET /api/product/:id'; + + apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); + + return apmSynthtraceEsClient.index([ + timerange(start, end) + .interval('1m') + .rate(GO_PROD_LIST_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ + transactionName: transactionNameProductList, + transactionType: 'Worker', + }) + .timestamp(timestamp) + .duration(1000) + .success() + ), + timerange(start, end) + .interval('1m') + .rate(GO_PROD_LIST_ERROR_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ + transactionName: transactionNameProductList, + transactionType: 'Worker', + }) + .duration(1000) + .timestamp(timestamp) + .failure() + ), + timerange(start, end) + .interval('1m') + .rate(GO_PROD_ID_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: transactionNameProductId }) + .timestamp(timestamp) + .duration(1000) + .success() + ), + timerange(start, end) + .interval('1m') + .rate(GO_PROD_ID_ERROR_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: transactionNameProductId }) + .duration(1000) + .timestamp(timestamp) + .failure() + ), + ]); + }); + + after(() => apmSynthtraceEsClient.clean()); + + describe('compare latency value between service inventory and service maps', () => { + before(async () => { + [errorTransactionValues, errorRateMetricValues] = await Promise.all([ + getErrorRateValues('transaction'), + getErrorRateValues('metric'), + ]); + }); + + it('returns same avg error rate value for Transaction-based and Metric-based data', () => { + [ + errorTransactionValues.serviceInventoryErrorRate, + errorTransactionValues.serviceMapsNodeDetailsErrorRate, + errorRateMetricValues.serviceInventoryErrorRate, + errorRateMetricValues.serviceMapsNodeDetailsErrorRate, + ].forEach((value) => expect(value).to.be.equal(GO_PROD_ID_ERROR_RATE / 100)); + }); + }); + }); +} 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 abc7f72945e2e..7cc9ef6e1dff0 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 @@ -14,5 +14,6 @@ export default function apmApiIntegrationTests({ loadTestFile(require.resolve('./agent_explorer')); loadTestFile(require.resolve('./custom_dashboards')); loadTestFile(require.resolve('./dependencies')); + loadTestFile(require.resolve('./error_rate')); }); } diff --git a/x-pack/test/apm_api_integration/tests/error_rate/service_maps.spec.ts b/x-pack/test/apm_api_integration/tests/error_rate/service_maps.spec.ts deleted file mode 100644 index aa7d635b977cc..0000000000000 --- a/x-pack/test/apm_api_integration/tests/error_rate/service_maps.spec.ts +++ /dev/null @@ -1,163 +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 getErrorRateValues(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 serviceInventoryErrorRate = - serviceInventoryAPIResponse.body.items[0].transactionErrorRate; - - const serviceMapsNodeDetailsErrorRate = meanBy( - serviceMapsNodeDetails.body.currentPeriod.failedTransactionsRate?.timeseries, - 'y' - ); - - return { - serviceInventoryErrorRate, - serviceMapsNodeDetailsErrorRate, - }; - } - - let errorRateMetricValues: Awaited>; - let errorTransactionValues: Awaited>; - registry.when('Service Maps APIs', { config: 'trial', archives: [] }, () => { - describe('when data is loaded ', () => { - const GO_PROD_LIST_RATE = 75; - const GO_PROD_LIST_ERROR_RATE = 25; - const GO_PROD_ID_RATE = 50; - const GO_PROD_ID_ERROR_RATE = 50; - before(() => { - const serviceGoProdInstance = apm - .service({ name: serviceName, environment: 'production', agentName: 'go' }) - .instance('instance-a'); - - const transactionNameProductList = 'GET /api/product/list'; - const transactionNameProductId = 'GET /api/product/:id'; - - return apmSynthtraceEsClient.index([ - timerange(start, end) - .interval('1m') - .rate(GO_PROD_LIST_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ - transactionName: transactionNameProductList, - transactionType: 'Worker', - }) - .timestamp(timestamp) - .duration(1000) - .success() - ), - timerange(start, end) - .interval('1m') - .rate(GO_PROD_LIST_ERROR_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ - transactionName: transactionNameProductList, - transactionType: 'Worker', - }) - .duration(1000) - .timestamp(timestamp) - .failure() - ), - timerange(start, end) - .interval('1m') - .rate(GO_PROD_ID_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: transactionNameProductId }) - .timestamp(timestamp) - .duration(1000) - .success() - ), - timerange(start, end) - .interval('1m') - .rate(GO_PROD_ID_ERROR_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: transactionNameProductId }) - .duration(1000) - .timestamp(timestamp) - .failure() - ), - ]); - }); - - after(() => apmSynthtraceEsClient.clean()); - - // FLAKY: https://github.com/elastic/kibana/issues/172772 - describe('compare latency value between service inventory and service maps', () => { - before(async () => { - [errorTransactionValues, errorRateMetricValues] = await Promise.all([ - getErrorRateValues('transaction'), - getErrorRateValues('metric'), - ]); - }); - - it('returns same avg error rate value for Transaction-based and Metric-based data', () => { - [ - errorTransactionValues.serviceInventoryErrorRate, - errorTransactionValues.serviceMapsNodeDetailsErrorRate, - errorRateMetricValues.serviceInventoryErrorRate, - errorRateMetricValues.serviceMapsNodeDetailsErrorRate, - ].forEach((value) => expect(value).to.be.equal(GO_PROD_ID_ERROR_RATE / 100)); - }); - }); - }); - }); -} From 5d30c37988c6b7055048618443d6669b303e51d0 Mon Sep 17 00:00:00 2001 From: "miriam.aparicio" Date: Mon, 11 Nov 2024 16:49:46 +0000 Subject: [PATCH 2/2] add higher describe --- .../apm/error_rate/service_apis.spec.ts | 166 +++++++++--------- .../apm/error_rate/service_maps.spec.ts | 148 ++++++++-------- 2 files changed, 159 insertions(+), 155 deletions(-) diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_apis.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_apis.spec.ts index 4db7224418b8b..56dded824a32d 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_apis.spec.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_apis.spec.ts @@ -156,93 +156,95 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon let errorRateMetricValues: Awaited>; let errorTransactionValues: Awaited>; - describe('when data is loaded ', () => { - let apmSynthtraceEsClient: ApmSynthtraceEsClient; - - before(async () => { - const serviceGoProdInstance = apm - .service({ name: serviceName, environment: 'production', agentName: 'go' }) - .instance('instance-a'); - - const transactionNameProductList = 'GET /api/product/list'; - const transactionNameProductId = 'GET /api/product/:id'; - - apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); - - await apmSynthtraceEsClient.index([ - timerange(start, end) - .interval('1m') - .rate(GO_PROD_LIST_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: transactionNameProductList }) - .timestamp(timestamp) - .duration(1000) - .success() - ), - timerange(start, end) - .interval('1m') - .rate(GO_PROD_LIST_ERROR_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: transactionNameProductList }) - .duration(1000) - .timestamp(timestamp) - .failure() - ), - timerange(start, end) - .interval('1m') - .rate(GO_PROD_ID_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: transactionNameProductId }) - .timestamp(timestamp) - .duration(1000) - .success() - ), - timerange(start, end) - .interval('1m') - .rate(GO_PROD_ID_ERROR_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: transactionNameProductId }) - .duration(1000) - .timestamp(timestamp) - .failure() - ), - ]); - }); - - after(() => apmSynthtraceEsClient.clean()); + describe('Services APIs', () => { + describe('when data is loaded ', () => { + let apmSynthtraceEsClient: ApmSynthtraceEsClient; - describe('compare error rate value between service inventory, error rate chart, service inventory and transactions apis', () => { before(async () => { - [errorTransactionValues, errorRateMetricValues] = await Promise.all([ - getErrorRateValues({ processorEvent: 'transaction' }), - getErrorRateValues({ processorEvent: 'metric' }), + const serviceGoProdInstance = apm + .service({ name: serviceName, environment: 'production', agentName: 'go' }) + .instance('instance-a'); + + const transactionNameProductList = 'GET /api/product/list'; + const transactionNameProductId = 'GET /api/product/:id'; + + apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); + + await apmSynthtraceEsClient.index([ + timerange(start, end) + .interval('1m') + .rate(GO_PROD_LIST_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: transactionNameProductList }) + .timestamp(timestamp) + .duration(1000) + .success() + ), + timerange(start, end) + .interval('1m') + .rate(GO_PROD_LIST_ERROR_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: transactionNameProductList }) + .duration(1000) + .timestamp(timestamp) + .failure() + ), + timerange(start, end) + .interval('1m') + .rate(GO_PROD_ID_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: transactionNameProductId }) + .timestamp(timestamp) + .duration(1000) + .success() + ), + timerange(start, end) + .interval('1m') + .rate(GO_PROD_ID_ERROR_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: transactionNameProductId }) + .duration(1000) + .timestamp(timestamp) + .failure() + ), ]); }); - it('returns same avg error rate value for Transaction-based and Metric-based data', () => { - [ - errorTransactionValues.serviceInventoryErrorRate, - errorTransactionValues.errorRateChartApiMean, - errorTransactionValues.serviceInstancesErrorRateSum, - errorRateMetricValues.serviceInventoryErrorRate, - errorRateMetricValues.errorRateChartApiMean, - errorRateMetricValues.serviceInstancesErrorRateSum, - ].forEach((value) => - expect(value).to.be.equal(mean([GO_PROD_LIST_ERROR_RATE, GO_PROD_ID_ERROR_RATE]) / 100) - ); - }); - - it('returns same sum error rate value for Transaction-based and Metric-based data', () => { - [ - errorTransactionValues.transactionsGroupErrorRateSum, - errorRateMetricValues.transactionsGroupErrorRateSum, - ].forEach((value) => - expect(value).to.be.equal((GO_PROD_LIST_ERROR_RATE + GO_PROD_ID_ERROR_RATE) / 100) - ); + after(() => apmSynthtraceEsClient.clean()); + + describe('compare error rate value between service inventory, error rate chart, service inventory and transactions apis', () => { + before(async () => { + [errorTransactionValues, errorRateMetricValues] = await Promise.all([ + getErrorRateValues({ processorEvent: 'transaction' }), + getErrorRateValues({ processorEvent: 'metric' }), + ]); + }); + + it('returns same avg error rate value for Transaction-based and Metric-based data', () => { + [ + errorTransactionValues.serviceInventoryErrorRate, + errorTransactionValues.errorRateChartApiMean, + errorTransactionValues.serviceInstancesErrorRateSum, + errorRateMetricValues.serviceInventoryErrorRate, + errorRateMetricValues.errorRateChartApiMean, + errorRateMetricValues.serviceInstancesErrorRateSum, + ].forEach((value) => + expect(value).to.be.equal(mean([GO_PROD_LIST_ERROR_RATE, GO_PROD_ID_ERROR_RATE]) / 100) + ); + }); + + it('returns same sum error rate value for Transaction-based and Metric-based data', () => { + [ + errorTransactionValues.transactionsGroupErrorRateSum, + errorRateMetricValues.transactionsGroupErrorRateSum, + ].forEach((value) => + expect(value).to.be.equal((GO_PROD_LIST_ERROR_RATE + GO_PROD_ID_ERROR_RATE) / 100) + ); + }); }); }); }); diff --git a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_maps.spec.ts b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_maps.spec.ts index 579abd2d368a3..462ad8db4bdda 100644 --- a/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_maps.spec.ts +++ b/x-pack/test/api_integration/deployment_agnostic/apis/observability/apm/error_rate/service_maps.spec.ts @@ -80,85 +80,87 @@ export default function ApiTest({ getService }: DeploymentAgnosticFtrProviderCon let errorRateMetricValues: Awaited>; let errorTransactionValues: Awaited>; - describe('when data is loaded ', () => { - let apmSynthtraceEsClient: ApmSynthtraceEsClient; - before(async () => { - const serviceGoProdInstance = apm - .service({ name: serviceName, environment: 'production', agentName: 'go' }) - .instance('instance-a'); - - const transactionNameProductList = 'GET /api/product/list'; - const transactionNameProductId = 'GET /api/product/:id'; - - apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); + describe('Service Maps APIs', () => { + describe('when data is loaded ', () => { + let apmSynthtraceEsClient: ApmSynthtraceEsClient; + before(async () => { + const serviceGoProdInstance = apm + .service({ name: serviceName, environment: 'production', agentName: 'go' }) + .instance('instance-a'); - return apmSynthtraceEsClient.index([ - timerange(start, end) - .interval('1m') - .rate(GO_PROD_LIST_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ - transactionName: transactionNameProductList, - transactionType: 'Worker', - }) - .timestamp(timestamp) - .duration(1000) - .success() - ), - timerange(start, end) - .interval('1m') - .rate(GO_PROD_LIST_ERROR_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ - transactionName: transactionNameProductList, - transactionType: 'Worker', - }) - .duration(1000) - .timestamp(timestamp) - .failure() - ), - timerange(start, end) - .interval('1m') - .rate(GO_PROD_ID_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: transactionNameProductId }) - .timestamp(timestamp) - .duration(1000) - .success() - ), - timerange(start, end) - .interval('1m') - .rate(GO_PROD_ID_ERROR_RATE) - .generator((timestamp) => - serviceGoProdInstance - .transaction({ transactionName: transactionNameProductId }) - .duration(1000) - .timestamp(timestamp) - .failure() - ), - ]); - }); + const transactionNameProductList = 'GET /api/product/list'; + const transactionNameProductId = 'GET /api/product/:id'; - after(() => apmSynthtraceEsClient.clean()); + apmSynthtraceEsClient = await synthtrace.createApmSynthtraceEsClient(); - describe('compare latency value between service inventory and service maps', () => { - before(async () => { - [errorTransactionValues, errorRateMetricValues] = await Promise.all([ - getErrorRateValues('transaction'), - getErrorRateValues('metric'), + return apmSynthtraceEsClient.index([ + timerange(start, end) + .interval('1m') + .rate(GO_PROD_LIST_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ + transactionName: transactionNameProductList, + transactionType: 'Worker', + }) + .timestamp(timestamp) + .duration(1000) + .success() + ), + timerange(start, end) + .interval('1m') + .rate(GO_PROD_LIST_ERROR_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ + transactionName: transactionNameProductList, + transactionType: 'Worker', + }) + .duration(1000) + .timestamp(timestamp) + .failure() + ), + timerange(start, end) + .interval('1m') + .rate(GO_PROD_ID_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: transactionNameProductId }) + .timestamp(timestamp) + .duration(1000) + .success() + ), + timerange(start, end) + .interval('1m') + .rate(GO_PROD_ID_ERROR_RATE) + .generator((timestamp) => + serviceGoProdInstance + .transaction({ transactionName: transactionNameProductId }) + .duration(1000) + .timestamp(timestamp) + .failure() + ), ]); }); - it('returns same avg error rate value for Transaction-based and Metric-based data', () => { - [ - errorTransactionValues.serviceInventoryErrorRate, - errorTransactionValues.serviceMapsNodeDetailsErrorRate, - errorRateMetricValues.serviceInventoryErrorRate, - errorRateMetricValues.serviceMapsNodeDetailsErrorRate, - ].forEach((value) => expect(value).to.be.equal(GO_PROD_ID_ERROR_RATE / 100)); + after(() => apmSynthtraceEsClient.clean()); + + describe('compare latency value between service inventory and service maps', () => { + before(async () => { + [errorTransactionValues, errorRateMetricValues] = await Promise.all([ + getErrorRateValues('transaction'), + getErrorRateValues('metric'), + ]); + }); + + it('returns same avg error rate value for Transaction-based and Metric-based data', () => { + [ + errorTransactionValues.serviceInventoryErrorRate, + errorTransactionValues.serviceMapsNodeDetailsErrorRate, + errorRateMetricValues.serviceInventoryErrorRate, + errorRateMetricValues.serviceMapsNodeDetailsErrorRate, + ].forEach((value) => expect(value).to.be.equal(GO_PROD_ID_ERROR_RATE / 100)); + }); }); }); });