Skip to content

Commit 1cb81b5

Browse files
[7.x] [Metrics UI] Display No Data context.values as [NO DATA] (#78038) (#79161)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 383c3bf commit 1cb81b5

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ export const FIRED_ACTIONS = {
148148

149149
const formatMetric = (metric: SnapshotMetricType, value: number) => {
150150
const metricFormatter = get(METRIC_FORMATTERS, metric, METRIC_FORMATTERS.count);
151-
if (value == null) {
152-
return '';
151+
if (isNaN(value)) {
152+
return i18n.translate('xpack.infra.metrics.alerting.inventory.noDataFormattedValue', {
153+
defaultMessage: '[NO DATA]',
154+
});
153155
}
154156
const formatter = createFormatter(metricFormatter.formatter, metricFormatter.template);
155157
return formatter(value);

x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,24 @@ const formatAlertResult = <AlertResult>(
131131
} & AlertResult
132132
) => {
133133
const { metric, currentValue, threshold } = alertResult;
134-
if (!metric.endsWith('.pct')) return alertResult;
134+
const noDataValue = i18n.translate(
135+
'xpack.infra.metrics.alerting.threshold.noDataFormattedValue',
136+
{
137+
defaultMessage: '[NO DATA]',
138+
}
139+
);
140+
if (!metric.endsWith('.pct'))
141+
return {
142+
...alertResult,
143+
currentValue: currentValue ?? noDataValue,
144+
};
135145
const formatter = createFormatter('percent');
136146
return {
137147
...alertResult,
138-
currentValue: formatter(currentValue),
148+
currentValue:
149+
currentValue !== null && typeof currentValue !== 'undefined'
150+
? formatter(currentValue)
151+
: noDataValue,
139152
threshold: Array.isArray(threshold) ? threshold.map((v: number) => formatter(v)) : threshold,
140153
};
141154
};

0 commit comments

Comments
 (0)