mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[APM] Adds support for metrics for latency distribution histogram (#136083)
* [APM] Adds support for metrics for latency distribution histogram (#132394) * PR feedback Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
6f9d771714
commit
e337b58f7f
6 changed files with 65 additions and 45 deletions
|
@ -9,13 +9,10 @@ import { scaleLog } from 'd3-scale';
|
|||
|
||||
import { isFiniteNumber } from '@kbn/observability-plugin/common/utils/is_finite_number';
|
||||
import { CommonCorrelationsQueryParams } from '../../../../common/correlations/types';
|
||||
import {
|
||||
SPAN_DURATION,
|
||||
TRANSACTION_DURATION,
|
||||
} from '../../../../common/elasticsearch_fieldnames';
|
||||
import { ProcessorEvent } from '../../../../common/processor_event';
|
||||
import { Setup } from '../../../lib/helpers/setup_request';
|
||||
import { getCommonCorrelationsQuery } from './get_common_correlations_query';
|
||||
import { getDurationField } from '../utils';
|
||||
|
||||
const getHistogramRangeSteps = (min: number, max: number, steps: number) => {
|
||||
// A d3 based scale function as a helper to get equally distributed bins on a log scale.
|
||||
|
@ -42,8 +39,7 @@ export const fetchDurationHistogramRangeSteps = async ({
|
|||
|
||||
const steps = 100;
|
||||
|
||||
const durationField =
|
||||
eventType === ProcessorEvent.span ? SPAN_DURATION : TRANSACTION_DURATION;
|
||||
const durationField = getDurationField(eventType);
|
||||
|
||||
const resp = await apmEventClient.search(
|
||||
'get_duration_histogram_range_steps',
|
||||
|
|
|
@ -5,15 +5,12 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
SPAN_DURATION,
|
||||
TRANSACTION_DURATION,
|
||||
} from '../../../../common/elasticsearch_fieldnames';
|
||||
import { SIGNIFICANT_VALUE_DIGITS } from '../../../../common/correlations/constants';
|
||||
import { Setup } from '../../../lib/helpers/setup_request';
|
||||
import { ProcessorEvent } from '../../../../common/processor_event';
|
||||
import { getCommonCorrelationsQuery } from './get_common_correlations_query';
|
||||
import { CommonCorrelationsQueryParams } from '../../../../common/correlations/types';
|
||||
import { getDurationField } from '../utils';
|
||||
|
||||
export const fetchDurationPercentiles = async ({
|
||||
eventType,
|
||||
|
@ -32,36 +29,34 @@ export const fetchDurationPercentiles = async ({
|
|||
totalDocs: number;
|
||||
percentiles: Record<string, number>;
|
||||
}> => {
|
||||
const response = await setup.apmEventClient.search(
|
||||
'get_duration_percentiles',
|
||||
{
|
||||
apm: { events: [eventType] },
|
||||
body: {
|
||||
track_total_hits: true,
|
||||
query: getCommonCorrelationsQuery({
|
||||
start,
|
||||
end,
|
||||
environment,
|
||||
kuery,
|
||||
query,
|
||||
}),
|
||||
size: 0,
|
||||
aggs: {
|
||||
duration_percentiles: {
|
||||
percentiles: {
|
||||
hdr: {
|
||||
number_of_significant_value_digits: SIGNIFICANT_VALUE_DIGITS,
|
||||
},
|
||||
field:
|
||||
eventType === ProcessorEvent.span
|
||||
? SPAN_DURATION
|
||||
: TRANSACTION_DURATION,
|
||||
...(Array.isArray(percents) ? { percents } : {}),
|
||||
const params = {
|
||||
apm: { events: [eventType] },
|
||||
body: {
|
||||
track_total_hits: true,
|
||||
query: getCommonCorrelationsQuery({
|
||||
start,
|
||||
end,
|
||||
environment,
|
||||
kuery,
|
||||
query,
|
||||
}),
|
||||
size: 0,
|
||||
aggs: {
|
||||
duration_percentiles: {
|
||||
percentiles: {
|
||||
hdr: {
|
||||
number_of_significant_value_digits: SIGNIFICANT_VALUE_DIGITS,
|
||||
},
|
||||
field: getDurationField(eventType),
|
||||
...(Array.isArray(percents) ? { percents } : {}),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
const response = await setup.apmEventClient.search(
|
||||
'get_duration_percentiles',
|
||||
params
|
||||
);
|
||||
|
||||
// return early with no results if the search didn't return any documents
|
||||
|
|
|
@ -6,14 +6,11 @@
|
|||
*/
|
||||
|
||||
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import {
|
||||
SPAN_DURATION,
|
||||
TRANSACTION_DURATION,
|
||||
} from '../../../../common/elasticsearch_fieldnames';
|
||||
import { ProcessorEvent } from '../../../../common/processor_event';
|
||||
import { Setup } from '../../../lib/helpers/setup_request';
|
||||
import { getCommonCorrelationsQuery } from './get_common_correlations_query';
|
||||
import { Environment } from '../../../../common/environment_rt';
|
||||
import { getDurationField } from '../utils';
|
||||
|
||||
export const fetchDurationRanges = async ({
|
||||
rangeSteps,
|
||||
|
@ -64,10 +61,7 @@ export const fetchDurationRanges = async ({
|
|||
aggs: {
|
||||
logspace_ranges: {
|
||||
range: {
|
||||
field:
|
||||
eventType === ProcessorEvent.span
|
||||
? SPAN_DURATION
|
||||
: TRANSACTION_DURATION,
|
||||
field: getDurationField(eventType),
|
||||
ranges,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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 {
|
||||
SPAN_DURATION,
|
||||
TRANSACTION_DURATION,
|
||||
TRANSACTION_DURATION_HISTOGRAM,
|
||||
} from '../../../../common/elasticsearch_fieldnames';
|
||||
import { ProcessorEvent } from '../../../../common/processor_event';
|
||||
|
||||
export function getDurationField(eventType: ProcessorEvent) {
|
||||
switch (eventType) {
|
||||
case ProcessorEvent.metric:
|
||||
return TRANSACTION_DURATION_HISTOGRAM;
|
||||
case ProcessorEvent.span:
|
||||
return SPAN_DURATION;
|
||||
default:
|
||||
return TRANSACTION_DURATION;
|
||||
}
|
||||
}
|
|
@ -7,3 +7,4 @@
|
|||
|
||||
export { computeExpectationsAndRanges } from './compute_expectations_and_ranges';
|
||||
export { splitAllSettledPromises } from './split_all_settled_promises';
|
||||
export { getDurationField } from './get_duration_field';
|
||||
|
|
|
@ -11,6 +11,7 @@ import { termQuery } from '@kbn/observability-plugin/server';
|
|||
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { getOverallLatencyDistribution } from './get_overall_latency_distribution';
|
||||
import { setupRequest } from '../../lib/helpers/setup_request';
|
||||
import { getSearchAggregatedTransactions } from '../../lib/helpers/transactions';
|
||||
import { createApmServerRoute } from '../apm_routes/create_apm_server_route';
|
||||
import { environmentRt, kueryRt, rangeRt } from '../default_api_types';
|
||||
import {
|
||||
|
@ -61,9 +62,18 @@ const latencyOverallTransactionDistributionRoute = createApmServerRoute({
|
|||
termFilters,
|
||||
} = resources.params.body;
|
||||
|
||||
const searchAggregatedTransactions = await getSearchAggregatedTransactions({
|
||||
...setup,
|
||||
kuery,
|
||||
start,
|
||||
end,
|
||||
});
|
||||
|
||||
return getOverallLatencyDistribution({
|
||||
setup,
|
||||
eventType: ProcessorEvent.transaction,
|
||||
eventType: searchAggregatedTransactions
|
||||
? ProcessorEvent.metric
|
||||
: ProcessorEvent.transaction,
|
||||
environment,
|
||||
kuery,
|
||||
start,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue