Skip to content

Commit

Permalink
Merge branch 'master' into sessions/save-all-sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Feb 1, 2021
2 parents de99c73 + c66124e commit 53a820e
Show file tree
Hide file tree
Showing 61 changed files with 936 additions and 589 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pageLoadAssetSize:
indexLifecycleManagement: 107090
indexManagement: 140608
indexPatternManagement: 154222
infra: 197873
infra: 204800
fleet: 415829
ingestPipelines: 58003
inputControlVis: 172675
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ export async function getTransactionErrorRateChartPreview({
},
};

const outcomes = getOutcomeAggregation({
searchAggregatedTransactions: false,
});
const outcomes = getOutcomeAggregation();

const { intervalString } = getBucketSize({ start, end, numBuckets: 20 });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { isEmpty, omit } from 'lodash';
import { isEmpty, omit, merge } from 'lodash';
import { EventOutcome } from '../../../../common/event_outcome';
import {
processSignificantTermAggs,
Expand Down Expand Up @@ -134,8 +134,7 @@ export async function getErrorRateTimeSeries({
extended_bounds: { min: start, max: end },
},
aggs: {
// TODO: add support for metrics
outcomes: getOutcomeAggregation({ searchAggregatedTransactions: false }),
outcomes: getOutcomeAggregation(),
},
};

Expand All @@ -147,13 +146,12 @@ export async function getErrorRateTimeSeries({
};
return acc;
},
{} as Record<
string,
{
{} as {
[key: string]: {
filter: AggregationOptionsByType['filter'];
aggs: { timeseries: typeof timeseriesAgg };
}
>
};
}
);

