Add minimum bucket size when using metric powered ui (#103773)
* Add minimum bucket size when using metric powered ui * addressing PR comments * addressing comments Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
5d95e2e0cd
commit
b612fca2e7
|
@ -13,24 +13,18 @@ export function getBucketSize({
|
|||
start,
|
||||
end,
|
||||
numBuckets = 100,
|
||||
minBucketSize,
|
||||
}: {
|
||||
start: number;
|
||||
end: number;
|
||||
numBuckets?: number;
|
||||
minBucketSize?: number;
|
||||
}) {
|
||||
const duration = moment.duration(end - start, 'ms');
|
||||
const bucketSize = Math.max(
|
||||
calculateAuto.near(numBuckets, duration).asSeconds(),
|
||||
1
|
||||
minBucketSize || 1
|
||||
);
|
||||
const intervalString = `${bucketSize}s`;
|
||||
|
||||
if (bucketSize < 0) {
|
||||
return {
|
||||
bucketSize: 0,
|
||||
intervalString: 'auto',
|
||||
};
|
||||
}
|
||||
|
||||
return { bucketSize, intervalString };
|
||||
return { bucketSize, intervalString: `${bucketSize}s` };
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
import { getBucketSizeForAggregatedTransactions } from './';
|
||||
|
||||
describe('getBucketSizeForAggregatedTransactions', () => {
|
||||
describe('when searchAggregatedTransactions is enabled', () => {
|
||||
it('returns min bucket size when date difference is lower than 60s', () => {
|
||||
expect(
|
||||
getBucketSizeForAggregatedTransactions({
|
||||
start: new Date('2021-06-30T15:00:00.000Z').valueOf(),
|
||||
end: new Date('2021-06-30T15:00:30.000Z').valueOf(),
|
||||
numBuckets: 10,
|
||||
searchAggregatedTransactions: true,
|
||||
})
|
||||
).toEqual({ bucketSize: 60, intervalString: '60s' });
|
||||
});
|
||||
it('returns bucket size when date difference is greater than 60s', () => {
|
||||
expect(
|
||||
getBucketSizeForAggregatedTransactions({
|
||||
start: new Date('2021-06-30T15:00:00.000Z').valueOf(),
|
||||
end: new Date('2021-06-30T15:30:00.000Z').valueOf(),
|
||||
numBuckets: 10,
|
||||
searchAggregatedTransactions: true,
|
||||
})
|
||||
).toEqual({ bucketSize: 300, intervalString: '300s' });
|
||||
});
|
||||
});
|
||||
describe('when searchAggregatedTransactions is disabled', () => {
|
||||
it('returns 1s as bucket size', () => {
|
||||
expect(
|
||||
getBucketSizeForAggregatedTransactions({
|
||||
start: new Date('2021-06-30T15:00:00.000Z').valueOf(),
|
||||
end: new Date('2021-06-30T15:00:30.000Z').valueOf(),
|
||||
numBuckets: 10,
|
||||
searchAggregatedTransactions: false,
|
||||
})
|
||||
).toEqual({ bucketSize: 1, intervalString: '1s' });
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { getBucketSize } from '../get_bucket_size';
|
||||
|
||||
export function getBucketSizeForAggregatedTransactions({
|
||||
start,
|
||||
end,
|
||||
numBuckets = 100,
|
||||
searchAggregatedTransactions,
|
||||
}: {
|
||||
start: number;
|
||||
end: number;
|
||||
numBuckets?: number;
|
||||
searchAggregatedTransactions?: boolean;
|
||||
}) {
|
||||
const minBucketSize = searchAggregatedTransactions ? 60 : undefined;
|
||||
return getBucketSize({ start, end, numBuckets, minBucketSize });
|
||||
}
|
|
@ -20,7 +20,7 @@ import {
|
|||
getTransactionDurationFieldForAggregatedTransactions,
|
||||
} from '../../helpers/aggregated_transactions';
|
||||
import { calculateThroughput } from '../../helpers/calculate_throughput';
|
||||
import { getBucketSize } from '../../helpers/get_bucket_size';
|
||||
import { getBucketSizeForAggregatedTransactions } from '../../helpers/get_bucket_size_for_aggregated_transactions';
|
||||
import {
|
||||
getLatencyAggregation,
|
||||
getLatencyValue,
|
||||
|
@ -78,11 +78,14 @@ export async function getServiceInstancesTransactionStatistics<
|
|||
}): Promise<Array<ServiceInstanceTransactionStatistics<T>>> {
|
||||
const { apmEventClient } = setup;
|
||||
|
||||
const { intervalString, bucketSize } = getBucketSize({
|
||||
start,
|
||||
end,
|
||||
numBuckets,
|
||||
});
|
||||
const { intervalString, bucketSize } = getBucketSizeForAggregatedTransactions(
|
||||
{
|
||||
start,
|
||||
end,
|
||||
numBuckets,
|
||||
searchAggregatedTransactions,
|
||||
}
|
||||
);
|
||||
|
||||
const field = getTransactionDurationFieldForAggregatedTransactions(
|
||||
searchAggregatedTransactions
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
*/
|
||||
|
||||
import { keyBy } from 'lodash';
|
||||
import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate';
|
||||
import {
|
||||
EVENT_OUTCOME,
|
||||
SERVICE_NAME,
|
||||
|
@ -15,10 +14,11 @@ 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 {
|
||||
environmentQuery,
|
||||
rangeQuery,
|
||||
kqlQuery,
|
||||
rangeQuery,
|
||||
} from '../../../server/utils/queries';
|
||||
import { Coordinate } from '../../../typings/timeseries';
|
||||
import {
|
||||
|
@ -26,7 +26,7 @@ import {
|
|||
getProcessorEventForAggregatedTransactions,
|
||||
getTransactionDurationFieldForAggregatedTransactions,
|
||||
} from '../helpers/aggregated_transactions';
|
||||
import { getBucketSize } from '../helpers/get_bucket_size';
|
||||
import { getBucketSizeForAggregatedTransactions } from '../helpers/get_bucket_size_for_aggregated_transactions';
|
||||
import {
|
||||
getLatencyAggregation,
|
||||
getLatencyValue,
|
||||
|
@ -68,7 +68,12 @@ export async function getServiceTransactionGroupDetailedStatistics({
|
|||
}>
|
||||
> {
|
||||
const { apmEventClient } = setup;
|
||||
const { intervalString } = getBucketSize({ start, end, numBuckets });
|
||||
const { intervalString } = getBucketSizeForAggregatedTransactions({
|
||||
start,
|
||||
end,
|
||||
numBuckets,
|
||||
searchAggregatedTransactions,
|
||||
});
|
||||
|
||||
const field = getTransactionDurationFieldForAggregatedTransactions(
|
||||
searchAggregatedTransactions
|
||||
|
|
|
@ -17,8 +17,8 @@ import {
|
|||
} from '../../../../common/transaction_types';
|
||||
import {
|
||||
environmentQuery,
|
||||
rangeQuery,
|
||||
kqlQuery,
|
||||
rangeQuery,
|
||||
} from '../../../../server/utils/queries';
|
||||
import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent';
|
||||
import {
|
||||
|
@ -26,8 +26,8 @@ import {
|
|||
getProcessorEventForAggregatedTransactions,
|
||||
getTransactionDurationFieldForAggregatedTransactions,
|
||||
} from '../../helpers/aggregated_transactions';
|
||||
import { getBucketSize } from '../../helpers/get_bucket_size';
|
||||
import { calculateThroughput } from '../../helpers/calculate_throughput';
|
||||
import { getBucketSizeForAggregatedTransactions } from '../../helpers/get_bucket_size_for_aggregated_transactions';
|
||||
import {
|
||||
calculateTransactionErrorPercentage,
|
||||
getOutcomeAggregation,
|
||||
|
@ -117,10 +117,11 @@ export async function getServiceTransactionStats({
|
|||
timeseries: {
|
||||
date_histogram: {
|
||||
field: '@timestamp',
|
||||
fixed_interval: getBucketSize({
|
||||
fixed_interval: getBucketSizeForAggregatedTransactions({
|
||||
start,
|
||||
end,
|
||||
numBuckets: 20,
|
||||
searchAggregatedTransactions,
|
||||
}).intervalString,
|
||||
min_doc_count: 0,
|
||||
extended_bounds: { min: start, max: end },
|
||||
|
|
|
@ -12,14 +12,14 @@ import {
|
|||
} from '../../../common/elasticsearch_fieldnames';
|
||||
import {
|
||||
environmentQuery,
|
||||
rangeQuery,
|
||||
kqlQuery,
|
||||
rangeQuery,
|
||||
} from '../../../server/utils/queries';
|
||||
import {
|
||||
getDocumentTypeFilterForAggregatedTransactions,
|
||||
getProcessorEventForAggregatedTransactions,
|
||||
} from '../helpers/aggregated_transactions';
|
||||
import { getBucketSize } from '../helpers/get_bucket_size';
|
||||
import { getBucketSizeForAggregatedTransactions } from '../helpers/get_bucket_size_for_aggregated_transactions';
|
||||
import { Setup } from '../helpers/setup_request';
|
||||
|
||||
interface Options {
|
||||
|
@ -44,7 +44,11 @@ function fetcher({
|
|||
end,
|
||||
}: Options) {
|
||||
const { apmEventClient } = setup;
|
||||
const { intervalString } = getBucketSize({ start, end });
|
||||
const { intervalString } = getBucketSizeForAggregatedTransactions({
|
||||
start,
|
||||
end,
|
||||
searchAggregatedTransactions,
|
||||
});
|
||||
const filter: ESFilter[] = [
|
||||
{ term: { [SERVICE_NAME]: serviceName } },
|
||||
{ term: { [TRANSACTION_TYPE]: transactionType } },
|
||||
|
|
|
@ -5,9 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate';
|
||||
import { Coordinate } from '../../../typings/timeseries';
|
||||
|
||||
import {
|
||||
EVENT_OUTCOME,
|
||||
SERVICE_NAME,
|
||||
|
@ -15,16 +12,18 @@ import {
|
|||
TRANSACTION_TYPE,
|
||||
} from '../../../common/elasticsearch_fieldnames';
|
||||
import { EventOutcome } from '../../../common/event_outcome';
|
||||
import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate';
|
||||
import {
|
||||
environmentQuery,
|
||||
rangeQuery,
|
||||
kqlQuery,
|
||||
rangeQuery,
|
||||
} from '../../../server/utils/queries';
|
||||
import { Coordinate } from '../../../typings/timeseries';
|
||||
import {
|
||||
getDocumentTypeFilterForAggregatedTransactions,
|
||||
getProcessorEventForAggregatedTransactions,
|
||||
} from '../helpers/aggregated_transactions';
|
||||
import { getBucketSize } from '../helpers/get_bucket_size';
|
||||
import { getBucketSizeForAggregatedTransactions } from '../helpers/get_bucket_size_for_aggregated_transactions';
|
||||
import { Setup, SetupTimeRange } from '../helpers/setup_request';
|
||||
import {
|
||||
calculateTransactionErrorPercentage,
|
||||
|
@ -101,7 +100,11 @@ export async function getErrorRate({
|
|||
timeseries: {
|
||||
date_histogram: {
|
||||
field: '@timestamp',
|
||||
fixed_interval: getBucketSize({ start, end }).intervalString,
|
||||
fixed_interval: getBucketSizeForAggregatedTransactions({
|
||||
start,
|
||||
end,
|
||||
searchAggregatedTransactions,
|
||||
}).intervalString,
|
||||
min_doc_count: 0,
|
||||
extended_bounds: { min: start, max: end },
|
||||
},
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { offsetPreviousPeriodCoordinates } from '../../../../common/utils/offset_previous_period_coordinate';
|
||||
import { ESFilter } from '../../../../../../../src/core/types/elasticsearch';
|
||||
import { PromiseReturnType } from '../../../../../observability/typings/common';
|
||||
import {
|
||||
|
@ -14,18 +13,19 @@ import {
|
|||
TRANSACTION_TYPE,
|
||||
} from '../../../../common/elasticsearch_fieldnames';
|
||||
import { LatencyAggregationType } from '../../../../common/latency_aggregation_types';
|
||||
import { offsetPreviousPeriodCoordinates } from '../../../../common/utils/offset_previous_period_coordinate';
|
||||
import {
|
||||
environmentQuery,
|
||||
rangeQuery,
|
||||
kqlQuery,
|
||||
rangeQuery,
|
||||
} from '../../../../server/utils/queries';
|
||||
import {
|
||||
getDocumentTypeFilterForAggregatedTransactions,
|
||||
getProcessorEventForAggregatedTransactions,
|
||||
getTransactionDurationFieldForAggregatedTransactions,
|
||||
} from '../../../lib/helpers/aggregated_transactions';
|
||||
import { getBucketSize } from '../../../lib/helpers/get_bucket_size';
|
||||
import { Setup, SetupTimeRange } from '../../../lib/helpers/setup_request';
|
||||
import { getBucketSizeForAggregatedTransactions } from '../../helpers/get_bucket_size_for_aggregated_transactions';
|
||||
import {
|
||||
getLatencyAggregation,
|
||||
getLatencyValue,
|
||||
|
@ -58,7 +58,11 @@ function searchLatency({
|
|||
end: number;
|
||||
}) {
|
||||
const { apmEventClient } = setup;
|
||||
const { intervalString } = getBucketSize({ start, end });
|
||||
const { intervalString } = getBucketSizeForAggregatedTransactions({
|
||||
start,
|
||||
end,
|
||||
searchAggregatedTransactions,
|
||||
});
|
||||
|
||||
const filter: ESFilter[] = [
|
||||
{ term: { [SERVICE_NAME]: serviceName } },
|
||||
|
|
|
@ -15,15 +15,15 @@ import {
|
|||
} from '../../../../common/elasticsearch_fieldnames';
|
||||
import {
|
||||
environmentQuery,
|
||||
rangeQuery,
|
||||
kqlQuery,
|
||||
rangeQuery,
|
||||
} from '../../../../server/utils/queries';
|
||||
import {
|
||||
getDocumentTypeFilterForAggregatedTransactions,
|
||||
getProcessorEventForAggregatedTransactions,
|
||||
} from '../../../lib/helpers/aggregated_transactions';
|
||||
import { getBucketSize } from '../../../lib/helpers/get_bucket_size';
|
||||
import { Setup, SetupTimeRange } from '../../../lib/helpers/setup_request';
|
||||
import { getBucketSizeForAggregatedTransactions } from '../../helpers/get_bucket_size_for_aggregated_transactions';
|
||||
import { getThroughputBuckets } from './transform';
|
||||
|
||||
export type ThroughputChartsResponse = PromiseReturnType<
|
||||
|
@ -115,7 +115,12 @@ export async function getThroughputCharts({
|
|||
setup: Setup & SetupTimeRange;
|
||||
searchAggregatedTransactions: boolean;
|
||||
}) {
|
||||
const { bucketSize, intervalString } = getBucketSize(setup);
|
||||
const { bucketSize, intervalString } = getBucketSizeForAggregatedTransactions(
|
||||
{
|
||||
...setup,
|
||||
searchAggregatedTransactions,
|
||||
}
|
||||
);
|
||||
|
||||
const response = await searchThroughput({
|
||||
environment,
|
||||
|
|
Loading…
Reference in a new issue