Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Replace Locale.US with Locale.ROOT
Browse files Browse the repository at this point in the history
  • Loading branch information
kaituo committed Jan 29, 2021
1 parent bb09144 commit f0aeb7d
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ protected InitProgressProfile computeInitProgressProfile(long totalUpdates, long
int neededPoints = (int) (requiredSamples - totalUpdates);
return new InitProgressProfile(
// rounding: 93.456 => 93%, 93.556 => 94%
// Without Locale.US, sometimes conversions use localized decimal digits
// Without Locale.ROOT, sometimes conversions use localized decimal digits
// rather than the usual ASCII digits. See https://tinyurl.com/y5sdr5tp
String.format(Locale.US, "%.0f%%", percent),
String.format(Locale.ROOT, "%.0f%%", percent),
intervalMins * neededPoints,
neededPoints
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void executeDetector(AnomalyDetector detector, Instant startTime, Instant
new MultiResponsesDelegateActionListener<EntityAnomalyResult>(
entityAnomalyResultListener,
entities.size(),
String.format(Locale.US, "Fail to get preview result for multi entity detector %s", detector.getDetectorId()),
String.format(Locale.ROOT, "Fail to get preview result for multi entity detector %s", detector.getDetectorId()),
true
);
for (Entity entity : entities) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public Optional<Entry<double[][], Integer>> getFeaturesForSampledPeriods(
Map<Long, double[]> cache = new HashMap<>();
int currentStride = maxStride;
Optional<double[][]> features = Optional.empty();
logger.info(String.format(Locale.US, "Getting features for detector %s starting %d", detector.getDetectorId(), endTime));
logger.info(String.format(Locale.ROOT, "Getting features for detector %s starting %d", detector.getDetectorId(), endTime));
while (currentStride >= 1) {
boolean isInterpolatable = currentStride < maxStride;
features = getFeaturesForSampledPeriods(detector, maxSamples, currentStride, endTime, cache, isInterpolatable);
Expand Down Expand Up @@ -513,7 +513,7 @@ public void getFeaturesForSampledPeriods(
ActionListener<Optional<Entry<double[][], Integer>>> listener
) {
Map<Long, double[]> cache = new HashMap<>();
logger.info(String.format(Locale.US, "Getting features for detector %s ending at %d", detector.getDetectorId(), endTime));
logger.info(String.format(Locale.ROOT, "Getting features for detector %s ending at %d", detector.getDetectorId(), endTime));
getFeatureSamplesWithCache(detector, maxSamples, maxStride, endTime, cache, maxStride, listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private void onCheckpointNotExist(Map<String, Object> source, String modelId, bo
saveModelCheckpointSync(source, modelId);
}
} else {
logger.error(String.format(Locale.US, "Unexpected error creating index %s", indexName), exception);
logger.error(String.format(Locale.ROOT, "Unexpected error creating index %s", indexName), exception);
}
}));
}
Expand Down Expand Up @@ -272,7 +272,7 @@ public void flush() {
// It is possible the index has been created while we sending the create request
flush(bulkRequest);
} else {
logger.error(String.format(Locale.US, "Unexpected error creating index %s", indexName), exception);
logger.error(String.format(Locale.ROOT, "Unexpected error creating index %s", indexName), exception);
}
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public List<ModelState<?>> getAllModels() {
*/
@Deprecated
public void stopModel(String detectorId, String modelId) {
logger.info(String.format(Locale.US, "Stopping detector %s model %s", detectorId, modelId));
logger.info(String.format(Locale.ROOT, "Stopping detector %s model %s", detectorId, modelId));
stopModel(forests, modelId, this::toCheckpoint);
stopModel(thresholds, modelId, this::toCheckpoint);
}
Expand All @@ -458,7 +458,7 @@ private <T> void stopModel(Map<String, ModelState<T>> models, String modelId, Fu
* @param listener onResponse is called with null when the operation is completed
*/
public void stopModel(String detectorId, String modelId, ActionListener<Void> listener) {
logger.info(String.format(Locale.US, "Stopping detector %s model %s", detectorId, modelId));
logger.info(String.format(Locale.ROOT, "Stopping detector %s model %s", detectorId, modelId));
stopModel(
forests,
modelId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Entry<Integer, Integer> getPartitionedForestSizes(RandomCutForest forest,
* @return ID for the RCF model partition
*/
public String getRcfModelId(String detectorId, int partitionNumber) {
return String.format(Locale.US, RCF_MODEL_ID_PATTERN, detectorId, partitionNumber);
return String.format(Locale.ROOT, RCF_MODEL_ID_PATTERN, detectorId, partitionNumber);
}

/**
Expand All @@ -144,6 +144,6 @@ public String getRcfModelId(String detectorId, int partitionNumber) {
* @return ID for the thresholding model
*/
public String getThresholdModelId(String detectorId) {
return String.format(Locale.US, THRESHOLD_MODEL_ID_PATTERN, detectorId);
return String.format(Locale.ROOT, THRESHOLD_MODEL_ID_PATTERN, detectorId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public List<RestHandler.Route> routes() {
// get if a detector name exists with name
new RestHandler.Route(
RestRequest.Method.GET,
String.format(Locale.US, "%s/%s", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, MATCH)
String.format(Locale.ROOT, "%s/%s", AnomalyDetectorPlugin.AD_BASE_DETECTORS_URI, MATCH)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,13 @@ private void validateCategoricalField(String detectorId) {
}

if (foundField == false) {
listener.onFailure(new IllegalArgumentException(String.format(Locale.US, NOT_FOUND_ERR_MSG, categoryField0)));
listener.onFailure(new IllegalArgumentException(String.format(Locale.ROOT, NOT_FOUND_ERR_MSG, categoryField0)));
return;
}

searchAdInputIndices(detectorId);
}, error -> {
String message = String.format(Locale.US, "Fail to get the index mapping of %s", anomalyDetector.getIndices());
String message = String.format(Locale.ROOT, "Fail to get the index mapping of %s", anomalyDetector.getIndices());
logger.error(message, error);
listener.onFailure(new IllegalArgumentException(message));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private void addResult(BulkRequest bulkRequest, AnomalyResult result) {
IndexRequest indexRequest = new IndexRequest(indexName).source(result.toXContent(builder, RestHandlerUtils.XCONTENT_WITH_TYPE));
bulkRequest.add(indexRequest);
} catch (IOException e) {
LOG.error(String.format(Locale.US, "Failed to prepare bulk %s", indexName), e);
LOG.error(String.format(Locale.ROOT, "Failed to prepare bulk %s", indexName), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ private boolean shouldStart(
}

if (stateManager.isMuted(thresholdNodeId)) {
listener.onFailure(new InternalFailure(adID, String.format(Locale.US, NODE_UNRESPONSIVE_ERR_MSG + " %s", thresholdModelID)));
listener.onFailure(new InternalFailure(adID, String.format(Locale.ROOT, NODE_UNRESPONSIVE_ERR_MSG + " %s", thresholdModelID)));
return false;
}

Expand Down Expand Up @@ -1060,7 +1060,7 @@ private Optional<AnomalyDetectionException> coldStartIfNoCheckPoint(AnomalyDetec
LOG.info("Trigger cold start for {}", detectorId);
coldStart(detector);
} else {
String errorMsg = String.format(Locale.US, "Fail to get checkpoint state for %s", detectorId);
String errorMsg = String.format(Locale.ROOT, "Fail to get checkpoint state for %s", detectorId);
LOG.error(errorMsg, exception);
stateManager.setLastColdStartException(detectorId, new AnomalyDetectionException(errorMsg, exception));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public String executor() {
}
);
} catch (Exception e) {
LOG.error(String.format(Locale.US, "Fail to get entity profile for detector {}, entity {}", adID, entityValue), e);
LOG.error(String.format(Locale.ROOT, "Fail to get entity profile for detector {}, entity {}", adID, entityValue), e);
listener.onFailure(new AnomalyDetectionException(adID, FAIL_TO_GET_ENTITY_PROFILE_MSG, e));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public String executor() {

});
} catch (Exception e) {
LOG.error(String.format(Locale.US, "Fail to poll RCF models for {}", adID), e);
LOG.error(String.format(Locale.ROOT, "Fail to poll RCF models for {}", adID), e);
listener.onFailure(new AnomalyDetectionException(adID, FAIL_TO_GET_RCF_UPDATE_MSG, e));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void index(T toSave, String detectorId) {
} else {
throw new AnomalyDetectionException(
detectorId,
String.format(Locale.US, "Unexpected error creating index %s", indexName),
String.format(Locale.ROOT, "Unexpected error creating index %s", indexName),
exception
);
}
Expand All @@ -156,7 +156,7 @@ private void onCreateIndexResponse(CreateIndexResponse response, T toSave, Strin
} else {
throw new AnomalyDetectionException(
detectorId,
String.format(Locale.US, "Creating %s with mappings call not acknowledged.", indexName)
String.format(Locale.ROOT, "Creating %s with mappings call not acknowledged.", indexName)
);
}
}
Expand All @@ -170,8 +170,8 @@ protected void save(T toSave, String detectorId) {

saveIteration(indexRequest, detectorId, savingBackoffPolicy.iterator());
} catch (Exception e) {
LOG.error(String.format(Locale.US, "Failed to save %s", indexName), e);
throw new AnomalyDetectionException(detectorId, String.format(Locale.US, "Cannot save %s", indexName));
LOG.error(String.format(Locale.ROOT, "Failed to save %s", indexName), e);
throw new AnomalyDetectionException(detectorId, String.format(Locale.ROOT, "Cannot save %s", indexName));
}
}

Expand All @@ -182,7 +182,7 @@ void saveIteration(IndexRequest indexRequest, String detectorId, Iterator<TimeVa
client::index,
ActionListener
.<IndexResponse>wrap(
response -> { LOG.debug(String.format(Locale.US, SUCCESS_SAVING_MSG, detectorId)); },
response -> { LOG.debug(String.format(Locale.ROOT, SUCCESS_SAVING_MSG, detectorId)); },
exception -> {
// Elasticsearch has a thread pool and a queue for write per node. A thread
// pool will have N number of workers ready to handle the requests. When a
Expand All @@ -198,10 +198,10 @@ void saveIteration(IndexRequest indexRequest, String detectorId, Iterator<TimeVa
// with randomized exponential backoff.
Throwable cause = ExceptionsHelper.unwrapCause(exception);
if (!(cause instanceof EsRejectedExecutionException) || !backoff.hasNext()) {
LOG.error(String.format(Locale.US, FAIL_TO_SAVE_ERR_MSG, detectorId), cause);
LOG.error(String.format(Locale.ROOT, FAIL_TO_SAVE_ERR_MSG, detectorId), cause);
} else {
TimeValue nextDelay = backoff.next();
LOG.warn(String.format(Locale.US, RETRY_SAVING_ERR_MSG, detectorId), cause);
LOG.warn(String.format(Locale.ROOT, RETRY_SAVING_ERR_MSG, detectorId), cause);
// copy original request's source without other information like autoGeneratedTimestamp
// otherwise, an exception will be thrown indicating autoGeneratedTimestamp should not be set
// while request id is already set (id is set because we have already sent the request before).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void flush(ADResultBulkRequest currentBulkRequest, String detectorId) {
} else {
throw new AnomalyDetectionException(
detectorId,
String.format(Locale.US, "Unexpected error creating index %s", indexName),
String.format(Locale.ROOT, "Unexpected error creating index %s", indexName),
exception
);
}
Expand Down Expand Up @@ -167,8 +167,8 @@ private void bulk(ADResultBulkRequest currentBulkRequest, String detectorId) {
ADResultBulkAction.INSTANCE,
currentBulkRequest,
ActionListener
.<BulkResponse>wrap(response -> LOG.debug(String.format(Locale.US, SUCCESS_SAVING_MSG, detectorId)), exception -> {
LOG.error(String.format(Locale.US, FAIL_TO_SAVE_ERR_MSG, detectorId), exception);
.<BulkResponse>wrap(response -> LOG.debug(String.format(Locale.ROOT, SUCCESS_SAVING_MSG, detectorId)), exception -> {
LOG.error(String.format(Locale.ROOT, FAIL_TO_SAVE_ERR_MSG, detectorId), exception);
Throwable cause = Throwables.getRootCause(exception);
// too much indexing pressure
// TODO: pause indexing a bit before trying again, ideally with randomized exponential backoff.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void onFailure(Exception e) {
private void finish() {
if (this.returnOnPartialResults || this.exceptions.size() == 0) {
if (this.exceptions.size() > 0) {
LOG.error(String.format(Locale.US, "Although returning result, there exists exceptions: %s", this.exceptions));
LOG.error(String.format(Locale.ROOT, "Although returning result, there exists exceptions: %s", this.exceptions));
}
handleSavedResponses();
} else {
Expand Down

0 comments on commit f0aeb7d

Please sign in to comment.