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

[APM] Remove rate aggregations #112343

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5d0d418
fixing rate aggregation bug
cauemarcondes Sep 15, 2021
b11a3ed
Merge branch '7.15' into apm-throughput-fix
kibanamachine Sep 15, 2021
cf1c1d4
fixing tests and i18n
cauemarcondes Sep 15, 2021
d8a7b3d
Merge branch 'apm-throughput-fix' of github.com:cauemarcondes/kibana …
cauemarcondes Sep 15, 2021
917d11d
fixing tests
cauemarcondes Sep 15, 2021
9d1b0c6
Merge branch '7.15' of github.com:elastic/kibana into apm-throughput-fix
cauemarcondes Sep 15, 2021
8074ded
putting back some code
cauemarcondes Sep 16, 2021
6b87f7c
fixing import path
cauemarcondes Sep 16, 2021
ffdfa37
Merge branch '7.15' into apm-throughput-fix
kibanamachine Sep 20, 2021
29d267d
addressing pr changes
cauemarcondes Sep 21, 2021
f9715a6
fixing prettier
cauemarcondes Sep 21, 2021
1863af6
renaming
cauemarcondes Sep 21, 2021
52082f2
roll back
cauemarcondes Sep 21, 2021
920446d
ading more tests
cauemarcondes Sep 21, 2021
fb99e15
fixing observability api
cauemarcondes Sep 21, 2021
d039b26
Merge branch '7.15' of github.com:elastic/kibana into apm-throughput-fix
cauemarcondes Sep 22, 2021
0346169
removing tps
cauemarcondes Sep 22, 2021
c8626e2
fixing ci
cauemarcondes Sep 22, 2021
5461eaa
fixing throughput
cauemarcondes Sep 22, 2021
44fdd99
fixing i18n and test
cauemarcondes Sep 22, 2021
e51dca8
fixing tests
cauemarcondes Sep 23, 2021
a6506ed
addressing pr comments
cauemarcondes Sep 23, 2021
39ea850
fixing ci
cauemarcondes Sep 23, 2021
513961d
Merge branch '7.15' into apm-throughput-fix
kibanamachine Sep 27, 2021
4fb3901
improving tests
cauemarcondes Sep 27, 2021
22f04e3
Merge branch 'apm-throughput-fix' of github.com:cauemarcondes/kibana …
cauemarcondes Sep 27, 2021
63ddf04
adding throughput api test
cauemarcondes Sep 29, 2021
6246a7b
Merge branch '7.15' into apm-throughput-fix
kibanamachine Sep 29, 2021
c014d4c
Merge branch '7.15' of github.com:elastic/kibana into apm-throughput-fix
cauemarcondes Oct 4, 2021
832a6df
adding throughput tests
cauemarcondes Oct 5, 2021
31992c5
Merge branch 'apm-throughput-fix' of github.com:cauemarcondes/kibana …
cauemarcondes Oct 5, 2021
cfd6c20
addressing PR changes
cauemarcondes Oct 5, 2021
a8ea02e
adding dependencies test
cauemarcondes Oct 5, 2021
5ef60ce
adding tests for dependencies apis
cauemarcondes Oct 5, 2021
9489676
addressing pr changes
cauemarcondes Oct 6, 2021
a281db3
renaming archives
cauemarcondes Oct 6, 2021
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
10 changes: 5 additions & 5 deletions x-pack/plugins/apm/common/utils/formatters/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import { asDecimalOrInteger, asInteger, asDecimal } from './formatters';
import { TimeUnit } from './datetime';
import { Maybe } from '../../../typings/common';
import { isFiniteNumber } from '../is_finite_number';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import type { ThroughputUnit } from '../../../server/lib/helpers/calculate_throughput';

interface FormatterOptions {
defaultValue?: string;
Expand Down Expand Up @@ -182,10 +180,12 @@ export function asTransactionRate(value: Maybe<number>) {
});
}

export function asExactTransactionRate(value: number, unit: ThroughputUnit) {
export function asExactTransactionRate(value: number) {
return i18n.translate('xpack.apm.exactTransactionRateLabel', {
defaultMessage: `{value} { unit, select, minute {tpm} other {tps} }`,
values: { value: asDecimalOrInteger(value), unit },
defaultMessage: `{value} tpm`,
values: {
value: asDecimalOrInteger(value),
},
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,29 +123,16 @@ 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)',
})
}
content={i18n.translate('xpack.apm.serviceOverview.tpmHelp', {
defaultMessage:
'Throughput is measured in transactions per minute (tpm)',
})}
position="right"
/>
</EuiFlexItem>
Expand All @@ -157,7 +144,7 @@ export function ServiceOverviewThroughputChart({
showAnnotations={false}
fetchStatus={status}
timeseries={timeseries}
yLabelFormat={(y) => asExactTransactionRate(y, data.throughputUnit)}
yLabelFormat={asExactTransactionRate}
customTheme={comparisonChartTheme}
/>
</EuiPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe('Observability dashboard data', () => {
start: 'now-15m',
end: 'now',
},
bucketSize: '600s',
bucketSize: 600,
intervalString: '600s',
};
afterEach(() => {
callApmApiMock.mockClear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const fetchObservabilityOverviewPageData = async ({
absoluteTime,
relativeTime,
bucketSize,
intervalString,
}: FetchDataParams): Promise<ApmFetchDataResponse> => {
const data = await callApmApi({
endpoint: 'GET /api/apm/observability_overview',
Expand All @@ -24,6 +25,7 @@ export const fetchObservabilityOverviewPageData = async ({
start: new Date(absoluteTime.start).toISOString(),
end: new Date(absoluteTime.end).toISOString(),
bucketSize,
intervalString,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ 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 { calculateThroughputWithInterval } from '../helpers/calculate_throughput';
import { getBucketSize } from '../helpers/get_bucket_size';

export async function getThroughputChartsForBackend({
backendName,
Expand All @@ -41,6 +42,12 @@ export async function getThroughputChartsForBackend({
offset,
});

const { intervalString, bucketSize } = getBucketSize({
start: startWithOffset,
end: endWithOffset,
minBucketSize: 60,
});
sorenlouv marked this conversation as resolved.
Show resolved Hide resolved

const response = await apmEventClient.search('get_throughput_for_backend', {
apm: {
events: [ProcessorEvent.metric],
Expand All @@ -59,16 +66,16 @@ export async function getThroughputChartsForBackend({
},
aggs: {
timeseries: {
date_histogram: getMetricsDateHistogramParams({
start: startWithOffset,
end: endWithOffset,
metricsInterval: 60,
}),
date_histogram: {
field: '@timestamp',
fixed_interval: intervalString,
min_doc_count: 0,
extended_bounds: { min: startWithOffset, max: endWithOffset },
sorenlouv marked this conversation as resolved.
Show resolved Hide resolved
},
aggs: {
throughput: {
rate: {
sumSpanDestination: {
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
sum: {
field: SPAN_DESTINATION_SERVICE_RESPONSE_TIME_COUNT,
unit: 'minute',
},
},
},
Expand All @@ -81,7 +88,10 @@ export async function getThroughputChartsForBackend({
response.aggregations?.timeseries.buckets.map((bucket) => {
return {
x: bucket.key + offsetInMs,
y: bucket.throughput.value,
y: calculateThroughputWithInterval({
bucketSize,
value: bucket.sumSpanDestination.value || 0,
}),
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
};
}) ?? []
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { joinByKey } from '../../../../common/utils/join_by_key';
import { Setup } from '../../helpers/setup_request';
import { getStats } from './get_stats';
import { getDestinationMap } from './get_destination_map';
import { calculateThroughput } from '../../helpers/calculate_throughput';
import { calculateThroughputWithRange } from '../../helpers/calculate_throughput';
import { withApmSpan } from '../../../utils/with_apm_span';

export function getConnectionStats({
Expand Down Expand Up @@ -123,18 +123,15 @@ export function getConnectionStats({
throughput: {
value:
mergedStats.value.count > 0
? calculateThroughput({
? calculateThroughputWithRange({
start,
end,
value: mergedStats.value.count,
})
: null,
timeseries: mergedStats.timeseries.map((point) => ({
x: point.x,
y:
point.count > 0
? calculateThroughput({ start, end, value: point.count })
: null,
y: point.count, // sparklines only shows trend (no axis)
})),
},
errorRate: {
Expand Down
15 changes: 13 additions & 2 deletions x-pack/plugins/apm/server/lib/helpers/calculate_throughput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@

import { SetupTimeRange } from './setup_request';

export function calculateThroughput({
export function calculateThroughputWithRange({
start,
end,
value,
}: SetupTimeRange & { value: number }) {
}: SetupTimeRange & { value: number; unit?: ThroughputUnit }) {
const durationAsMinutes = (end - start) / 1000 / 60;
return value / durationAsMinutes;
}

export function calculateThroughputWithInterval({
bucketSize,
value,
}: {
bucketSize: number;
value: number;
}) {
const durationAsMinutes = bucketSize / 60;
return value / durationAsMinutes;
}

export type ThroughputUnit = 'minute' | 'second';
export function getThroughputUnit(bucketSize: number): ThroughputUnit {
return bucketSize >= 60 ? 'minute' : 'second';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ import {
getDocumentTypeFilterForAggregatedTransactions,
getProcessorEventForAggregatedTransactions,
} from '../helpers/aggregated_transactions';
import { calculateThroughput } from '../helpers/calculate_throughput';
import {
calculateThroughputWithInterval,
calculateThroughputWithRange,
} from '../helpers/calculate_throughput';

export async function getTransactionsPerMinute({
setup,
bucketSize,
intervalString,
searchAggregatedTransactions,
}: {
setup: Setup & SetupTimeRange;
bucketSize: string;
bucketSize: number;
intervalString: string;
searchAggregatedTransactions: boolean;
}) {
const { apmEventClient, start, end } = setup;
Expand Down Expand Up @@ -60,12 +65,9 @@ export async function getTransactionsPerMinute({
timeseries: {
date_histogram: {
field: '@timestamp',
fixed_interval: bucketSize,
fixed_interval: intervalString,
min_doc_count: 0,
},
aggs: {
throughput: { rate: { unit: 'minute' as const } },
},
},
},
},
Expand All @@ -86,15 +88,18 @@ export async function getTransactionsPerMinute({
) || aggregations.transactionType.buckets[0];

return {
value: calculateThroughput({
value: calculateThroughputWithRange({
start,
end,
value: topTransactionTypeBucket?.doc_count || 0,
}),
timeseries:
topTransactionTypeBucket?.timeseries.buckets.map((bucket) => ({
x: bucket.key,
y: bucket.throughput.value,
y: calculateThroughputWithInterval({
bucketSize,
value: bucket.doc_count,
}),
})) || [],
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { EventOutcome } from '../../../common/event_outcome';
import { ProcessorEvent } from '../../../common/processor_event';
import { environmentQuery } from '../../../common/utils/environment_query';
import { withApmSpan } from '../../utils/with_apm_span';
import { calculateThroughput } from '../helpers/calculate_throughput';
import { calculateThroughputWithRange } from '../helpers/calculate_throughput';
import { Setup, SetupTimeRange } from '../helpers/setup_request';

interface Options {
Expand Down Expand Up @@ -76,7 +76,7 @@ export function getServiceMapBackendNodeInfo({

const avgErrorRate = errorCount / count;
const avgTransactionDuration = latencySum / count;
const avgRequestsPerMinute = calculateThroughput({
const avgRequestsPerMinute = calculateThroughputWithRange({
start,
end,
value: count,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
getProcessorEventForAggregatedTransactions,
getTransactionDurationFieldForAggregatedTransactions,
} from '../../helpers/aggregated_transactions';
import { calculateThroughput } from '../../helpers/calculate_throughput';
import { calculateThroughputWithRange } from '../../helpers/calculate_throughput';
import { getBucketSizeForAggregatedTransactions } from '../../helpers/get_bucket_size_for_aggregated_transactions';
import {
getLatencyAggregation,
Expand Down Expand Up @@ -194,7 +194,11 @@ export async function getServiceInstancesTransactionStatistics<
aggregation: latency,
latencyAggregationType,
}),
throughput: calculateThroughput({ start, end, value: count }),
throughput: calculateThroughputWithRange({
start,
end,
value: count,
}),
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { keyBy } from 'lodash';
import { kqlQuery, rangeQuery } from '../../../../observability/server';
import {
EVENT_OUTCOME,
SERVICE_NAME,
Expand All @@ -14,9 +15,8 @@ import {
} from '../../../common/elasticsearch_fieldnames';
import { EventOutcome } from '../../../common/event_outcome';
import { LatencyAggregationType } from '../../../common/latency_aggregation_types';
import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate';
import { kqlQuery, rangeQuery } from '../../../../observability/server';
import { environmentQuery } from '../../../common/utils/environment_query';
import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate';
import { Coordinate } from '../../../typings/timeseries';
import {
getDocumentTypeFilterForAggregatedTransactions,
Expand Down Expand Up @@ -125,11 +125,6 @@ export async function getServiceTransactionGroupDetailedStatistics({
},
},
aggs: {
throughput_rate: {
rate: {
unit: 'minute',
},
},
...getLatencyAggregation(latencyAggregationType, field),
[EVENT_OUTCOME]: {
terms: {
Expand Down Expand Up @@ -160,7 +155,7 @@ export async function getServiceTransactionGroupDetailedStatistics({
}));
const throughput = bucket.timeseries.buckets.map((timeseriesBucket) => ({
x: timeseriesBucket.key,
y: timeseriesBucket.throughput_rate.value,
y: timeseriesBucket.doc_count, // sparklines only shows trend (no axis)
}));
const errorRate = bucket.timeseries.buckets.map((timeseriesBucket) => ({
x: timeseriesBucket.key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
getProcessorEventForAggregatedTransactions,
getTransactionDurationFieldForAggregatedTransactions,
} from '../helpers/aggregated_transactions';
import { calculateThroughput } from '../helpers/calculate_throughput';
import { calculateThroughputWithRange } from '../helpers/calculate_throughput';
import {
getLatencyAggregation,
getLatencyValue,
Expand Down Expand Up @@ -126,7 +126,7 @@ export async function getServiceTransactionGroups({
latencyAggregationType,
aggregation: bucket.latency,
}),
throughput: calculateThroughput({
throughput: calculateThroughputWithRange({
start,
end,
value: bucket.doc_count,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
getProcessorEventForAggregatedTransactions,
getTransactionDurationFieldForAggregatedTransactions,
} from '../../helpers/aggregated_transactions';
import { calculateThroughput } from '../../helpers/calculate_throughput';
import { calculateThroughputWithRange } from '../../helpers/calculate_throughput';
import {
calculateFailedTransactionRate,
getOutcomeAggregation,
Expand Down Expand Up @@ -140,7 +140,7 @@ export async function getServiceTransactionStats({
transactionErrorRate: calculateFailedTransactionRate(
topTransactionTypeBucket.outcomes
),
throughput: calculateThroughput({
throughput: calculateThroughputWithRange({
start,
end,
value: topTransactionTypeBucket.doc_count,
Expand Down
Loading