From 4ad4706340a721b2dc18d220340c19e7bf13f254 Mon Sep 17 00:00:00 2001 From: Kaituo Li Date: Wed, 6 Jan 2021 17:07:19 -0800 Subject: [PATCH] Fix log messages and init progress for the profile API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR fixes incorrect or unnecessary log messages.  The PR also specifies init progress to use ASCII explicitly.  Otherwise, it is possible we may get unexpected characters. Testing done: 1. gradle build --- .../ad/AbstractProfileRunner.java | 6 +++++- .../opendistroforelasticsearch/ad/EntityProfileRunner.java | 7 ++++++- .../ad/transport/EntityProfileTransportAction.java | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/AbstractProfileRunner.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AbstractProfileRunner.java index b639b206..74715e8a 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/AbstractProfileRunner.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/AbstractProfileRunner.java @@ -15,6 +15,8 @@ package com.amazon.opendistroforelasticsearch.ad; +import java.util.Locale; + import com.amazon.opendistroforelasticsearch.ad.model.InitProgressProfile; public abstract class AbstractProfileRunner { @@ -29,7 +31,9 @@ protected InitProgressProfile computeInitProgressProfile(long totalUpdates, long int neededPoints = (int) (requiredSamples - totalUpdates); return new InitProgressProfile( // rounding: 93.456 => 93%, 93.556 => 94% - String.format("%.0f%%", percent), + // Without Locale.US, sometimes conversions use localized decimal digits + // rather than the usual ASCII digits. See https://tinyurl.com/y5sdr5tp + String.format(Locale.US, "%.0f%%", percent), intervalMins * neededPoints, neededPoints ); diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/EntityProfileRunner.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/EntityProfileRunner.java index 43a5fdc7..fb51ad47 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/EntityProfileRunner.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/EntityProfileRunner.java @@ -227,8 +227,13 @@ private void getJob( delegateListener.onResponse(builder.build()); }, exception -> { - logger.warn("fail to get last sample time", exception); // sth wrong like result index not created. Return what we have + if (exception instanceof IndexNotFoundException) { + // don't print out stack trace since it is not helpful + logger.info("Result index hasn't been created", exception.getMessage()); + } else { + logger.warn("fail to get last sample time", exception); + } delegateListener.onResponse(builder.build()); })); } diff --git a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/EntityProfileTransportAction.java b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/EntityProfileTransportAction.java index 0aee46f9..56547615 100644 --- a/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/EntityProfileTransportAction.java +++ b/src/main/java/com/amazon/opendistroforelasticsearch/ad/transport/EntityProfileTransportAction.java @@ -118,7 +118,7 @@ protected void doExecute(Task task, EntityProfileRequest request, ActionListener listener.onResponse(builder.build()); } else { // redirect - LOG.debug("Sending RCF polling request to {} for detector {}, entity {}", nodeId, adID, entityValue); + LOG.debug("Sending entity profile request to {} for detector {}, entity {}", nodeId, adID, entityValue); try { transportService