Skip to content

Commit

Permalink
[APM] Latency threshold alerts are not being triggered (#110315) (#11…
Browse files Browse the repository at this point in the history
…0381)

Co-authored-by: Cauê Marcondes <[email protected]>
  • Loading branch information
kibanamachine and cauemarcondes authored Aug 30, 2021
1 parent 8dc8626 commit bebf6bf
Showing 1 changed file with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* 2.0.
*/

import { schema } from '@kbn/config-schema';
import { take } from 'rxjs/operators';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/api/types';
import { schema } from '@kbn/config-schema';
import type {
ALERT_EVALUATION_THRESHOLD as ALERT_EVALUATION_THRESHOLD_TYPED,
ALERT_EVALUATION_VALUE as ALERT_EVALUATION_VALUE_TYPED,
Expand All @@ -19,33 +18,36 @@ import {
ALERT_REASON as ALERT_REASON_NON_TYPED,
// @ts-expect-error
} from '@kbn/rule-data-utils/target_node/technical_field_names';
import { SearchAggregatedTransactionSetting } from '../../../common/aggregated_transactions';
import { take } from 'rxjs/operators';
import { asDuration } from '../../../../observability/common/utils/formatters';
import { createLifecycleRuleTypeFactory } from '../../../../rule_registry/server';
import {
getEnvironmentLabel,
getEnvironmentEsField,
} from '../../../common/environment_filter_values';
import { SearchAggregatedTransactionSetting } from '../../../common/aggregated_transactions';
import {
AlertType,
APM_SERVER_FEATURE_ID,
ALERT_TYPES_CONFIG,
APM_SERVER_FEATURE_ID,
formatTransactionDurationReason,
} from '../../../common/alert_types';
import {
PROCESSOR_EVENT,
SERVICE_NAME,
TRANSACTION_DURATION,
TRANSACTION_TYPE,
} from '../../../common/elasticsearch_fieldnames';
import {
getEnvironmentEsField,
getEnvironmentLabel,
} from '../../../common/environment_filter_values';
import { ProcessorEvent } from '../../../common/processor_event';
import { getDurationFormatter } from '../../../common/utils/formatters';
import { environmentQuery } from '../../../common/utils/environment_query';
import { getDurationFormatter } from '../../../common/utils/formatters';
import {
getDocumentTypeFilterForAggregatedTransactions,
getTransactionDurationFieldForAggregatedTransactions,
} from '../helpers/aggregated_transactions';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import { apmActionVariables } from './action_variables';
import { alertingEsClient } from './alerting_es_client';
import { RegisterRuleDependencies } from './register_apm_alerts';
import { getDocumentTypeFilterForAggregatedTransactions } from '../helpers/aggregated_transactions';

const ALERT_EVALUATION_THRESHOLD: typeof ALERT_EVALUATION_THRESHOLD_TYPED = ALERT_EVALUATION_THRESHOLD_NON_TYPED;
const ALERT_EVALUATION_VALUE: typeof ALERT_EVALUATION_VALUE_TYPED = ALERT_EVALUATION_VALUE_NON_TYPED;
Expand Down Expand Up @@ -118,6 +120,10 @@ export function registerTransactionDurationAlertType({
? indices['apm_oss.metricsIndices']
: indices['apm_oss.transactionIndices'];

const field = getTransactionDurationFieldForAggregatedTransactions(
searchAggregatedTransactions
);

const searchParams = {
index,
body: {
Expand Down Expand Up @@ -148,10 +154,10 @@ export function registerTransactionDurationAlertType({
aggs: {
latency:
alertParams.aggregationType === 'avg'
? { avg: { field: TRANSACTION_DURATION } }
? { avg: { field } }
: {
percentiles: {
field: TRANSACTION_DURATION,
field,
percents: [
alertParams.aggregationType === '95th' ? 95 : 99,
],
Expand Down

0 comments on commit bebf6bf

Please sign in to comment.