const params = {
Expand All @@ -162,32 +160,25 @@ export async function getErrorRateTimeSeries({
body: {
size: 0,
query: { bool: { filter: backgroundFilters } },
aggs: {
// overall aggs
timeseries: timeseriesAgg,

// per term aggs
...perTermAggs,
},
aggs: merge({ timeseries: timeseriesAgg }, perTermAggs),
},
};

const response = await apmEventClient.search(params);
type Agg = NonNullable<typeof response.aggregations>;
const { aggregations } = response;

if (!response.aggregations) {
if (!aggregations) {
return {};
}

return {
overall: {
timeseries: getTransactionErrorRateTimeSeries(
response.aggregations.timeseries.buckets
aggregations.timeseries.buckets
),
},
significantTerms: topSigTerms.map((topSig, index) => {
// @ts-expect-error
const agg = response.aggregations[`term_${index}`] as Agg;
const agg = aggregations[`term_${index}`]!;

return {
...topSig,
Expand Down
41 changes: 11 additions & 30 deletions x-pack/plugins/apm/server/lib/helpers/transaction_error_rate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,21 @@ import {
AggregationOptionsByType,
AggregationResultOf,
} from '../../../../../typings/elasticsearch/aggregations';
import { getTransactionDurationFieldForAggregatedTransactions } from './aggregated_transactions';

export function getOutcomeAggregation({
searchAggregatedTransactions,
}: {
searchAggregatedTransactions: boolean;
}) {
return {
terms: {
field: EVENT_OUTCOME,
include: [EventOutcome.failure, EventOutcome.success],
},
aggs: {
// simply using the doc count to get the number of requests is not possible for transaction metrics (histograms)
// to work around this we get the number of transactions by counting the number of latency values
count: {
value_count: {
field: getTransactionDurationFieldForAggregatedTransactions(
searchAggregatedTransactions
),
},
},
},
};
}
export const getOutcomeAggregation = () => ({
terms: {
field: EVENT_OUTCOME,
include: [EventOutcome.failure, EventOutcome.success],
},
});

type OutcomeAggregation = ReturnType<typeof getOutcomeAggregation>;

export function calculateTransactionErrorPercentage(
outcomeResponse: AggregationResultOf<
ReturnType<typeof getOutcomeAggregation>,
{}
>
outcomeResponse: AggregationResultOf<OutcomeAggregation, {}>
) {
const outcomes = Object.fromEntries(
outcomeResponse.buckets.map(({ key, count }) => [key, count.value])
outcomeResponse.buckets.map(({ key, doc_count: count }) => [key, count])
);

const failedTransactions = outcomes[EventOutcome.failure] ?? 0;
Expand All @@ -56,7 +37,7 @@ export function getTransactionErrorRateTimeSeries(
buckets: AggregationResultOf<
{
date_histogram: AggregationOptionsByType['date_histogram'];
aggs: { outcomes: ReturnType<typeof getOutcomeAggregation> };
aggs: { outcomes: OutcomeAggregation };
},
{}
>['buckets']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import { rangeFilter } from '../../../common/utils/range_filter';
import { Coordinates } from '../../../../observability/typings/common';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import {
getProcessorEventForAggregatedTransactions,
getTransactionDurationFieldForAggregatedTransactions,
} from '../helpers/aggregated_transactions';
import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';

export async function getTransactionCoordinates({
setup,
Expand Down Expand Up @@ -49,15 +46,6 @@ export async function getTransactionCoordinates({
fixed_interval: bucketSize,
min_doc_count: 0,
},
aggs: {
count: {
value_count: {
field: getTransactionDurationFieldForAggregatedTransactions(
searchAggregatedTransactions
),
},
},
},
},
},
},
Expand All @@ -68,7 +56,7 @@ export async function getTransactionCoordinates({
return (
aggregations?.distribution.buckets.map((bucket) => ({
x: bucket.key,
y: bucket.count.value / deltaAsMinutes,
y: bucket.doc_count / deltaAsMinutes,
})) || []
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ describe('getServiceMapServiceNodeInfo', () => {
apmEventClient: {
search: () =>
Promise.resolve({
hits: {
total: { value: 1 },
},
aggregations: {
count: { value: 1 },
duration: { value: null },
avgCpuUsage: { value: null },
avgMemoryUsage: { value: null },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,12 @@ async function getTransactionStats({
),
},
},
count: {
value_count: {
field: getTransactionDurationFieldForAggregatedTransactions(
searchAggregatedTransactions
),
},
},
},
},
};
const response = await apmEventClient.search(params);

const totalRequests = response.aggregations?.count.value ?? 0;
const totalRequests = response.hits.total.value;

return {
avgTransactionDuration: response.aggregations?.duration.value ?? null,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@ export async function getServiceInstanceTransactionStats({
}: ServiceInstanceParams) {
const { apmEventClient, start, end, esFilter } = setup;

const { intervalString } = getBucketSize({ start, end, numBuckets });
const { intervalString, bucketSize } = getBucketSize({
start,
end,
numBuckets,
});

const field = getTransactionDurationFieldForAggregatedTransactions(
searchAggregatedTransactions
);

const subAggs = {
count: {
value_count: {
field,
},
},
avg_transaction_duration: {
avg: {
field,
Expand All @@ -53,13 +52,6 @@ export async function getServiceInstanceTransactionStats({
[EVENT_OUTCOME]: EventOutcome.failure,
},
},
aggs: {
count: {
value_count: {
field,
},
},
},
},
};

Expand Down Expand Up @@ -113,12 +105,13 @@ export async function getServiceInstanceTransactionStats({
});

const deltaAsMinutes = (end - start) / 60 / 1000;
const bucketSizeInMinutes = bucketSize / 60;

return (
response.aggregations?.[SERVICE_NODE_NAME].buckets.map(
(serviceNodeBucket) => {
const {
count,
doc_count: count,
avg_transaction_duration: avgTransactionDuration,
key,
failures,
Expand All @@ -128,17 +121,17 @@ export async function getServiceInstanceTransactionStats({
return {
serviceNodeName: String(key),
errorRate: {
value: failures.count.value / count.value,
value: failures.doc_count / count,
timeseries: timeseries.buckets.map((dateBucket) => ({
x: dateBucket.key,
y: dateBucket.failures.count.value / dateBucket.count.value,
y: dateBucket.failures.doc_count / dateBucket.doc_count,
})),
},
throughput: {
value: count.value / deltaAsMinutes,
value: count / deltaAsMinutes,
timeseries: timeseries.buckets.map((dateBucket) => ({
x: dateBucket.key,
y: dateBucket.count.value / deltaAsMinutes,
y: dateBucket.doc_count / bucketSizeInMinutes,
})),
},
latency: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {

import { ESFilter } from '../../../../../../typings/elasticsearch';
import {
getDocumentTypeFilterForAggregatedTransactions,
getProcessorEventForAggregatedTransactions,
getTransactionDurationFieldForAggregatedTransactions,
} from '../../helpers/aggregated_transactions';
Expand Down Expand Up @@ -76,6 +77,9 @@ export async function getTimeseriesDataForTransactionGroups({
{ term: { [SERVICE_NAME]: serviceName } },
{ term: { [TRANSACTION_TYPE]: transactionType } },
{ range: rangeFilter(start, end) },
...getDocumentTypeFilterForAggregatedTransactions(
searchAggregatedTransactions
),
...esFilter,
],
},
Expand All @@ -99,10 +103,8 @@ export async function getTimeseriesDataForTransactionGroups({
},
aggs: {
...getLatencyAggregation(latencyAggregationType, field),
transaction_count: { value_count: { field } },
[EVENT_OUTCOME]: {
filter: { term: { [EVENT_OUTCOME]: EventOutcome.failure } },
aggs: { transaction_count: { value_count: { field } } },
},
},
},
Expand Down
Loading

0 comments on commit 53a820e

Please sign in to comment.