Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OBS]home page is showing incorrect value of APM throughput (tpm) #95991

Merged
merged 6 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/

import { mean } from 'lodash';
import {
ApmFetchDataResponse,
FetchDataParams,
Expand All @@ -31,7 +30,7 @@ export const fetchObservabilityOverviewPageData = async ({
},
});

const { serviceCount, transactionCoordinates } = data;
const { serviceCount, transactionPerMinute } = data;

return {
appLink: `/app/apm/services?rangeFrom=${relativeTime.start}&rangeTo=${relativeTime.end}`,
Expand All @@ -42,17 +41,12 @@ export const fetchObservabilityOverviewPageData = async ({
},
transactions: {
type: 'number',
value:
mean(
transactionCoordinates
.map(({ y }) => y)
.filter((y) => y && isFinite(y))
) || 0,
value: transactionPerMinute.value || 0,
},
},
series: {
transactions: {
coordinates: transactionCoordinates,
coordinates: transactionPerMinute.timeseries,
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@
* 2.0.
*/

import {
TRANSACTION_PAGE_LOAD,
TRANSACTION_REQUEST,
} from '../../../common/transaction_types';
import { TRANSACTION_TYPE } from '../../../common/elasticsearch_fieldnames';
import { rangeQuery } from '../../../server/utils/queries';
import { Coordinates } from '../../../../observability/typings/common';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
import { calculateThroughput } from '../helpers/calculate_throughput';
import { withApmSpan } from '../../utils/with_apm_span';

export function getTransactionCoordinates({
export function getTransactionPerMinute({
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
setup,
bucketSize,
searchAggregatedTransactions,
}: {
setup: Setup & SetupTimeRange;
bucketSize: string;
searchAggregatedTransactions: boolean;
}): Promise<Coordinates[]> {
}): Promise<{ value: number | undefined; timeseries: Coordinates[] }> {
return withApmSpan(
'observability_overview_get_transaction_distribution',
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
async () => {
Expand All @@ -42,23 +47,47 @@ export function getTransactionCoordinates({
},
},
aggs: {
distribution: {
date_histogram: {
field: '@timestamp',
fixed_interval: bucketSize,
min_doc_count: 0,
transactionType: {
terms: {
field: TRANSACTION_TYPE,
},
aggs: {
timeseries: {
date_histogram: {
field: '@timestamp',
fixed_interval: bucketSize,
min_doc_count: 0,
},
},
},
},
},
},
});

return (
aggregations?.distribution.buckets.map((bucket) => ({
x: bucket.key,
y: calculateThroughput({ start, end, value: bucket.doc_count }),
})) || []
);
if (!aggregations || !aggregations.transactionType.buckets) {
return { value: undefined, timeseries: [] };
}

const topTransactionTypeBucket =
aggregations.transactionType.buckets.find(
({ key: transactionType }) =>
transactionType === TRANSACTION_REQUEST ||
transactionType === TRANSACTION_PAGE_LOAD
) || aggregations.transactionType.buckets[0];

return {
value: calculateThroughput({
start,
end,
value: topTransactionTypeBucket?.doc_count || 0,
}),
timeseries:
topTransactionTypeBucket?.timeseries.buckets.map((bucket) => ({
x: bucket.key,
y: calculateThroughput({ start, end, value: bucket.doc_count }),
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
})) || [],
};
}
);
}
8 changes: 4 additions & 4 deletions x-pack/plugins/apm/server/routes/observability_overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import * as t from 'io-ts';
import { setupRequest } from '../lib/helpers/setup_request';
import { getServiceCount } from '../lib/observability_overview/get_service_count';
import { getTransactionCoordinates } from '../lib/observability_overview/get_transaction_coordinates';
import { getTransactionPerMinute } from '../lib/observability_overview/get_transaction_per_minute';
import { getHasData } from '../lib/observability_overview/has_data';
import { createRoute } from './create_route';
import { rangeRt } from './default_api_types';
Expand Down Expand Up @@ -39,18 +39,18 @@ export const observabilityOverviewRoute = createRoute({
);

return withApmSpan('observability_overview', async () => {
const [serviceCount, transactionCoordinates] = await Promise.all([
const [serviceCount, transactionPerMinute] = await Promise.all([
getServiceCount({
setup,
searchAggregatedTransactions,
}),
getTransactionCoordinates({
getTransactionPerMinute({
setup,
bucketSize,
searchAggregatedTransactions,
}),
]);
return { serviceCount, transactionCoordinates };
return { serviceCount, transactionPerMinute };
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ function formatTpm(value?: number) {
return numeral(value).format('0.00a');
}

function formatTpmStat(value?: number) {
if (!value || value === 0) {
return '0';
}
if (value <= 0.1) {
return '< 0.1';
}
return numeral(value).format('0,0.0');
}

export function APMSection({ bucketSize }: Props) {
const theme = useContext(ThemeContext);
const chartTheme = useChartTheme();
Expand Down Expand Up @@ -93,7 +103,7 @@ export function APMSection({ bucketSize }: Props) {
</EuiFlexItem>
<EuiFlexItem grow={false}>
<StyledStat
title={`${formatTpm(stats?.transactions.value)} tpm`}
title={`${formatTpmStat(stats?.transactions.value)} tpm`}
description={i18n.translate('xpack.observability.overview.apm.throughput', {
defaultMessage: 'Throughput',
})}
Expand Down