From 5d0d418e62839676a5e90727b72ea299854b2358 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Wed, 15 Sep 2021 15:25:57 -0400 Subject: [PATCH] fixing rate aggregation bug --- .../service_overview_throughput_chart.tsx | 35 ++----------------- .../get_throughput_charts_for_backend.ts | 16 ++------- .../get_transactions_per_minute.ts | 5 +-- ...e_transaction_group_detailed_statistics.ts | 8 ++--- .../apm/server/lib/services/get_throughput.ts | 16 ++++----- x-pack/plugins/apm/server/routes/services.ts | 10 +----- 6 files changed, 16 insertions(+), 74 deletions(-) diff --git a/x-pack/plugins/apm/public/components/app/service_overview/service_overview_throughput_chart.tsx b/x-pack/plugins/apm/public/components/app/service_overview/service_overview_throughput_chart.tsx index 718d6878c7c99..00aad114c9452 100644 --- a/x-pack/plugins/apm/public/components/app/service_overview/service_overview_throughput_chart.tsx +++ b/x-pack/plugins/apm/public/components/app/service_overview/service_overview_throughput_chart.tsx @@ -5,21 +5,15 @@ * 2.0. */ -import { - EuiPanel, - EuiTitle, - EuiIconTip, - EuiFlexItem, - EuiFlexGroup, -} from '@elastic/eui'; +import { EuiPanel, EuiTitle, EuiFlexItem, EuiFlexGroup } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React from 'react'; -import { asExactTransactionRate } from '../../../../common/utils/formatters'; import { useApmServiceContext } from '../../../context/apm_service/use_apm_service_context'; import { useUrlParams } from '../../../context/url_params_context/use_url_params'; import { useFetcher } from '../../../hooks/use_fetcher'; import { useTheme } from '../../../hooks/use_theme'; import { TimeseriesChart } from '../../shared/charts/timeseries_chart'; +import { asTransactionRate } from '../../../../common/utils/formatters'; import { getComparisonChartTheme, getTimeRangeComparison, @@ -123,32 +117,9 @@ export function ServiceOverviewThroughputChart({ 'xpack.apm.serviceOverview.throughtputChartTitle', { defaultMessage: 'Throughput' } )} - {data.throughputUnit === 'second' - ? i18n.translate( - 'xpack.apm.serviceOverview.throughtputPerSecondChartTitle', - { defaultMessage: ' (per second)' } - ) - : ''} - - - - asExactTransactionRate(y, data.throughputUnit)} + yLabelFormat={asTransactionRate} customTheme={comparisonChartTheme} /> diff --git a/x-pack/plugins/apm/server/lib/backends/get_throughput_charts_for_backend.ts b/x-pack/plugins/apm/server/lib/backends/get_throughput_charts_for_backend.ts index 19a26c3fcf035..19a8742bbe1a5 100644 --- a/x-pack/plugins/apm/server/lib/backends/get_throughput_charts_for_backend.ts +++ b/x-pack/plugins/apm/server/lib/backends/get_throughput_charts_for_backend.ts @@ -5,16 +5,14 @@ * 2.0. */ -import { - SPAN_DESTINATION_SERVICE_RESOURCE, - SPAN_DESTINATION_SERVICE_RESPONSE_TIME_COUNT, -} from '../../../common/elasticsearch_fieldnames'; +import { SPAN_DESTINATION_SERVICE_RESOURCE } from '../../../common/elasticsearch_fieldnames'; import { environmentQuery } from '../../../common/utils/environment_query'; import { kqlQuery, rangeQuery } from '../../../../observability/server'; import { ProcessorEvent } from '../../../common/processor_event'; import { Setup } from '../helpers/setup_request'; import { getMetricsDateHistogramParams } from '../helpers/metrics'; import { getOffsetInMs } from '../../../common/utils/get_offset_in_ms'; +import { calculateThroughput } from '../helpers/calculate_throughput'; export async function getThroughputChartsForBackend({ backendName, @@ -64,14 +62,6 @@ export async function getThroughputChartsForBackend({ end: endWithOffset, metricsInterval: 60, }), - aggs: { - throughput: { - rate: { - field: SPAN_DESTINATION_SERVICE_RESPONSE_TIME_COUNT, - unit: 'minute', - }, - }, - }, }, }, }, @@ -81,7 +71,7 @@ export async function getThroughputChartsForBackend({ response.aggregations?.timeseries.buckets.map((bucket) => { return { x: bucket.key + offsetInMs, - y: bucket.throughput.value, + y: calculateThroughput({ start, end, value: bucket.doc_count }), }; }) ?? [] ); diff --git a/x-pack/plugins/apm/server/lib/observability_overview/get_transactions_per_minute.ts b/x-pack/plugins/apm/server/lib/observability_overview/get_transactions_per_minute.ts index 90cef471c38af..a59ba26673379 100644 --- a/x-pack/plugins/apm/server/lib/observability_overview/get_transactions_per_minute.ts +++ b/x-pack/plugins/apm/server/lib/observability_overview/get_transactions_per_minute.ts @@ -63,9 +63,6 @@ export async function getTransactionsPerMinute({ fixed_interval: bucketSize, min_doc_count: 0, }, - aggs: { - throughput: { rate: { unit: 'minute' as const } }, - }, }, }, }, @@ -94,7 +91,7 @@ export async function getTransactionsPerMinute({ timeseries: topTransactionTypeBucket?.timeseries.buckets.map((bucket) => ({ x: bucket.key, - y: bucket.throughput.value, + y: calculateThroughput({ start, end, value: bucket.doc_count }), })) || [], }; } diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_group_detailed_statistics.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_group_detailed_statistics.ts index d8a28a127499f..cdbb258f572da 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_group_detailed_statistics.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_group_detailed_statistics.ts @@ -30,6 +30,7 @@ import { } from '../helpers/latency_aggregation_type'; import { Setup, SetupTimeRange } from '../helpers/setup_request'; import { calculateFailedTransactionRate } from '../helpers/transaction_error_rate'; +import { calculateThroughput } from '../helpers/calculate_throughput'; export async function getServiceTransactionGroupDetailedStatistics({ environment, @@ -125,11 +126,6 @@ export async function getServiceTransactionGroupDetailedStatistics({ }, }, aggs: { - throughput_rate: { - rate: { - unit: 'minute', - }, - }, ...getLatencyAggregation(latencyAggregationType, field), [EVENT_OUTCOME]: { terms: { @@ -160,7 +156,7 @@ export async function getServiceTransactionGroupDetailedStatistics({ })); const throughput = bucket.timeseries.buckets.map((timeseriesBucket) => ({ x: timeseriesBucket.key, - y: timeseriesBucket.throughput_rate.value, + y: calculateThroughput({ start, end, value: timeseriesBucket.doc_count }), })); const errorRate = bucket.timeseries.buckets.map((timeseriesBucket) => ({ x: timeseriesBucket.key, 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 e866918fc29bb..5db12d9c3d3e7 100644 --- a/x-pack/plugins/apm/server/lib/services/get_throughput.ts +++ b/x-pack/plugins/apm/server/lib/services/get_throughput.ts @@ -17,6 +17,7 @@ import { getProcessorEventForAggregatedTransactions, } from '../helpers/aggregated_transactions'; import { Setup } from '../helpers/setup_request'; +import { calculateThroughput } from '../helpers/calculate_throughput'; interface Options { environment: string; @@ -28,7 +29,6 @@ interface Options { start: number; end: number; intervalString: string; - throughputUnit: 'minute' | 'second'; } export async function getThroughput({ @@ -41,7 +41,6 @@ export async function getThroughput({ start, end, intervalString, - throughputUnit, }: Options) { const { apmEventClient } = setup; @@ -75,13 +74,6 @@ export async function getThroughput({ min_doc_count: 0, extended_bounds: { min: start, max: end }, }, - aggs: { - throughput: { - rate: { - unit: throughputUnit, - }, - }, - }, }, }, }, @@ -96,7 +88,11 @@ export async function getThroughput({ response.aggregations?.timeseries.buckets.map((bucket) => { return { x: bucket.key, - y: bucket.throughput.value, + y: calculateThroughput({ + start, + end, + value: bucket.doc_count, + }), }; }) ?? [] ); diff --git a/x-pack/plugins/apm/server/routes/services.ts b/x-pack/plugins/apm/server/routes/services.ts index 32a7dcefb5cc8..fcf7156d35df6 100644 --- a/x-pack/plugins/apm/server/routes/services.ts +++ b/x-pack/plugins/apm/server/routes/services.ts @@ -12,7 +12,6 @@ import { uniq } from 'lodash'; import { latencyAggregationTypeRt } from '../../common/latency_aggregation_types'; import { ProfilingValueType } from '../../common/profiling'; import { getSearchAggregatedTransactions } from '../lib/helpers/aggregated_transactions'; -import { getThroughputUnit } from '../lib/helpers/calculate_throughput'; import { setupRequest } from '../lib/helpers/setup_request'; import { getServiceAnnotations } from '../lib/services/annotations'; import { getServices } from '../lib/services/get_services'; @@ -475,17 +474,12 @@ const serviceThroughputRoute = createApmServerRoute({ }); const { start, end } = setup; - const { - bucketSize, - intervalString, - } = getBucketSizeForAggregatedTransactions({ + const { intervalString } = getBucketSizeForAggregatedTransactions({ start, end, searchAggregatedTransactions, }); - const throughputUnit = getThroughputUnit(bucketSize); - const commonProps = { environment, kuery, @@ -493,7 +487,6 @@ const serviceThroughputRoute = createApmServerRoute({ serviceName, setup, transactionType, - throughputUnit, intervalString, }; @@ -518,7 +511,6 @@ const serviceThroughputRoute = createApmServerRoute({ currentPeriodTimeseries: currentPeriod, previousPeriodTimeseries: previousPeriod, }), - throughputUnit, }; }, });