Skip to content

Commit

Permalink
fixing rate aggregation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Sep 15, 2021
1 parent b11f6c8 commit 5d0d418
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)' }
)
: ''}
</h2>
</EuiTitle>
</EuiFlexItem>

<EuiFlexItem grow={false}>
<EuiIconTip
content={
data.throughputUnit === 'minute'
? i18n.translate('xpack.apm.serviceOverview.tpmHelp', {
defaultMessage:
'Throughput is measured in transactions per minute (tpm)',
})
: i18n.translate('xpack.apm.serviceOverview.tpsHelp', {
defaultMessage:
'Throughput is measured in transactions per second (tps)',
})
}
position="right"
/>
</EuiFlexItem>
</EuiFlexGroup>

<TimeseriesChart
Expand All @@ -157,7 +128,7 @@ export function ServiceOverviewThroughputChart({
showAnnotations={false}
fetchStatus={status}
timeseries={timeseries}
yLabelFormat={(y) => asExactTransactionRate(y, data.throughputUnit)}
yLabelFormat={asTransactionRate}
customTheme={comparisonChartTheme}
/>
</EuiPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -64,14 +62,6 @@ export async function getThroughputChartsForBackend({
end: endWithOffset,
metricsInterval: 60,
}),
aggs: {
throughput: {
rate: {
field: SPAN_DESTINATION_SERVICE_RESPONSE_TIME_COUNT,
unit: 'minute',
},
},
},
},
},
},
Expand All @@ -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 }),
};
}) ?? []
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ export async function getTransactionsPerMinute({
fixed_interval: bucketSize,
min_doc_count: 0,
},
aggs: {
throughput: { rate: { unit: 'minute' as const } },
},
},
},
},
Expand Down Expand Up @@ -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 }),
})) || [],
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -125,11 +126,6 @@ export async function getServiceTransactionGroupDetailedStatistics({
},
},
aggs: {
throughput_rate: {
rate: {
unit: 'minute',
},
},
...getLatencyAggregation(latencyAggregationType, field),
[EVENT_OUTCOME]: {
terms: {
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 6 additions & 10 deletions x-pack/plugins/apm/server/lib/services/get_throughput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +29,6 @@ interface Options {
start: number;
end: number;
intervalString: string;
throughputUnit: 'minute' | 'second';
}

export async function getThroughput({
Expand All @@ -41,7 +41,6 @@ export async function getThroughput({
start,
end,
intervalString,
throughputUnit,
}: Options) {
const { apmEventClient } = setup;

Expand Down Expand Up @@ -75,13 +74,6 @@ export async function getThroughput({
min_doc_count: 0,
extended_bounds: { min: start, max: end },
},
aggs: {
throughput: {
rate: {
unit: throughputUnit,
},
},
},
},
},
},
Expand All @@ -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,
}),
};
}) ?? []
);
Expand Down
10 changes: 1 addition & 9 deletions x-pack/plugins/apm/server/routes/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -475,25 +474,19 @@ 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,
searchAggregatedTransactions,
serviceName,
setup,
transactionType,
throughputUnit,
intervalString,
};

Expand All @@ -518,7 +511,6 @@ const serviceThroughputRoute = createApmServerRoute({
currentPeriodTimeseries: currentPeriod,
previousPeriodTimeseries: previousPeriod,
}),
throughputUnit,
};
},
});
Expand Down

0 comments on commit 5d0d418

Please sign in to comment.