From 3641ae72d2bcf106b02c584c82259a673fe9ad0b Mon Sep 17 00:00:00 2001 From: Zacqary Xeper <zacqary.xeper@elastic.co> Date: Mon, 21 Sep 2020 11:43:32 -0500 Subject: [PATCH] [Metrics UI] Display No Data context.values as [NO DATA] --- .../inventory_metric_threshold_executor.ts | 6 ++++-- .../metric_threshold_executor.ts | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts index 99904f15b4606..b56ede1974393 100644 --- a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts @@ -148,8 +148,10 @@ export const FIRED_ACTIONS = { const formatMetric = (metric: SnapshotMetricType, value: number) => { const metricFormatter = get(METRIC_FORMATTERS, metric, METRIC_FORMATTERS.count); - if (value == null) { - return ''; + if (isNaN(value)) { + return i18n.translate('xpack.infra.metrics.alerting.inventory.noDataFormattedValue', { + defaultMessage: '[NO DATA]', + }); } const formatter = createFormatter(metricFormatter.formatter, metricFormatter.template); return formatter(value); diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts index c85685b4cdca8..4dec552c5bd6c 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts @@ -131,11 +131,24 @@ const formatAlertResult = <AlertResult>( } & AlertResult ) => { const { metric, currentValue, threshold } = alertResult; - if (!metric.endsWith('.pct')) return alertResult; + const noDataValue = i18n.translate( + 'xpack.infra.metrics.alerting.threshold.noDataFormattedValue', + { + defaultMessage: '[NO DATA]', + } + ); + if (!metric.endsWith('.pct')) + return { + ...alertResult, + currentValue: currentValue ?? noDataValue, + }; const formatter = createFormatter('percent'); return { ...alertResult, - currentValue: formatter(currentValue), + currentValue: + currentValue !== null && typeof currentValue !== 'undefined' + ? formatter(currentValue) + : noDataValue, threshold: Array.isArray(threshold) ? threshold.map((v: number) => formatter(v)) : threshold, }; };