From cf3bd39bcf7780d5e27fc57f34f930fa28df8b84 Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Tue, 26 Jan 2021 15:02:44 -0500 Subject: [PATCH 1/6] [APM] fixes incorrect values in service overview throughput chart --- .../plugins/apm/server/lib/services/get_throughput.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/apm/server/lib/services/get_throughput.ts b/x-pack/plugins/apm/server/lib/services/get_throughput.ts index 29071f96e3a06..bde826a568da9 100644 --- a/x-pack/plugins/apm/server/lib/services/get_throughput.ts +++ b/x-pack/plugins/apm/server/lib/services/get_throughput.ts @@ -27,12 +27,17 @@ interface Options { type ESResponse = PromiseReturnType; -function transform(response: ESResponse) { +function transform(response: ESResponse, options: Options) { + const { end, start } = options.setup; + const deltaAsMinutes = (end - start) / 1000 / 60; if (response.hits.total.value === 0) { return []; } const buckets = response.aggregations?.throughput.buckets ?? []; - return buckets.map(({ key: x, doc_count: y }) => ({ x, y })); + return buckets.map(({ key: x, doc_count: y }) => ({ + x, + y: y / deltaAsMinutes, + })); } async function fetcher({ @@ -82,6 +87,6 @@ async function fetcher({ export async function getThroughput(options: Options) { return { - throughput: transform(await fetcher(options)), + throughput: transform(await fetcher(options), options), }; } From 301801d11c98a42aa70a3fb85074ec42203c34b0 Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Tue, 26 Jan 2021 16:04:38 -0500 Subject: [PATCH 2/6] Consolidates various throughput rate calculations to one helper function --- .../apm/server/lib/helpers/get_tpm_rate.ts | 12 +++++++++ .../get_transaction_coordinates.ts | 5 ++-- .../get_service_dependencies/index.ts | 9 +++---- .../get_service_instance_transaction_stats.ts | 7 +++-- .../get_transaction_groups_for_page.ts | 5 ++-- .../merge_transaction_group_data.ts | 5 ++-- .../get_service_transaction_stats.ts | 26 +++++-------------- .../apm/server/lib/services/get_throughput.ts | 9 +++---- .../get_throughput_charts/index.ts | 6 ++--- .../get_throughput_charts/transform.ts | 8 +++--- 10 files changed, 41 insertions(+), 51 deletions(-) create mode 100644 x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts diff --git a/x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts b/x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts new file mode 100644 index 0000000000000..f0d08749c2332 --- /dev/null +++ b/x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SetupTimeRange } from './setup_request'; + +export function getTpmRate({ start, end }: SetupTimeRange, eventCount: number) { + const durationAsMinutes = (end - start) / 1000 / 60; + return eventCount / durationAsMinutes; +} diff --git a/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts b/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts index 5531944fc7180..7fa57bef83301 100644 --- a/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts +++ b/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts @@ -15,6 +15,7 @@ import { getProcessorEventForAggregatedTransactions, getTransactionDurationFieldForAggregatedTransactions, } from '../helpers/aggregated_transactions'; +import { getTpmRate } from '../helpers/get_tpm_rate'; export async function getTransactionCoordinates({ setup, @@ -63,12 +64,10 @@ export async function getTransactionCoordinates({ }, }); - const deltaAsMinutes = (end - start) / 1000 / 60; - return ( aggregations?.distribution.buckets.map((bucket) => ({ x: bucket.key, - y: bucket.count.value / deltaAsMinutes, + y: getTpmRate(setup, bucket.count.value), })) || [] ); } diff --git a/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts b/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts index 0ac881aeac00e..02a951ddbbf4b 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts @@ -13,6 +13,7 @@ import { joinByKey } from '../../../../common/utils/join_by_key'; import { Setup, SetupTimeRange } from '../../helpers/setup_request'; import { getMetrics } from './get_metrics'; import { getDestinationMap } from './get_destination_map'; +import { getTpmRate } from '../../helpers/get_tpm_rate'; export type ServiceDependencyItem = { name: string; @@ -50,8 +51,6 @@ export async function getServiceDependencies({ environment: string; numBuckets: number; }): Promise { - const { start, end } = setup; - const [allMetrics, destinationMap] = await Promise.all([ getMetrics({ setup, @@ -134,8 +133,6 @@ export async function getServiceDependencies({ } ); - const deltaAsMinutes = (end - start) / 60 / 1000; - const destMetrics = { latency: { value: @@ -150,11 +147,11 @@ export async function getServiceDependencies({ throughput: { value: mergedMetrics.value.count > 0 - ? mergedMetrics.value.count / deltaAsMinutes + ? getTpmRate(setup, mergedMetrics.value.count) : null, timeseries: mergedMetrics.timeseries.map((point) => ({ x: point.x, - y: point.count > 0 ? point.count / deltaAsMinutes : null, + y: point.count > 0 ? getTpmRate(setup, point.count) : null, })), }, errorRate: { diff --git a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts index 5880b5cbc9546..66b6f85bd54ec 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts @@ -19,6 +19,7 @@ import { getProcessorEventForAggregatedTransactions, getTransactionDurationFieldForAggregatedTransactions, } from '../../helpers/aggregated_transactions'; +import { getTpmRate } from '../../helpers/get_tpm_rate'; export async function getServiceInstanceTransactionStats({ setup, @@ -112,8 +113,6 @@ export async function getServiceInstanceTransactionStats({ }, }); - const deltaAsMinutes = (end - start) / 60 / 1000; - return ( response.aggregations?.[SERVICE_NODE_NAME].buckets.map( (serviceNodeBucket) => { @@ -135,10 +134,10 @@ export async function getServiceInstanceTransactionStats({ })), }, throughput: { - value: count.value / deltaAsMinutes, + value: getTpmRate(setup, count.value), timeseries: timeseries.buckets.map((dateBucket) => ({ x: dateBucket.key, - y: dateBucket.count.value / deltaAsMinutes, + y: getTpmRate(setup, dateBucket.count.value), })), }, latency: { diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts index ccccf946512dd..01be5ad2115b6 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts @@ -25,6 +25,7 @@ import { getLatencyAggregation, getLatencyValue, } from '../../helpers/latency_aggregation_type'; +import { getTpmRate } from '../../helpers/get_tpm_rate'; export type ServiceOverviewTransactionGroupSortField = | 'name' @@ -64,8 +65,6 @@ export async function getTransactionGroupsForPage({ transactionType: string; latencyAggregationType: LatencyAggregationType; }) { - const deltaAsMinutes = (end - start) / 1000 / 60; - const field = getTransactionDurationFieldForAggregatedTransactions( searchAggregatedTransactions ); @@ -124,7 +123,7 @@ export async function getTransactionGroupsForPage({ latencyAggregationType, aggregation: bucket.latency, }), - throughput: bucket.transaction_count.value / deltaAsMinutes, + throughput: getTpmRate({ start, end }, bucket.transaction_count.value), errorRate, }; }) ?? []; diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts index a8794e3c09a40..04b344dae3145 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts @@ -6,6 +6,7 @@ import { EVENT_OUTCOME } from '../../../../common/elasticsearch_fieldnames'; import { LatencyAggregationType } from '../../../../common/latency_aggregation_types'; +import { getTpmRate } from '../../helpers/get_tpm_rate'; import { getLatencyValue } from '../../helpers/latency_aggregation_type'; import { TransactionGroupTimeseriesData } from './get_timeseries_data_for_transaction_groups'; import { TransactionGroupWithoutTimeseriesData } from './get_transaction_groups_for_page'; @@ -25,8 +26,6 @@ export function mergeTransactionGroupData({ latencyAggregationType: LatencyAggregationType; transactionType: string; }) { - const deltaAsMinutes = (end - start) / 1000 / 60; - return transactionGroups.map((transactionGroup) => { const groupBucket = timeseriesData.find( ({ key }) => key === transactionGroup.name @@ -52,7 +51,7 @@ export function mergeTransactionGroupData({ ...acc.throughput, timeseries: acc.throughput.timeseries.concat({ x: point.key, - y: point.transaction_count.value / deltaAsMinutes, + y: getTpmRate({ start, end }, point.transaction_count.value), }), }, errorRate: { diff --git a/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts b/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts index 0ee7080dc0834..721b29a8cbd6b 100644 --- a/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts +++ b/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts @@ -22,6 +22,7 @@ import { getTransactionDurationFieldForAggregatedTransactions, } from '../../helpers/aggregated_transactions'; import { getBucketSize } from '../../helpers/get_bucket_size'; +import { getTpmRate } from '../../helpers/get_tpm_rate'; import { calculateTransactionErrorPercentage, getOutcomeAggregation, @@ -35,16 +36,6 @@ interface AggregationParams { const MAX_NUMBER_OF_SERVICES = 500; -function calculateAvgDuration({ - value, - deltaAsMinutes, -}: { - value: number; - deltaAsMinutes: number; -}) { - return value / deltaAsMinutes; -} - export async function getServiceTransactionStats({ setup, searchAggregatedTransactions, @@ -139,8 +130,6 @@ export async function getServiceTransactionStats({ }, }); - const deltaAsMinutes = (setup.end - setup.start) / 1000 / 60; - return ( response.aggregations?.services.buckets.map((bucket) => { const topTransactionTypeBucket = @@ -179,17 +168,14 @@ export async function getServiceTransactionStats({ ), }, transactionsPerMinute: { - value: calculateAvgDuration({ - value: topTransactionTypeBucket.real_document_count.value, - deltaAsMinutes, - }), + value: getTpmRate( + setup, + topTransactionTypeBucket.real_document_count.value + ), timeseries: topTransactionTypeBucket.timeseries.buckets.map( (dateBucket) => ({ x: dateBucket.key, - y: calculateAvgDuration({ - value: dateBucket.real_document_count.value, - deltaAsMinutes, - }), + y: getTpmRate(setup, dateBucket.real_document_count.value), }) ), }, diff --git a/x-pack/plugins/apm/server/lib/services/get_throughput.ts b/x-pack/plugins/apm/server/lib/services/get_throughput.ts index bde826a568da9..5ddb75fa8b431 100644 --- a/x-pack/plugins/apm/server/lib/services/get_throughput.ts +++ b/x-pack/plugins/apm/server/lib/services/get_throughput.ts @@ -16,6 +16,7 @@ import { getProcessorEventForAggregatedTransactions, } from '../helpers/aggregated_transactions'; import { getBucketSize } from '../helpers/get_bucket_size'; +import { getTpmRate } from '../helpers/get_tpm_rate'; import { Setup, SetupTimeRange } from '../helpers/setup_request'; interface Options { @@ -27,16 +28,14 @@ interface Options { type ESResponse = PromiseReturnType; -function transform(response: ESResponse, options: Options) { - const { end, start } = options.setup; - const deltaAsMinutes = (end - start) / 1000 / 60; +function transform(options: Options, response: ESResponse) { if (response.hits.total.value === 0) { return []; } const buckets = response.aggregations?.throughput.buckets ?? []; return buckets.map(({ key: x, doc_count: y }) => ({ x, - y: y / deltaAsMinutes, + y: getTpmRate(options.setup, y), })); } @@ -87,6 +86,6 @@ async function fetcher({ export async function getThroughput(options: Options) { return { - throughput: transform(await fetcher(options), options), + throughput: transform(options, await fetcher(options)), }; } diff --git a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts index be374ccfe3400..86c886ba76a54 100644 --- a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts +++ b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts @@ -106,9 +106,7 @@ export async function getThroughputCharts({ setup: Setup & SetupTimeRange; searchAggregatedTransactions: boolean; }) { - const { start, end } = setup; - const { bucketSize, intervalString } = getBucketSize({ start, end }); - const durationAsMinutes = (end - start) / 1000 / 60; + const { bucketSize, intervalString } = getBucketSize(setup); const response = await searchThroughput({ serviceName, @@ -123,7 +121,7 @@ export async function getThroughputCharts({ throughputTimeseries: getThroughputBuckets({ throughputResultBuckets: response.aggregations?.throughput.buckets, bucketSize, - durationAsMinutes, + setupTimeRange: setup, }), }; } diff --git a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts index a12e36c0e9de4..476221312120b 100644 --- a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts +++ b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts @@ -7,17 +7,19 @@ import { sortBy } from 'lodash'; import { NOT_AVAILABLE_LABEL } from '../../../../common/i18n'; import { ThroughputChartsResponse } from '.'; +import { getTpmRate } from '../../helpers/get_tpm_rate'; +import { SetupTimeRange } from '../../helpers/setup_request'; type ThroughputResultBuckets = Required['aggregations']['throughput']['buckets']; export function getThroughputBuckets({ throughputResultBuckets = [], bucketSize, - durationAsMinutes, + setupTimeRange, }: { throughputResultBuckets?: ThroughputResultBuckets; bucketSize: number; - durationAsMinutes: number; + setupTimeRange: SetupTimeRange; }) { const buckets = throughputResultBuckets.map( ({ key: resultKey, timeseries }) => { @@ -38,7 +40,7 @@ export function getThroughputBuckets({ .reduce((a, b) => a + b, 0); // calculate average throughput - const avg = docCountTotal / durationAsMinutes; + const avg = getTpmRate(setupTimeRange, docCountTotal); return { key, dataPoints, avg }; } From b3c0abcf64e90a8f2fdd2eef744154d8accb8899 Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Tue, 26 Jan 2021 23:52:01 -0500 Subject: [PATCH 3/6] PR feedback and test snapshot update --- ...et_tpm_rate.ts => calculate_throughput.ts} | 8 ++- .../get_transaction_coordinates.ts | 4 +- .../get_service_dependencies/index.ts | 14 ++++- .../get_service_instance_transaction_stats.ts | 10 +++- .../get_transaction_groups_for_page.ts | 8 ++- .../merge_transaction_group_data.ts | 8 ++- .../get_service_transaction_stats.ts | 17 ++++-- .../apm/server/lib/services/get_throughput.ts | 7 ++- .../get_throughput_charts/transform.ts | 5 +- .../services/__snapshots__/throughput.snap | 58 +++++++++---------- 10 files changed, 85 insertions(+), 54 deletions(-) rename x-pack/plugins/apm/server/lib/helpers/{get_tpm_rate.ts => calculate_throughput.ts} (71%) diff --git a/x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts b/x-pack/plugins/apm/server/lib/helpers/calculate_throughput.ts similarity index 71% rename from x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts rename to x-pack/plugins/apm/server/lib/helpers/calculate_throughput.ts index f0d08749c2332..7fcbe9e798188 100644 --- a/x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts +++ b/x-pack/plugins/apm/server/lib/helpers/calculate_throughput.ts @@ -6,7 +6,11 @@ import { SetupTimeRange } from './setup_request'; -export function getTpmRate({ start, end }: SetupTimeRange, eventCount: number) { +export function calculateThroughput({ + start, + end, + value, +}: SetupTimeRange & { value: number }) { const durationAsMinutes = (end - start) / 1000 / 60; - return eventCount / durationAsMinutes; + return value / durationAsMinutes; } diff --git a/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts b/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts index 7fa57bef83301..5b662f3a21916 100644 --- a/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts +++ b/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts @@ -15,7 +15,7 @@ import { getProcessorEventForAggregatedTransactions, getTransactionDurationFieldForAggregatedTransactions, } from '../helpers/aggregated_transactions'; -import { getTpmRate } from '../helpers/get_tpm_rate'; +import { calculateThroughput } from '../helpers/calculate_throughput'; export async function getTransactionCoordinates({ setup, @@ -67,7 +67,7 @@ export async function getTransactionCoordinates({ return ( aggregations?.distribution.buckets.map((bucket) => ({ x: bucket.key, - y: getTpmRate(setup, bucket.count.value), + y: calculateThroughput({ start, end, value: bucket.count.value }), })) || [] ); } diff --git a/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts b/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts index 02a951ddbbf4b..2b209f8f6a80a 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts @@ -13,7 +13,7 @@ import { joinByKey } from '../../../../common/utils/join_by_key'; import { Setup, SetupTimeRange } from '../../helpers/setup_request'; import { getMetrics } from './get_metrics'; import { getDestinationMap } from './get_destination_map'; -import { getTpmRate } from '../../helpers/get_tpm_rate'; +import { calculateThroughput } from '../../helpers/calculate_throughput'; export type ServiceDependencyItem = { name: string; @@ -51,6 +51,7 @@ export async function getServiceDependencies({ environment: string; numBuckets: number; }): Promise { + const { start, end } = setup; const [allMetrics, destinationMap] = await Promise.all([ getMetrics({ setup, @@ -147,11 +148,18 @@ export async function getServiceDependencies({ throughput: { value: mergedMetrics.value.count > 0 - ? getTpmRate(setup, mergedMetrics.value.count) + ? calculateThroughput({ + start, + end, + value: mergedMetrics.value.count, + }) : null, timeseries: mergedMetrics.timeseries.map((point) => ({ x: point.x, - y: point.count > 0 ? getTpmRate(setup, point.count) : null, + y: + point.count > 0 + ? calculateThroughput({ start, end, value: point.count }) + : null, })), }, errorRate: { diff --git a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts index 66b6f85bd54ec..298232f110fe7 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts @@ -19,7 +19,7 @@ import { getProcessorEventForAggregatedTransactions, getTransactionDurationFieldForAggregatedTransactions, } from '../../helpers/aggregated_transactions'; -import { getTpmRate } from '../../helpers/get_tpm_rate'; +import { calculateThroughput } from '../../helpers/calculate_throughput'; export async function getServiceInstanceTransactionStats({ setup, @@ -134,10 +134,14 @@ export async function getServiceInstanceTransactionStats({ })), }, throughput: { - value: getTpmRate(setup, count.value), + value: calculateThroughput({ start, end, value: count.value }), timeseries: timeseries.buckets.map((dateBucket) => ({ x: dateBucket.key, - y: getTpmRate(setup, dateBucket.count.value), + y: calculateThroughput({ + start, + end, + value: dateBucket.count.value, + }), })), }, latency: { diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts index 01be5ad2115b6..684eaa07691e3 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts @@ -25,7 +25,7 @@ import { getLatencyAggregation, getLatencyValue, } from '../../helpers/latency_aggregation_type'; -import { getTpmRate } from '../../helpers/get_tpm_rate'; +import { calculateThroughput } from '../../helpers/calculate_throughput'; export type ServiceOverviewTransactionGroupSortField = | 'name' @@ -123,7 +123,11 @@ export async function getTransactionGroupsForPage({ latencyAggregationType, aggregation: bucket.latency, }), - throughput: getTpmRate({ start, end }, bucket.transaction_count.value), + throughput: calculateThroughput({ + start, + end, + value: bucket.transaction_count.value, + }), errorRate, }; }) ?? []; diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts index 04b344dae3145..254de1828a93d 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts @@ -6,7 +6,7 @@ import { EVENT_OUTCOME } from '../../../../common/elasticsearch_fieldnames'; import { LatencyAggregationType } from '../../../../common/latency_aggregation_types'; -import { getTpmRate } from '../../helpers/get_tpm_rate'; +import { calculateThroughput } from '../../helpers/calculate_throughput'; import { getLatencyValue } from '../../helpers/latency_aggregation_type'; import { TransactionGroupTimeseriesData } from './get_timeseries_data_for_transaction_groups'; import { TransactionGroupWithoutTimeseriesData } from './get_transaction_groups_for_page'; @@ -51,7 +51,11 @@ export function mergeTransactionGroupData({ ...acc.throughput, timeseries: acc.throughput.timeseries.concat({ x: point.key, - y: getTpmRate({ start, end }, point.transaction_count.value), + y: calculateThroughput({ + start, + end, + value: point.transaction_count.value, + }), }), }, errorRate: { diff --git a/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts b/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts index 721b29a8cbd6b..1c3472d8bfa0e 100644 --- a/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts +++ b/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts @@ -22,7 +22,7 @@ import { getTransactionDurationFieldForAggregatedTransactions, } from '../../helpers/aggregated_transactions'; import { getBucketSize } from '../../helpers/get_bucket_size'; -import { getTpmRate } from '../../helpers/get_tpm_rate'; +import { calculateThroughput } from '../../helpers/calculate_throughput'; import { calculateTransactionErrorPercentage, getOutcomeAggregation, @@ -168,14 +168,19 @@ export async function getServiceTransactionStats({ ), }, transactionsPerMinute: { - value: getTpmRate( - setup, - topTransactionTypeBucket.real_document_count.value - ), + value: calculateThroughput({ + start, + end, + value: topTransactionTypeBucket.real_document_count.value, + }), timeseries: topTransactionTypeBucket.timeseries.buckets.map( (dateBucket) => ({ x: dateBucket.key, - y: getTpmRate(setup, dateBucket.real_document_count.value), + y: calculateThroughput({ + start, + end, + value: dateBucket.real_document_count.value, + }), }) ), }, diff --git a/x-pack/plugins/apm/server/lib/services/get_throughput.ts b/x-pack/plugins/apm/server/lib/services/get_throughput.ts index 5ddb75fa8b431..15ecc88a019db 100644 --- a/x-pack/plugins/apm/server/lib/services/get_throughput.ts +++ b/x-pack/plugins/apm/server/lib/services/get_throughput.ts @@ -16,7 +16,7 @@ import { getProcessorEventForAggregatedTransactions, } from '../helpers/aggregated_transactions'; import { getBucketSize } from '../helpers/get_bucket_size'; -import { getTpmRate } from '../helpers/get_tpm_rate'; +import { calculateThroughput } from '../helpers/calculate_throughput'; import { Setup, SetupTimeRange } from '../helpers/setup_request'; interface Options { @@ -32,10 +32,11 @@ function transform(options: Options, response: ESResponse) { if (response.hits.total.value === 0) { return []; } + const { start, end } = options.setup; const buckets = response.aggregations?.throughput.buckets ?? []; - return buckets.map(({ key: x, doc_count: y }) => ({ + return buckets.map(({ key: x, doc_count: value }) => ({ x, - y: getTpmRate(options.setup, y), + y: calculateThroughput({ start, end, value }), })); } diff --git a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts index 476221312120b..3206ce872ffb7 100644 --- a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts +++ b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts @@ -7,7 +7,7 @@ import { sortBy } from 'lodash'; import { NOT_AVAILABLE_LABEL } from '../../../../common/i18n'; import { ThroughputChartsResponse } from '.'; -import { getTpmRate } from '../../helpers/get_tpm_rate'; +import { calculateThroughput } from '../../helpers/calculate_throughput'; import { SetupTimeRange } from '../../helpers/setup_request'; type ThroughputResultBuckets = Required['aggregations']['throughput']['buckets']; @@ -21,6 +21,7 @@ export function getThroughputBuckets({ bucketSize: number; setupTimeRange: SetupTimeRange; }) { + const { start, end } = setupTimeRange; const buckets = throughputResultBuckets.map( ({ key: resultKey, timeseries }) => { const dataPoints = timeseries.buckets.map((bucket) => { @@ -40,7 +41,7 @@ export function getThroughputBuckets({ .reduce((a, b) => a + b, 0); // calculate average throughput - const avg = getTpmRate(setupTimeRange, docCountTotal); + const avg = calculateThroughput({ start, end, value: docCountTotal }); return { key, dataPoints, avg }; } diff --git a/x-pack/test/apm_api_integration/basic/tests/services/__snapshots__/throughput.snap b/x-pack/test/apm_api_integration/basic/tests/services/__snapshots__/throughput.snap index fe7f434aad2e1..a1e2268173f4e 100644 --- a/x-pack/test/apm_api_integration/basic/tests/services/__snapshots__/throughput.snap +++ b/x-pack/test/apm_api_integration/basic/tests/services/__snapshots__/throughput.snap @@ -8,7 +8,7 @@ Array [ }, Object { "x": 1607435880000, - "y": 4, + "y": 0.133333333333333, }, Object { "x": 1607435910000, @@ -16,7 +16,7 @@ Array [ }, Object { "x": 1607435940000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607435970000, @@ -24,11 +24,11 @@ Array [ }, Object { "x": 1607436000000, - "y": 3, + "y": 0.1, }, Object { "x": 1607436030000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607436060000, @@ -40,7 +40,7 @@ Array [ }, Object { "x": 1607436120000, - "y": 4, + "y": 0.133333333333333, }, Object { "x": 1607436150000, @@ -56,7 +56,7 @@ Array [ }, Object { "x": 1607436240000, - "y": 6, + "y": 0.2, }, Object { "x": 1607436270000, @@ -68,15 +68,15 @@ Array [ }, Object { "x": 1607436330000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607436360000, - "y": 5, + "y": 0.166666666666667, }, Object { "x": 1607436390000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607436420000, @@ -88,11 +88,11 @@ Array [ }, Object { "x": 1607436480000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607436510000, - "y": 5, + "y": 0.166666666666667, }, Object { "x": 1607436540000, @@ -104,11 +104,11 @@ Array [ }, Object { "x": 1607436600000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607436630000, - "y": 7, + "y": 0.233333333333333, }, Object { "x": 1607436660000, @@ -124,7 +124,7 @@ Array [ }, Object { "x": 1607436750000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607436780000, @@ -132,15 +132,15 @@ Array [ }, Object { "x": 1607436810000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607436840000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607436870000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607436900000, @@ -152,11 +152,11 @@ Array [ }, Object { "x": 1607436960000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607436990000, - "y": 4, + "y": 0.133333333333333, }, Object { "x": 1607437020000, @@ -168,11 +168,11 @@ Array [ }, Object { "x": 1607437080000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607437110000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607437140000, @@ -184,15 +184,15 @@ Array [ }, Object { "x": 1607437200000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607437230000, - "y": 7, + "y": 0.233333333333333, }, Object { "x": 1607437260000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607437290000, @@ -200,11 +200,11 @@ Array [ }, Object { "x": 1607437320000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607437350000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607437380000, @@ -216,11 +216,11 @@ Array [ }, Object { "x": 1607437440000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607437470000, - "y": 3, + "y": 0.1, }, Object { "x": 1607437500000, @@ -232,7 +232,7 @@ Array [ }, Object { "x": 1607437560000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607437590000, From b628724c2fb2542be12feadb2c690f5a5a51234b Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Wed, 27 Jan 2021 15:44:33 -0500 Subject: [PATCH 4/6] Revert "PR feedback and test snapshot update" This reverts commit b3c0abcf64e90a8f2fdd2eef744154d8accb8899. --- ...alculate_throughput.ts => get_tpm_rate.ts} | 8 +-- .../get_transaction_coordinates.ts | 4 +- .../get_service_dependencies/index.ts | 14 +---- .../get_service_instance_transaction_stats.ts | 10 +--- .../get_transaction_groups_for_page.ts | 8 +-- .../merge_transaction_group_data.ts | 8 +-- .../get_service_transaction_stats.ts | 17 ++---- .../apm/server/lib/services/get_throughput.ts | 7 +-- .../get_throughput_charts/transform.ts | 5 +- .../services/__snapshots__/throughput.snap | 58 +++++++++---------- 10 files changed, 54 insertions(+), 85 deletions(-) rename x-pack/plugins/apm/server/lib/helpers/{calculate_throughput.ts => get_tpm_rate.ts} (71%) diff --git a/x-pack/plugins/apm/server/lib/helpers/calculate_throughput.ts b/x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts similarity index 71% rename from x-pack/plugins/apm/server/lib/helpers/calculate_throughput.ts rename to x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts index 7fcbe9e798188..f0d08749c2332 100644 --- a/x-pack/plugins/apm/server/lib/helpers/calculate_throughput.ts +++ b/x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts @@ -6,11 +6,7 @@ import { SetupTimeRange } from './setup_request'; -export function calculateThroughput({ - start, - end, - value, -}: SetupTimeRange & { value: number }) { +export function getTpmRate({ start, end }: SetupTimeRange, eventCount: number) { const durationAsMinutes = (end - start) / 1000 / 60; - return value / durationAsMinutes; + return eventCount / durationAsMinutes; } diff --git a/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts b/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts index 5b662f3a21916..7fa57bef83301 100644 --- a/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts +++ b/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts @@ -15,7 +15,7 @@ import { getProcessorEventForAggregatedTransactions, getTransactionDurationFieldForAggregatedTransactions, } from '../helpers/aggregated_transactions'; -import { calculateThroughput } from '../helpers/calculate_throughput'; +import { getTpmRate } from '../helpers/get_tpm_rate'; export async function getTransactionCoordinates({ setup, @@ -67,7 +67,7 @@ export async function getTransactionCoordinates({ return ( aggregations?.distribution.buckets.map((bucket) => ({ x: bucket.key, - y: calculateThroughput({ start, end, value: bucket.count.value }), + y: getTpmRate(setup, bucket.count.value), })) || [] ); } diff --git a/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts b/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts index 2b209f8f6a80a..02a951ddbbf4b 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts @@ -13,7 +13,7 @@ import { joinByKey } from '../../../../common/utils/join_by_key'; import { Setup, SetupTimeRange } from '../../helpers/setup_request'; import { getMetrics } from './get_metrics'; import { getDestinationMap } from './get_destination_map'; -import { calculateThroughput } from '../../helpers/calculate_throughput'; +import { getTpmRate } from '../../helpers/get_tpm_rate'; export type ServiceDependencyItem = { name: string; @@ -51,7 +51,6 @@ export async function getServiceDependencies({ environment: string; numBuckets: number; }): Promise { - const { start, end } = setup; const [allMetrics, destinationMap] = await Promise.all([ getMetrics({ setup, @@ -148,18 +147,11 @@ export async function getServiceDependencies({ throughput: { value: mergedMetrics.value.count > 0 - ? calculateThroughput({ - start, - end, - value: mergedMetrics.value.count, - }) + ? getTpmRate(setup, mergedMetrics.value.count) : null, timeseries: mergedMetrics.timeseries.map((point) => ({ x: point.x, - y: - point.count > 0 - ? calculateThroughput({ start, end, value: point.count }) - : null, + y: point.count > 0 ? getTpmRate(setup, point.count) : null, })), }, errorRate: { diff --git a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts index 298232f110fe7..66b6f85bd54ec 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts @@ -19,7 +19,7 @@ import { getProcessorEventForAggregatedTransactions, getTransactionDurationFieldForAggregatedTransactions, } from '../../helpers/aggregated_transactions'; -import { calculateThroughput } from '../../helpers/calculate_throughput'; +import { getTpmRate } from '../../helpers/get_tpm_rate'; export async function getServiceInstanceTransactionStats({ setup, @@ -134,14 +134,10 @@ export async function getServiceInstanceTransactionStats({ })), }, throughput: { - value: calculateThroughput({ start, end, value: count.value }), + value: getTpmRate(setup, count.value), timeseries: timeseries.buckets.map((dateBucket) => ({ x: dateBucket.key, - y: calculateThroughput({ - start, - end, - value: dateBucket.count.value, - }), + y: getTpmRate(setup, dateBucket.count.value), })), }, latency: { diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts index 684eaa07691e3..01be5ad2115b6 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts @@ -25,7 +25,7 @@ import { getLatencyAggregation, getLatencyValue, } from '../../helpers/latency_aggregation_type'; -import { calculateThroughput } from '../../helpers/calculate_throughput'; +import { getTpmRate } from '../../helpers/get_tpm_rate'; export type ServiceOverviewTransactionGroupSortField = | 'name' @@ -123,11 +123,7 @@ export async function getTransactionGroupsForPage({ latencyAggregationType, aggregation: bucket.latency, }), - throughput: calculateThroughput({ - start, - end, - value: bucket.transaction_count.value, - }), + throughput: getTpmRate({ start, end }, bucket.transaction_count.value), errorRate, }; }) ?? []; diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts index 254de1828a93d..04b344dae3145 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts @@ -6,7 +6,7 @@ import { EVENT_OUTCOME } from '../../../../common/elasticsearch_fieldnames'; import { LatencyAggregationType } from '../../../../common/latency_aggregation_types'; -import { calculateThroughput } from '../../helpers/calculate_throughput'; +import { getTpmRate } from '../../helpers/get_tpm_rate'; import { getLatencyValue } from '../../helpers/latency_aggregation_type'; import { TransactionGroupTimeseriesData } from './get_timeseries_data_for_transaction_groups'; import { TransactionGroupWithoutTimeseriesData } from './get_transaction_groups_for_page'; @@ -51,11 +51,7 @@ export function mergeTransactionGroupData({ ...acc.throughput, timeseries: acc.throughput.timeseries.concat({ x: point.key, - y: calculateThroughput({ - start, - end, - value: point.transaction_count.value, - }), + y: getTpmRate({ start, end }, point.transaction_count.value), }), }, errorRate: { diff --git a/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts b/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts index 1c3472d8bfa0e..721b29a8cbd6b 100644 --- a/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts +++ b/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts @@ -22,7 +22,7 @@ import { getTransactionDurationFieldForAggregatedTransactions, } from '../../helpers/aggregated_transactions'; import { getBucketSize } from '../../helpers/get_bucket_size'; -import { calculateThroughput } from '../../helpers/calculate_throughput'; +import { getTpmRate } from '../../helpers/get_tpm_rate'; import { calculateTransactionErrorPercentage, getOutcomeAggregation, @@ -168,19 +168,14 @@ export async function getServiceTransactionStats({ ), }, transactionsPerMinute: { - value: calculateThroughput({ - start, - end, - value: topTransactionTypeBucket.real_document_count.value, - }), + value: getTpmRate( + setup, + topTransactionTypeBucket.real_document_count.value + ), timeseries: topTransactionTypeBucket.timeseries.buckets.map( (dateBucket) => ({ x: dateBucket.key, - y: calculateThroughput({ - start, - end, - value: dateBucket.real_document_count.value, - }), + y: getTpmRate(setup, dateBucket.real_document_count.value), }) ), }, diff --git a/x-pack/plugins/apm/server/lib/services/get_throughput.ts b/x-pack/plugins/apm/server/lib/services/get_throughput.ts index 15ecc88a019db..5ddb75fa8b431 100644 --- a/x-pack/plugins/apm/server/lib/services/get_throughput.ts +++ b/x-pack/plugins/apm/server/lib/services/get_throughput.ts @@ -16,7 +16,7 @@ import { getProcessorEventForAggregatedTransactions, } from '../helpers/aggregated_transactions'; import { getBucketSize } from '../helpers/get_bucket_size'; -import { calculateThroughput } from '../helpers/calculate_throughput'; +import { getTpmRate } from '../helpers/get_tpm_rate'; import { Setup, SetupTimeRange } from '../helpers/setup_request'; interface Options { @@ -32,11 +32,10 @@ function transform(options: Options, response: ESResponse) { if (response.hits.total.value === 0) { return []; } - const { start, end } = options.setup; const buckets = response.aggregations?.throughput.buckets ?? []; - return buckets.map(({ key: x, doc_count: value }) => ({ + return buckets.map(({ key: x, doc_count: y }) => ({ x, - y: calculateThroughput({ start, end, value }), + y: getTpmRate(options.setup, y), })); } diff --git a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts index 3206ce872ffb7..476221312120b 100644 --- a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts +++ b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts @@ -7,7 +7,7 @@ import { sortBy } from 'lodash'; import { NOT_AVAILABLE_LABEL } from '../../../../common/i18n'; import { ThroughputChartsResponse } from '.'; -import { calculateThroughput } from '../../helpers/calculate_throughput'; +import { getTpmRate } from '../../helpers/get_tpm_rate'; import { SetupTimeRange } from '../../helpers/setup_request'; type ThroughputResultBuckets = Required['aggregations']['throughput']['buckets']; @@ -21,7 +21,6 @@ export function getThroughputBuckets({ bucketSize: number; setupTimeRange: SetupTimeRange; }) { - const { start, end } = setupTimeRange; const buckets = throughputResultBuckets.map( ({ key: resultKey, timeseries }) => { const dataPoints = timeseries.buckets.map((bucket) => { @@ -41,7 +40,7 @@ export function getThroughputBuckets({ .reduce((a, b) => a + b, 0); // calculate average throughput - const avg = calculateThroughput({ start, end, value: docCountTotal }); + const avg = getTpmRate(setupTimeRange, docCountTotal); return { key, dataPoints, avg }; } diff --git a/x-pack/test/apm_api_integration/basic/tests/services/__snapshots__/throughput.snap b/x-pack/test/apm_api_integration/basic/tests/services/__snapshots__/throughput.snap index a1e2268173f4e..fe7f434aad2e1 100644 --- a/x-pack/test/apm_api_integration/basic/tests/services/__snapshots__/throughput.snap +++ b/x-pack/test/apm_api_integration/basic/tests/services/__snapshots__/throughput.snap @@ -8,7 +8,7 @@ Array [ }, Object { "x": 1607435880000, - "y": 0.133333333333333, + "y": 4, }, Object { "x": 1607435910000, @@ -16,7 +16,7 @@ Array [ }, Object { "x": 1607435940000, - "y": 0.0666666666666667, + "y": 2, }, Object { "x": 1607435970000, @@ -24,11 +24,11 @@ Array [ }, Object { "x": 1607436000000, - "y": 0.1, + "y": 3, }, Object { "x": 1607436030000, - "y": 0.0333333333333333, + "y": 1, }, Object { "x": 1607436060000, @@ -40,7 +40,7 @@ Array [ }, Object { "x": 1607436120000, - "y": 0.133333333333333, + "y": 4, }, Object { "x": 1607436150000, @@ -56,7 +56,7 @@ Array [ }, Object { "x": 1607436240000, - "y": 0.2, + "y": 6, }, Object { "x": 1607436270000, @@ -68,15 +68,15 @@ Array [ }, Object { "x": 1607436330000, - "y": 0.0333333333333333, + "y": 1, }, Object { "x": 1607436360000, - "y": 0.166666666666667, + "y": 5, }, Object { "x": 1607436390000, - "y": 0.0333333333333333, + "y": 1, }, Object { "x": 1607436420000, @@ -88,11 +88,11 @@ Array [ }, Object { "x": 1607436480000, - "y": 0.0666666666666667, + "y": 2, }, Object { "x": 1607436510000, - "y": 0.166666666666667, + "y": 5, }, Object { "x": 1607436540000, @@ -104,11 +104,11 @@ Array [ }, Object { "x": 1607436600000, - "y": 0.0666666666666667, + "y": 2, }, Object { "x": 1607436630000, - "y": 0.233333333333333, + "y": 7, }, Object { "x": 1607436660000, @@ -124,7 +124,7 @@ Array [ }, Object { "x": 1607436750000, - "y": 0.0666666666666667, + "y": 2, }, Object { "x": 1607436780000, @@ -132,15 +132,15 @@ Array [ }, Object { "x": 1607436810000, - "y": 0.0333333333333333, + "y": 1, }, Object { "x": 1607436840000, - "y": 0.0333333333333333, + "y": 1, }, Object { "x": 1607436870000, - "y": 0.0666666666666667, + "y": 2, }, Object { "x": 1607436900000, @@ -152,11 +152,11 @@ Array [ }, Object { "x": 1607436960000, - "y": 0.0666666666666667, + "y": 2, }, Object { "x": 1607436990000, - "y": 0.133333333333333, + "y": 4, }, Object { "x": 1607437020000, @@ -168,11 +168,11 @@ Array [ }, Object { "x": 1607437080000, - "y": 0.0333333333333333, + "y": 1, }, Object { "x": 1607437110000, - "y": 0.0333333333333333, + "y": 1, }, Object { "x": 1607437140000, @@ -184,15 +184,15 @@ Array [ }, Object { "x": 1607437200000, - "y": 0.0666666666666667, + "y": 2, }, Object { "x": 1607437230000, - "y": 0.233333333333333, + "y": 7, }, Object { "x": 1607437260000, - "y": 0.0333333333333333, + "y": 1, }, Object { "x": 1607437290000, @@ -200,11 +200,11 @@ Array [ }, Object { "x": 1607437320000, - "y": 0.0333333333333333, + "y": 1, }, Object { "x": 1607437350000, - "y": 0.0666666666666667, + "y": 2, }, Object { "x": 1607437380000, @@ -216,11 +216,11 @@ Array [ }, Object { "x": 1607437440000, - "y": 0.0333333333333333, + "y": 1, }, Object { "x": 1607437470000, - "y": 0.1, + "y": 3, }, Object { "x": 1607437500000, @@ -232,7 +232,7 @@ Array [ }, Object { "x": 1607437560000, - "y": 0.0333333333333333, + "y": 1, }, Object { "x": 1607437590000, From 534efb2d13a43918482166c49338687cf78cc777 Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Wed, 27 Jan 2021 15:44:49 -0500 Subject: [PATCH 5/6] Revert "Consolidates various throughput rate calculations to one helper function" This reverts commit 301801d11c98a42aa70a3fb85074ec42203c34b0. --- .../apm/server/lib/helpers/get_tpm_rate.ts | 12 --------- .../get_transaction_coordinates.ts | 5 ++-- .../get_service_dependencies/index.ts | 9 ++++--- .../get_service_instance_transaction_stats.ts | 7 ++--- .../get_transaction_groups_for_page.ts | 5 ++-- .../merge_transaction_group_data.ts | 5 ++-- .../get_service_transaction_stats.ts | 26 ++++++++++++++----- .../apm/server/lib/services/get_throughput.ts | 9 ++++--- .../get_throughput_charts/index.ts | 6 +++-- .../get_throughput_charts/transform.ts | 8 +++--- 10 files changed, 51 insertions(+), 41 deletions(-) delete mode 100644 x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts diff --git a/x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts b/x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts deleted file mode 100644 index f0d08749c2332..0000000000000 --- a/x-pack/plugins/apm/server/lib/helpers/get_tpm_rate.ts +++ /dev/null @@ -1,12 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -import { SetupTimeRange } from './setup_request'; - -export function getTpmRate({ start, end }: SetupTimeRange, eventCount: number) { - const durationAsMinutes = (end - start) / 1000 / 60; - return eventCount / durationAsMinutes; -} diff --git a/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts b/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts index 7fa57bef83301..5531944fc7180 100644 --- a/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts +++ b/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts @@ -15,7 +15,6 @@ import { getProcessorEventForAggregatedTransactions, getTransactionDurationFieldForAggregatedTransactions, } from '../helpers/aggregated_transactions'; -import { getTpmRate } from '../helpers/get_tpm_rate'; export async function getTransactionCoordinates({ setup, @@ -64,10 +63,12 @@ export async function getTransactionCoordinates({ }, }); + const deltaAsMinutes = (end - start) / 1000 / 60; + return ( aggregations?.distribution.buckets.map((bucket) => ({ x: bucket.key, - y: getTpmRate(setup, bucket.count.value), + y: bucket.count.value / deltaAsMinutes, })) || [] ); } diff --git a/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts b/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts index 02a951ddbbf4b..0ac881aeac00e 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts @@ -13,7 +13,6 @@ import { joinByKey } from '../../../../common/utils/join_by_key'; import { Setup, SetupTimeRange } from '../../helpers/setup_request'; import { getMetrics } from './get_metrics'; import { getDestinationMap } from './get_destination_map'; -import { getTpmRate } from '../../helpers/get_tpm_rate'; export type ServiceDependencyItem = { name: string; @@ -51,6 +50,8 @@ export async function getServiceDependencies({ environment: string; numBuckets: number; }): Promise { + const { start, end } = setup; + const [allMetrics, destinationMap] = await Promise.all([ getMetrics({ setup, @@ -133,6 +134,8 @@ export async function getServiceDependencies({ } ); + const deltaAsMinutes = (end - start) / 60 / 1000; + const destMetrics = { latency: { value: @@ -147,11 +150,11 @@ export async function getServiceDependencies({ throughput: { value: mergedMetrics.value.count > 0 - ? getTpmRate(setup, mergedMetrics.value.count) + ? mergedMetrics.value.count / deltaAsMinutes : null, timeseries: mergedMetrics.timeseries.map((point) => ({ x: point.x, - y: point.count > 0 ? getTpmRate(setup, point.count) : null, + y: point.count > 0 ? point.count / deltaAsMinutes : null, })), }, errorRate: { diff --git a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts index 66b6f85bd54ec..5880b5cbc9546 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts @@ -19,7 +19,6 @@ import { getProcessorEventForAggregatedTransactions, getTransactionDurationFieldForAggregatedTransactions, } from '../../helpers/aggregated_transactions'; -import { getTpmRate } from '../../helpers/get_tpm_rate'; export async function getServiceInstanceTransactionStats({ setup, @@ -113,6 +112,8 @@ export async function getServiceInstanceTransactionStats({ }, }); + const deltaAsMinutes = (end - start) / 60 / 1000; + return ( response.aggregations?.[SERVICE_NODE_NAME].buckets.map( (serviceNodeBucket) => { @@ -134,10 +135,10 @@ export async function getServiceInstanceTransactionStats({ })), }, throughput: { - value: getTpmRate(setup, count.value), + value: count.value / deltaAsMinutes, timeseries: timeseries.buckets.map((dateBucket) => ({ x: dateBucket.key, - y: getTpmRate(setup, dateBucket.count.value), + y: dateBucket.count.value / deltaAsMinutes, })), }, latency: { diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts index 01be5ad2115b6..ccccf946512dd 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts @@ -25,7 +25,6 @@ import { getLatencyAggregation, getLatencyValue, } from '../../helpers/latency_aggregation_type'; -import { getTpmRate } from '../../helpers/get_tpm_rate'; export type ServiceOverviewTransactionGroupSortField = | 'name' @@ -65,6 +64,8 @@ export async function getTransactionGroupsForPage({ transactionType: string; latencyAggregationType: LatencyAggregationType; }) { + const deltaAsMinutes = (end - start) / 1000 / 60; + const field = getTransactionDurationFieldForAggregatedTransactions( searchAggregatedTransactions ); @@ -123,7 +124,7 @@ export async function getTransactionGroupsForPage({ latencyAggregationType, aggregation: bucket.latency, }), - throughput: getTpmRate({ start, end }, bucket.transaction_count.value), + throughput: bucket.transaction_count.value / deltaAsMinutes, errorRate, }; }) ?? []; diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts index 04b344dae3145..a8794e3c09a40 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts @@ -6,7 +6,6 @@ import { EVENT_OUTCOME } from '../../../../common/elasticsearch_fieldnames'; import { LatencyAggregationType } from '../../../../common/latency_aggregation_types'; -import { getTpmRate } from '../../helpers/get_tpm_rate'; import { getLatencyValue } from '../../helpers/latency_aggregation_type'; import { TransactionGroupTimeseriesData } from './get_timeseries_data_for_transaction_groups'; import { TransactionGroupWithoutTimeseriesData } from './get_transaction_groups_for_page'; @@ -26,6 +25,8 @@ export function mergeTransactionGroupData({ latencyAggregationType: LatencyAggregationType; transactionType: string; }) { + const deltaAsMinutes = (end - start) / 1000 / 60; + return transactionGroups.map((transactionGroup) => { const groupBucket = timeseriesData.find( ({ key }) => key === transactionGroup.name @@ -51,7 +52,7 @@ export function mergeTransactionGroupData({ ...acc.throughput, timeseries: acc.throughput.timeseries.concat({ x: point.key, - y: getTpmRate({ start, end }, point.transaction_count.value), + y: point.transaction_count.value / deltaAsMinutes, }), }, errorRate: { diff --git a/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts b/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts index 721b29a8cbd6b..0ee7080dc0834 100644 --- a/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts +++ b/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts @@ -22,7 +22,6 @@ import { getTransactionDurationFieldForAggregatedTransactions, } from '../../helpers/aggregated_transactions'; import { getBucketSize } from '../../helpers/get_bucket_size'; -import { getTpmRate } from '../../helpers/get_tpm_rate'; import { calculateTransactionErrorPercentage, getOutcomeAggregation, @@ -36,6 +35,16 @@ interface AggregationParams { const MAX_NUMBER_OF_SERVICES = 500; +function calculateAvgDuration({ + value, + deltaAsMinutes, +}: { + value: number; + deltaAsMinutes: number; +}) { + return value / deltaAsMinutes; +} + export async function getServiceTransactionStats({ setup, searchAggregatedTransactions, @@ -130,6 +139,8 @@ export async function getServiceTransactionStats({ }, }); + const deltaAsMinutes = (setup.end - setup.start) / 1000 / 60; + return ( response.aggregations?.services.buckets.map((bucket) => { const topTransactionTypeBucket = @@ -168,14 +179,17 @@ export async function getServiceTransactionStats({ ), }, transactionsPerMinute: { - value: getTpmRate( - setup, - topTransactionTypeBucket.real_document_count.value - ), + value: calculateAvgDuration({ + value: topTransactionTypeBucket.real_document_count.value, + deltaAsMinutes, + }), timeseries: topTransactionTypeBucket.timeseries.buckets.map( (dateBucket) => ({ x: dateBucket.key, - y: getTpmRate(setup, dateBucket.real_document_count.value), + y: calculateAvgDuration({ + value: dateBucket.real_document_count.value, + deltaAsMinutes, + }), }) ), }, diff --git a/x-pack/plugins/apm/server/lib/services/get_throughput.ts b/x-pack/plugins/apm/server/lib/services/get_throughput.ts index 5ddb75fa8b431..bde826a568da9 100644 --- a/x-pack/plugins/apm/server/lib/services/get_throughput.ts +++ b/x-pack/plugins/apm/server/lib/services/get_throughput.ts @@ -16,7 +16,6 @@ import { getProcessorEventForAggregatedTransactions, } from '../helpers/aggregated_transactions'; import { getBucketSize } from '../helpers/get_bucket_size'; -import { getTpmRate } from '../helpers/get_tpm_rate'; import { Setup, SetupTimeRange } from '../helpers/setup_request'; interface Options { @@ -28,14 +27,16 @@ interface Options { type ESResponse = PromiseReturnType; -function transform(options: Options, response: ESResponse) { +function transform(response: ESResponse, options: Options) { + const { end, start } = options.setup; + const deltaAsMinutes = (end - start) / 1000 / 60; if (response.hits.total.value === 0) { return []; } const buckets = response.aggregations?.throughput.buckets ?? []; return buckets.map(({ key: x, doc_count: y }) => ({ x, - y: getTpmRate(options.setup, y), + y: y / deltaAsMinutes, })); } @@ -86,6 +87,6 @@ async function fetcher({ export async function getThroughput(options: Options) { return { - throughput: transform(options, await fetcher(options)), + throughput: transform(await fetcher(options), options), }; } diff --git a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts index 86c886ba76a54..be374ccfe3400 100644 --- a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts +++ b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts @@ -106,7 +106,9 @@ export async function getThroughputCharts({ setup: Setup & SetupTimeRange; searchAggregatedTransactions: boolean; }) { - const { bucketSize, intervalString } = getBucketSize(setup); + const { start, end } = setup; + const { bucketSize, intervalString } = getBucketSize({ start, end }); + const durationAsMinutes = (end - start) / 1000 / 60; const response = await searchThroughput({ serviceName, @@ -121,7 +123,7 @@ export async function getThroughputCharts({ throughputTimeseries: getThroughputBuckets({ throughputResultBuckets: response.aggregations?.throughput.buckets, bucketSize, - setupTimeRange: setup, + durationAsMinutes, }), }; } diff --git a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts index 476221312120b..a12e36c0e9de4 100644 --- a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts +++ b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts @@ -7,19 +7,17 @@ import { sortBy } from 'lodash'; import { NOT_AVAILABLE_LABEL } from '../../../../common/i18n'; import { ThroughputChartsResponse } from '.'; -import { getTpmRate } from '../../helpers/get_tpm_rate'; -import { SetupTimeRange } from '../../helpers/setup_request'; type ThroughputResultBuckets = Required['aggregations']['throughput']['buckets']; export function getThroughputBuckets({ throughputResultBuckets = [], bucketSize, - setupTimeRange, + durationAsMinutes, }: { throughputResultBuckets?: ThroughputResultBuckets; bucketSize: number; - setupTimeRange: SetupTimeRange; + durationAsMinutes: number; }) { const buckets = throughputResultBuckets.map( ({ key: resultKey, timeseries }) => { @@ -40,7 +38,7 @@ export function getThroughputBuckets({ .reduce((a, b) => a + b, 0); // calculate average throughput - const avg = getTpmRate(setupTimeRange, docCountTotal); + const avg = docCountTotal / durationAsMinutes; return { key, dataPoints, avg }; } From df0db70f2563f93a0d1addd7db14594175625d5a Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Thu, 28 Jan 2021 15:09:52 -0500 Subject: [PATCH 6/6] update api integration snapshot --- .../services/__snapshots__/throughput.snap | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/x-pack/test/apm_api_integration/tests/services/__snapshots__/throughput.snap b/x-pack/test/apm_api_integration/tests/services/__snapshots__/throughput.snap index f23601fccb174..eee0ec7f9ad38 100644 --- a/x-pack/test/apm_api_integration/tests/services/__snapshots__/throughput.snap +++ b/x-pack/test/apm_api_integration/tests/services/__snapshots__/throughput.snap @@ -8,7 +8,7 @@ Array [ }, Object { "x": 1607435880000, - "y": 4, + "y": 0.133333333333333, }, Object { "x": 1607435910000, @@ -16,7 +16,7 @@ Array [ }, Object { "x": 1607435940000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607435970000, @@ -24,11 +24,11 @@ Array [ }, Object { "x": 1607436000000, - "y": 3, + "y": 0.1, }, Object { "x": 1607436030000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607436060000, @@ -40,7 +40,7 @@ Array [ }, Object { "x": 1607436120000, - "y": 4, + "y": 0.133333333333333, }, Object { "x": 1607436150000, @@ -56,7 +56,7 @@ Array [ }, Object { "x": 1607436240000, - "y": 6, + "y": 0.2, }, Object { "x": 1607436270000, @@ -68,15 +68,15 @@ Array [ }, Object { "x": 1607436330000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607436360000, - "y": 5, + "y": 0.166666666666667, }, Object { "x": 1607436390000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607436420000, @@ -88,11 +88,11 @@ Array [ }, Object { "x": 1607436480000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607436510000, - "y": 5, + "y": 0.166666666666667, }, Object { "x": 1607436540000, @@ -104,11 +104,11 @@ Array [ }, Object { "x": 1607436600000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607436630000, - "y": 7, + "y": 0.233333333333333, }, Object { "x": 1607436660000, @@ -124,7 +124,7 @@ Array [ }, Object { "x": 1607436750000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607436780000, @@ -132,15 +132,15 @@ Array [ }, Object { "x": 1607436810000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607436840000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607436870000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607436900000, @@ -152,11 +152,11 @@ Array [ }, Object { "x": 1607436960000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607436990000, - "y": 4, + "y": 0.133333333333333, }, Object { "x": 1607437020000, @@ -168,11 +168,11 @@ Array [ }, Object { "x": 1607437080000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607437110000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607437140000, @@ -184,15 +184,15 @@ Array [ }, Object { "x": 1607437200000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607437230000, - "y": 7, + "y": 0.233333333333333, }, Object { "x": 1607437260000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607437290000, @@ -200,11 +200,11 @@ Array [ }, Object { "x": 1607437320000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607437350000, - "y": 2, + "y": 0.0666666666666667, }, Object { "x": 1607437380000, @@ -216,11 +216,11 @@ Array [ }, Object { "x": 1607437440000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607437470000, - "y": 3, + "y": 0.1, }, Object { "x": 1607437500000, @@ -232,7 +232,7 @@ Array [ }, Object { "x": 1607437560000, - "y": 1, + "y": 0.0333333333333333, }, Object { "x": 1607437590000,