[ML] Fix rare page crash when deleting anomaly detection job (#88622) (#88664)

This commit is contained in:
James Gowdy 2021-01-19 15:14:10 +00:00 committed by GitHub
parent 38606de526
commit 32faf87490
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,7 +15,15 @@ function formatData(txt) {
return numeral(txt).format(DATA_FORMAT); return numeral(txt).format(DATA_FORMAT);
} }
export function formatValues([key, value]) { export function formatValues(obj) {
if (!obj) {
// catch case that formatValues is called without a value.
// caused by very rare race condition when loading jobs list after deleting a job.
return ['', ''];
}
const [key, value] = obj;
// time // time
switch (key) { switch (key) {
case 'finished_time': case 'finished_time':
@ -28,8 +36,7 @@ export function formatValues([key, value]) {
case 'latest_empty_bucket_timestamp': case 'latest_empty_bucket_timestamp':
case 'latest_sparse_bucket_timestamp': case 'latest_sparse_bucket_timestamp':
case 'latest_bucket_timestamp': case 'latest_bucket_timestamp':
value = timeFormatter(value); return [key, timeFormatter(value)];
break;
// data // data
case 'established_model_memory': case 'established_model_memory':
@ -38,8 +45,7 @@ export function formatValues([key, value]) {
case 'model_bytes_exceeded': case 'model_bytes_exceeded':
case 'model_bytes_memory_limit': case 'model_bytes_memory_limit':
case 'peak_model_bytes': case 'peak_model_bytes':
value = formatData(value); return [key, formatData(value)];
break;
// numbers // numbers
case 'processed_record_count': case 'processed_record_count':
@ -57,8 +63,7 @@ export function formatValues([key, value]) {
case 'total_partition_field_count': case 'total_partition_field_count':
case 'bucket_allocation_failures_count': case 'bucket_allocation_failures_count':
case 'search_count': case 'search_count':
value = toLocaleString(value); return [key, toLocaleString(value)];
break;
// numbers rounded to 3 decimal places // numbers rounded to 3 decimal places
case 'average_search_time_per_bucket_ms': case 'average_search_time_per_bucket_ms':
@ -69,13 +74,14 @@ export function formatValues([key, value]) {
case 'average_bucket_processing_time_ms': case 'average_bucket_processing_time_ms':
case 'exponential_average_bucket_processing_time_ms': case 'exponential_average_bucket_processing_time_ms':
case 'exponential_average_bucket_processing_time_per_hour_ms': case 'exponential_average_bucket_processing_time_per_hour_ms':
value = typeof value === 'number' ? roundToDecimalPlace(value, 3).toLocaleString() : value; return [
break; key,
typeof value === 'number' ? roundToDecimalPlace(value, 3).toLocaleString() : value,
];
default: default:
break; return [key, value];
} }
return [key, value];
} }
// utility function to filter child object and arrays out of the supplied object. // utility function to filter child object and arrays out of the supplied object.