Skip to content

Commit

Permalink
[Metrics UI] Display No Data context.values as [NO DATA]
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Sep 21, 2020
1 parent 5832e97 commit 3641ae7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};

0 comments on commit 3641ae7

Please sign in to comment.