From d7cb37102883e5a0d1935361f2e20e15ef4c47a5 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Tue, 30 Jun 2020 17:37:07 +0200 Subject: [PATCH 1/4] changing transaction count to transaction rate per second --- .../apm/public/services/rest/observability.dashboard.test.ts | 2 +- .../apm/public/services/rest/observability_dashboard.ts | 5 +++-- .../observability_dashboard/get_transaction_coordinates.ts | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/apm/public/services/rest/observability.dashboard.test.ts b/x-pack/plugins/apm/public/services/rest/observability.dashboard.test.ts index 1ee8d79ee99a5..f991acde2a892 100644 --- a/x-pack/plugins/apm/public/services/rest/observability.dashboard.test.ts +++ b/x-pack/plugins/apm/public/services/rest/observability.dashboard.test.ts @@ -60,7 +60,7 @@ describe('Observability dashboard data', () => { transactions: { type: 'number', label: 'Transactions', - value: 6, + value: 2, color: '#6092c0', }, }, diff --git a/x-pack/plugins/apm/public/services/rest/observability_dashboard.ts b/x-pack/plugins/apm/public/services/rest/observability_dashboard.ts index 2221904932b63..7a5711edd3462 100644 --- a/x-pack/plugins/apm/public/services/rest/observability_dashboard.ts +++ b/x-pack/plugins/apm/public/services/rest/observability_dashboard.ts @@ -5,7 +5,7 @@ */ import { i18n } from '@kbn/i18n'; -import { sum } from 'lodash'; +import mean from 'lodash.mean'; // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { FetchDataParams } from '../../../../observability/public/data_handler'; import { ApmFetchDataResponse } from '../../../../observability/public/typings/fetch_data_response'; @@ -47,7 +47,8 @@ export const fetchLandingPageData = async ( 'xpack.apm.observabilityDashboard.stats.transactions', { defaultMessage: 'Transactions' } ), - value: sum(transactionCoordinates.map((coordinates) => coordinates.y)), + value: + mean(transactionCoordinates.map((coordinates) => coordinates.y)) || 0, color: theme.euiColorVis1, }, }, diff --git a/x-pack/plugins/apm/server/lib/observability_dashboard/get_transaction_coordinates.ts b/x-pack/plugins/apm/server/lib/observability_dashboard/get_transaction_coordinates.ts index 78ed11d839ad2..f0f1c900e6d7f 100644 --- a/x-pack/plugins/apm/server/lib/observability_dashboard/get_transaction_coordinates.ts +++ b/x-pack/plugins/apm/server/lib/observability_dashboard/get_transaction_coordinates.ts @@ -48,10 +48,12 @@ export async function getTransactionCoordinates({ }, }); + const deltaAsMinutes = (end - start) / 1000 / 60; + return ( aggregations?.distribution.buckets.map((bucket) => ({ x: bucket.key, - y: bucket.doc_count, + y: bucket.doc_count / deltaAsMinutes, })) || [] ); } From ffedc7f65c3498ac75dcde83c2d04ef1fd635765 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Wed, 1 Jul 2020 10:34:54 +0200 Subject: [PATCH 2/4] sanity check coordinates before calculate the mean --- .../rest/observability.dashboard.test.ts | 40 +++++++++++++++++++ .../services/rest/observability_dashboard.ts | 7 +++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/apm/public/services/rest/observability.dashboard.test.ts b/x-pack/plugins/apm/public/services/rest/observability.dashboard.test.ts index f991acde2a892..bf2476935dc51 100644 --- a/x-pack/plugins/apm/public/services/rest/observability.dashboard.test.ts +++ b/x-pack/plugins/apm/public/services/rest/observability.dashboard.test.ts @@ -117,5 +117,45 @@ describe('Observability dashboard data', () => { }, }); }); + it('returns transaction stat as 0 when y is undefined', async () => { + callApmApiMock.mockImplementation(() => + Promise.resolve({ + serviceCount: 0, + transactionCoordinates: [{ x: 1 }, { x: 2 }, { x: 3 }], + }) + ); + const response = await fetchLandingPageData( + { + startTime: '1', + endTime: '2', + bucketSize: '3', + }, + { theme } + ); + expect(response).toEqual({ + title: 'APM', + appLink: '/app/apm', + stats: { + services: { + type: 'number', + label: 'Services', + value: 0, + }, + transactions: { + type: 'number', + label: 'Transactions', + value: 0, + color: '#6092c0', + }, + }, + series: { + transactions: { + label: 'Transactions', + coordinates: [{ x: 1 }, { x: 2 }, { x: 3 }], + color: '#6092c0', + }, + }, + }); + }); }); }); diff --git a/x-pack/plugins/apm/public/services/rest/observability_dashboard.ts b/x-pack/plugins/apm/public/services/rest/observability_dashboard.ts index 7a5711edd3462..f2aeb03f4f51a 100644 --- a/x-pack/plugins/apm/public/services/rest/observability_dashboard.ts +++ b/x-pack/plugins/apm/public/services/rest/observability_dashboard.ts @@ -47,8 +47,11 @@ export const fetchLandingPageData = async ( 'xpack.apm.observabilityDashboard.stats.transactions', { defaultMessage: 'Transactions' } ), - value: - mean(transactionCoordinates.map((coordinates) => coordinates.y)) || 0, + value: !!transactionCoordinates.length + ? mean( + transactionCoordinates.map((coordinates) => coordinates.y || 0) + ) + : 0, color: theme.euiColorVis1, }, }, From 764d74b1c18fcae482e7cc067d02aa6772c76d86 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Wed, 1 Jul 2020 13:03:45 +0200 Subject: [PATCH 3/4] sanity check coordinates before calculate the mean --- .../public/services/rest/observability_dashboard.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/apm/public/services/rest/observability_dashboard.ts b/x-pack/plugins/apm/public/services/rest/observability_dashboard.ts index f2aeb03f4f51a..9f6fca1a48c27 100644 --- a/x-pack/plugins/apm/public/services/rest/observability_dashboard.ts +++ b/x-pack/plugins/apm/public/services/rest/observability_dashboard.ts @@ -47,11 +47,12 @@ export const fetchLandingPageData = async ( 'xpack.apm.observabilityDashboard.stats.transactions', { defaultMessage: 'Transactions' } ), - value: !!transactionCoordinates.length - ? mean( - transactionCoordinates.map((coordinates) => coordinates.y || 0) - ) - : 0, + value: + mean( + transactionCoordinates + .map(({ y }) => y) + .filter((y) => y && isFinite(y)) + ) || 0, color: theme.euiColorVis1, }, }, From 9ee655487c59959da0850c4864e680527b6c6401 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Wed, 1 Jul 2020 17:42:16 +0200 Subject: [PATCH 4/4] removing extend_bounds to return empty when no data is available --- .../lib/observability_dashboard/get_transaction_coordinates.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/apm/server/lib/observability_dashboard/get_transaction_coordinates.ts b/x-pack/plugins/apm/server/lib/observability_dashboard/get_transaction_coordinates.ts index bbba5f6821714..0d1a4274c16dc 100644 --- a/x-pack/plugins/apm/server/lib/observability_dashboard/get_transaction_coordinates.ts +++ b/x-pack/plugins/apm/server/lib/observability_dashboard/get_transaction_coordinates.ts @@ -41,7 +41,6 @@ export async function getTransactionCoordinates({ field: '@timestamp', fixed_interval: bucketSize, min_doc_count: 0, - extended_bounds: { min: start, max: end }, }, }, },