mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[RAC][Uptime] remove moment and use shared o11y utility to format duration… (#123995)
* [RAC][Uptime] remove moment and use shared utility to format duration in alert reason message * fix typescript errors Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
0ea5d02648
commit
5c912ecee8
2 changed files with 4 additions and 24 deletions
|
@ -5,8 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
import { min } from 'lodash';
|
||||
import * as moment from 'moment';
|
||||
import momentDurationFormatSetup from 'moment-duration-format';
|
||||
import datemath from '@elastic/datemath';
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
@ -32,13 +30,12 @@ import {
|
|||
GetMonitorStatusResult,
|
||||
GetMonitorDownStatusMessageParams,
|
||||
getMonitorDownStatusMessageParams,
|
||||
getInterval,
|
||||
} from '../requests/get_monitor_status';
|
||||
import { UNNAMED_LOCATION } from '../../../common/constants';
|
||||
import { getUptimeIndexPattern, IndexPatternTitleAndFields } from '../requests/get_index_pattern';
|
||||
import { UMServerLibs, UptimeESClient, createUptimeESClient } from '../lib';
|
||||
import { ActionGroupIdsOf } from '../../../../alerting/common';
|
||||
momentDurationFormatSetup(moment);
|
||||
import { formatDurationFromTimeUnitChar, TimeUnitChar } from '../../../../observability/common';
|
||||
|
||||
export type ActionGroupIds = ActionGroupIdsOf<typeof MONITOR_STATUS>;
|
||||
/**
|
||||
|
@ -189,7 +186,7 @@ export const getStatusMessage = (
|
|||
availabilityMessage = statusCheckTranslations.availabilityBreachLabel(
|
||||
(availMonInfo.availabilityRatio! * 100).toFixed(2),
|
||||
availability?.threshold!,
|
||||
getInterval(availability?.range!, availability?.rangeUnit!)
|
||||
formatDurationFromTimeUnitChar(availability?.range!, availability?.rangeUnit! as TimeUnitChar)
|
||||
);
|
||||
}
|
||||
if (availMonInfo && downMonParams?.info) {
|
||||
|
|
|
@ -8,15 +8,13 @@
|
|||
import { JsonObject } from '@kbn/utility-types';
|
||||
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { PromiseType } from 'utility-types';
|
||||
import * as moment from 'moment';
|
||||
import momentDurationFormatSetup from 'moment-duration-format';
|
||||
import { asMutableArray } from '../../../common/utils/as_mutable_array';
|
||||
import { UMElasticsearchQueryFn } from '../adapters';
|
||||
import { Ping } from '../../../common/runtime_types/ping';
|
||||
import { createEsQuery } from '../../../common/utils/es_search';
|
||||
import { UptimeESClient } from '../lib';
|
||||
import { UNNAMED_LOCATION } from '../../../common/constants';
|
||||
momentDurationFormatSetup(moment);
|
||||
import { formatDurationFromTimeUnitChar, TimeUnitChar } from '../../../../observability/common';
|
||||
|
||||
export interface GetMonitorStatusParams {
|
||||
filters?: JsonObject;
|
||||
|
@ -34,21 +32,6 @@ export interface GetMonitorStatusResult {
|
|||
monitorInfo: Ping;
|
||||
}
|
||||
|
||||
export const getInterval = (timerangeCount: number, timerangeUnit: string): string => {
|
||||
switch (timerangeUnit) {
|
||||
case 's':
|
||||
return moment.duration(timerangeCount, 'seconds').format('s [sec]');
|
||||
case 'm':
|
||||
return moment.duration(timerangeCount, 'minutes').format('m [min]');
|
||||
case 'h':
|
||||
return moment.duration(timerangeCount, 'hours').format('h [hr]');
|
||||
case 'd':
|
||||
return moment.duration(timerangeCount, 'days').format('d [day]');
|
||||
default:
|
||||
return `${timerangeCount} ${timerangeUnit}`;
|
||||
}
|
||||
};
|
||||
|
||||
export interface GetMonitorDownStatusMessageParams {
|
||||
info: Ping;
|
||||
count: number;
|
||||
|
@ -69,7 +52,7 @@ export const getMonitorDownStatusMessageParams = (
|
|||
count,
|
||||
interval: oldVersionTimeRange
|
||||
? oldVersionTimeRange.from.slice(-3)
|
||||
: getInterval(timerangeCount, timerangeUnit),
|
||||
: formatDurationFromTimeUnitChar(timerangeCount, timerangeUnit as TimeUnitChar),
|
||||
numTimes,
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue