[8.8] [AO] Fix APM latency expected value (#156269) (#156394)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[AO] Fix APM latency expected value
(#156269)](https://github.com/elastic/kibana/pull/156269)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Maryam
Saeidi","email":"maryam.saeidi@elastic.co"},"sourceCommit":{"committedDate":"2023-05-02T14:09:49Z","message":"[AO]
Fix APM latency expected value (#156269)\n\nFixes #154801\r\n\r\n## 📝
Summary \r\nThis PR fixes the expected value of the APM latency rule
both in the\r\nflyout and alert details page.\r\n\r\n|Before|After
1|After
2|\r\n|---|---|---|\r\n\r\n|![image](235477667-438ebd69-3e4d-4e95-88f1-5fc8febf9125.png)|\r\n\r\n\r\n##
🧪 How to test\r\n- Create an APM Latency alert\r\n- Click on the reason
to open the flyout and check the expected value\r\nthere\r\n- From the
action menu of that alert, go to alert details page and check\r\nthe
expected
value","sha":"b5914f4342659abbe168ca4d849d94b6ee24cbf4","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:APM","release_note:skip","Team:
Actionable
Observability","backport:prev-minor","v8.9.0"],"number":156269,"url":"https://github.com/elastic/kibana/pull/156269","mergeCommit":{"message":"[AO]
Fix APM latency expected value (#156269)\n\nFixes #154801\r\n\r\n## 📝
Summary \r\nThis PR fixes the expected value of the APM latency rule
both in the\r\nflyout and alert details page.\r\n\r\n|Before|After
1|After
2|\r\n|---|---|---|\r\n\r\n|![image](235477667-438ebd69-3e4d-4e95-88f1-5fc8febf9125.png)|\r\n\r\n\r\n##
🧪 How to test\r\n- Create an APM Latency alert\r\n- Click on the reason
to open the flyout and check the expected value\r\nthere\r\n- From the
action menu of that alert, go to alert details page and check\r\nthe
expected
value","sha":"b5914f4342659abbe168ca4d849d94b6ee24cbf4"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/156269","number":156269,"mergeCommit":{"message":"[AO]
Fix APM latency expected value (#156269)\n\nFixes #154801\r\n\r\n## 📝
Summary \r\nThis PR fixes the expected value of the APM latency rule
both in the\r\nflyout and alert details page.\r\n\r\n|Before|After
1|After
2|\r\n|---|---|---|\r\n\r\n|![image](235477667-438ebd69-3e4d-4e95-88f1-5fc8febf9125.png)|\r\n\r\n\r\n##
🧪 How to test\r\n- Create an APM Latency alert\r\n- Click on the reason
to open the flyout and check the expected value\r\nthere\r\n- From the
action menu of that alert, go to alert details page and check\r\nthe
expected value","sha":"b5914f4342659abbe168ca4d849d94b6ee24cbf4"}}]}]
BACKPORT-->

Co-authored-by: Maryam Saeidi <maryam.saeidi@elastic.co>
This commit is contained in:
Kibana Machine 2023-05-02 11:21:38 -04:00 committed by GitHub
parent 251123c4bb
commit 7f7062543f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -19,6 +19,7 @@ import {
import moment from 'moment';
import React, { useEffect, useMemo, useState } from 'react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
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';
@ -35,6 +36,9 @@ import {
TRANSACTION_TYPE,
} from './types';
const toMicroseconds = (value?: number) =>
value ? toMicrosecondsUtil(value, 'milliseconds') : value;
export function AlertDetailsAppSection({
rule,
alert,
@ -64,7 +68,7 @@ export function AlertDetailsAppSection({
),
value: formatAlertEvaluationValue(
alert?.fields[ALERT_RULE_TYPE_ID],
alert?.fields[ALERT_EVALUATION_THRESHOLD]
toMicroseconds(alert?.fields[ALERT_EVALUATION_THRESHOLD])
),
},
{

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 } from '../../common/utils/formatters';
import { asDuration, toMicroseconds } from '../../common/utils/formatters';
import { paths } from '../config/paths';
import { translations } from '../config/translations';
import { formatAlertEvaluationValue } from '../utils/format_alert_evaluation_value';
@ -42,6 +42,14 @@ 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: {
@ -89,7 +97,7 @@ export function AlertsFlyoutBody({ alert, id: pageId }: FlyoutProps) {
title: translations.alertsFlyout.expectedValueLabel,
description: formatAlertEvaluationValue(
alert.fields[ALERT_RULE_TYPE_ID],
alert.fields[ALERT_EVALUATION_THRESHOLD]
normalizeUnit(alert.fields[ALERT_RULE_TYPE_ID], alert.fields[ALERT_EVALUATION_THRESHOLD])
),
},
{