Change kibana.alert.evaluation.threshold unit to microseconds (#158703)

Resolves #156255
Fixes #158204
Partially reverts #154801

[RFC
Document](https://docs.google.com/document/d/1-O6-nqOedrjtTF9mHawd_u-vUdXu06KGI8ic5qNeQPQ/edit?usp=sharing)

## Summary

This PR changes kibana.alert.evaluation.threshold unit to microseconds
in AAD.

|Case|Screenshot|
|----|---|
|Saved value in
AAD|![image](9178031b-a187-4b3e-b6ed-6e67f4e708ce)|
|Should show correct information in
flyout|![image](75ec6664-8e2f-448d-b6d0-dacf01b22ac3)|
|Should show correct information on alert details
page|![image](4fb4b645-b450-48da-bec9-e7064b26258e)|
|Should show correct information in action
message|![image](c103266e-25ef-4c25-a0da-c6ecfd0e4c0a)|
|Same unit for value and threshold in the alert
table|![image](499814bc-9f41-4b94-9b03-18a75a50489f)|


## 🧪 How to test
- Generate an APM Latency threshold alert
- Check the threshold in
    - Alert's flyout
    - Alert's table
    - Alert details page (summary and chart)
    - Action generated by this alert
This commit is contained in:
Maryam Saeidi 2023-06-01 13:12:21 +02:00 committed by GitHub
parent 81b9bd2d90
commit d13f884ec3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 16 deletions

View file

@ -21,7 +21,6 @@ import React, { useEffect, useMemo } from 'react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { getPaddedAlertTimeRange } from '@kbn/observability-alert-details';
import { EuiCallOut } from '@elastic/eui';
import { toMicroseconds as toMicrosecondsUtil } from '../../../../../common/utils/formatters';
import { SERVICE_ENVIRONMENT } from '../../../../../common/es_fields/apm';
import { ChartPointerEventContextProvider } from '../../../../context/chart_pointer_event/chart_pointer_event_context';
import { TimeRangeMetadataContextProvider } from '../../../../context/time_range_metadata/time_range_metadata_context';
@ -37,9 +36,6 @@ import {
TRANSACTION_TYPE,
} from './types';
const toMicroseconds = (value?: number) =>
value ? toMicrosecondsUtil(value, 'milliseconds') : value;
export function AlertDetailsAppSection({
rule,
alert,
@ -69,7 +65,7 @@ export function AlertDetailsAppSection({
),
value: formatAlertEvaluationValue(
alert?.fields[ALERT_RULE_TYPE_ID],
toMicroseconds(alert?.fields[ALERT_EVALUATION_THRESHOLD])
alert?.fields[ALERT_EVALUATION_THRESHOLD]
),
},
{

View file

@ -280,7 +280,7 @@ export function registerTransactionDurationRuleType({
[TRANSACTION_NAME]: ruleParams.transactionName,
[PROCESSOR_EVENT]: ProcessorEvent.transaction,
[ALERT_EVALUATION_VALUE]: transactionDuration,
[ALERT_EVALUATION_THRESHOLD]: ruleParams.threshold,
[ALERT_EVALUATION_THRESHOLD]: thresholdMicroseconds,
[ALERT_REASON]: reason,
...sourceFields,
...groupByFields,

View file

@ -30,7 +30,7 @@ import { AlertLifecycleStatusBadge } from '@kbn/alerts-ui-shared';
import moment from 'moment-timezone';
import { useUiSetting } from '@kbn/kibana-react-plugin/public';
import { useKibana } from '../../utils/kibana_react';
import { asDuration, toMicroseconds } from '../../../common/utils/formatters';
import { asDuration } from '../../../common/utils/formatters';
import { paths } from '../../config/paths';
import { translations } from '../../config/translations';
import { formatAlertEvaluationValue } from '../../utils/format_alert_evaluation_value';
@ -42,14 +42,6 @@ interface FlyoutProps {
id?: string;
}
// For APM Latency threshold rule, threshold is in ms but the duration formatter works with microseconds
const normalizeUnit = (ruleTypeId: string, value?: number) => {
if (ruleTypeId === 'apm.transaction_duration' && value) {
return toMicroseconds(value, 'milliseconds');
}
return value;
};
export function AlertsFlyoutBody({ alert, id: pageId }: FlyoutProps) {
const {
http: {
@ -97,7 +89,7 @@ export function AlertsFlyoutBody({ alert, id: pageId }: FlyoutProps) {
title: translations.alertsFlyout.expectedValueLabel,
description: formatAlertEvaluationValue(
alert.fields[ALERT_RULE_TYPE_ID],
normalizeUnit(alert.fields[ALERT_RULE_TYPE_ID], alert.fields[ALERT_EVALUATION_THRESHOLD])
alert.fields[ALERT_EVALUATION_THRESHOLD]
),
},
{