diff --git a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/PerformanceAnalyzerWebServer.java b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/PerformanceAnalyzerWebServer.java index 9fed8f864..650ebc7ce 100644 --- a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/PerformanceAnalyzerWebServer.java +++ b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/PerformanceAnalyzerWebServer.java @@ -72,7 +72,7 @@ public static HttpServer createInternalServer( LOG.error("Could not create HttpServer on port {}", webServerPort, ex); Runtime.getRuntime().halt(1); } catch (Exception ex) { - ex.printStackTrace(); + LOG.error("Unable to create HttpServer", ex); Runtime.getRuntime().halt(1); } return null; diff --git a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/metrics/handler/MetricsServerHandler.java b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/metrics/handler/MetricsServerHandler.java index 9b95057cf..ddeb479f6 100644 --- a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/metrics/handler/MetricsServerHandler.java +++ b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/metrics/handler/MetricsServerHandler.java @@ -59,7 +59,7 @@ public void collectAPIData( collectStats(db, dbTimestamp, metricList, aggList, dimList, responseObserver); } catch (Exception e) { - e.printStackTrace(); + LOG.error("Exception during collecting API data", e); } } diff --git a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/net/GRPCConnectionManager.java b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/net/GRPCConnectionManager.java index d63f8b979..e08c48ed8 100644 --- a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/net/GRPCConnectionManager.java +++ b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/net/GRPCConnectionManager.java @@ -212,8 +212,7 @@ private ManagedChannel buildSecureChannel(final InstanceDetails remoteHost) { .maxRetryAttempts(MAX_RETRY_ATTEMPTS) .build(); } catch (SSLException e) { - LOG.error("Unable to build an SSL gRPC client. Exception: {}", e.getMessage()); - e.printStackTrace(); + LOG.error("Unable to build an SSL gRPC client.", e); // Wrap the SSL Exception in a generic RTE and re-throw. throw new RuntimeException(e); diff --git a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/RcaController.java b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/RcaController.java index 197129ab9..cf632ed88 100644 --- a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/RcaController.java +++ b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/RcaController.java @@ -367,8 +367,7 @@ private void readRcaEnabledFromConf() { LOG.info("RCA enabled changed from {} to {}", oldVal, newVal); } } catch (IOException e) { - LOG.error("Error reading file '{}': {}", filePath.toString(), e); - e.printStackTrace(); + LOG.error("Error reading file {}", filePath.toString(), e); rcaEnabled = rcaEnabledDefaultValue; } }); diff --git a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/RcaControllerHelper.java b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/RcaControllerHelper.java index 2eaeae399..50ab9852d 100644 --- a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/RcaControllerHelper.java +++ b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/RcaControllerHelper.java @@ -104,8 +104,7 @@ public static String getElectedMasterHostAddress() { return inputLine; } catch (IOException e) { - LOG.error("Could not get the elected master node: {}", e.getMessage()); - e.printStackTrace(); + LOG.error("Could not get the elected master node", e); } return ""; diff --git a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/framework/api/Metric.java b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/framework/api/Metric.java index db9999376..96b202113 100644 --- a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/framework/api/Metric.java +++ b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/framework/api/Metric.java @@ -76,8 +76,7 @@ public MetricFlowUnit gather(Queryable queryable) { PerformanceAnalyzerApp.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( ExceptionsAndErrors.EXCEPTION_IN_GATHER, name(), 1); // TODO: Emit log/stats that gathering failed. - LOG.error("RCA: Caught an exception while getting the DB {}", e.getMessage()); - e.printStackTrace(); + LOG.error("RCA: Caught an exception while getting the DB", e); return MetricFlowUnit.generic(); } try { @@ -94,8 +93,7 @@ public MetricFlowUnit gather(Queryable queryable) { } catch (Exception e) { PerformanceAnalyzerApp.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( ExceptionsAndErrors.EXCEPTION_IN_GATHER, name(), 1); - e.printStackTrace(); - LOG.error("Metric exception: {}", e.getMessage()); + LOG.error("Metric exception:", e); } return MetricFlowUnit.generic(); } diff --git a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/framework/api/Symptom.java b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/framework/api/Symptom.java index d10e918fa..e7dd56d83 100644 --- a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/framework/api/Symptom.java +++ b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/framework/api/Symptom.java @@ -54,7 +54,7 @@ public void generateFlowUnitListFromLocal(FlowUnitOperationArgWrapper args) { } catch (Exception ex) { PerformanceAnalyzerApp.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat( ExceptionsAndErrors.EXCEPTION_IN_OPERATE, name(), 1); - ex.printStackTrace(); + LOG.error("Exception caught during operate", ex); result = SymptomFlowUnit.generic(); } long endTime = System.currentTimeMillis(); diff --git a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/net/handler/PublishRequestHandler.java b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/net/handler/PublishRequestHandler.java index 1dbebc906..74770e307 100644 --- a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/net/handler/PublishRequestHandler.java +++ b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/net/handler/PublishRequestHandler.java @@ -125,10 +125,7 @@ public void onNext(FlowUnitMessage flowUnitMessage) { */ @Override public void onError(Throwable throwable) { - LOG.error( - "Client ran into an error while streaming flow units: {}", - throwable.getMessage()); - throwable.printStackTrace(); + LOG.error("Client ran into an error while streaming flow units:", throwable); } @Override diff --git a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/stats/emitters/PeriodicSamplers.java b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/stats/emitters/PeriodicSamplers.java index 78068b841..d69c42ab6 100644 --- a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/stats/emitters/PeriodicSamplers.java +++ b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/stats/emitters/PeriodicSamplers.java @@ -76,8 +76,8 @@ private void startExceptionHandlingThread() { } catch (Exception ex) { LOG.error( "Resource state poller exception cause : {}", - ex.getCause()); - ex.printStackTrace(); + ex.getCause(), + ex); } } }) diff --git a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/stats/eval/impl/NamedCounter.java b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/stats/eval/impl/NamedCounter.java index 65dd5dbdd..f76c64214 100644 --- a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/stats/eval/impl/NamedCounter.java +++ b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/rca/stats/eval/impl/NamedCounter.java @@ -32,8 +32,12 @@ import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class NamedCounter implements IStatistic { + + private static final Logger LOG = LogManager.getLogger(NamedCounter.class); private boolean empty; private Map counters; @@ -61,7 +65,7 @@ public void calculate(String key, Number value) { counters.put(key, mapValue); empty = false; } catch (Exception ex) { - ex.printStackTrace(); + LOG.error("Caught an exception while calculating the counter value", ex); } } } diff --git a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/reader_writer_shared/EventLogFileHandler.java b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/reader_writer_shared/EventLogFileHandler.java index b08ef5de8..197363b4c 100644 --- a/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/reader_writer_shared/EventLogFileHandler.java +++ b/src/main/java/com/amazon/opendistro/opensearch/performanceanalyzer/reader_writer_shared/EventLogFileHandler.java @@ -99,11 +99,11 @@ public void writeTmpFileWithPrivilege(List dataEntries, long epoch) { writeInternal(out, data); } } catch (IOException e) { - e.printStackTrace(); LOG.error( "Error writing entry '{}'. Cause: {}", currEntry == null ? "NOT_INITIALIZED" : currEntry.key, - e.getMessage()); + e.getMessage(), + e); } } @@ -118,8 +118,7 @@ public void renameFromTmpWithPrivilege(long epoch) { try { Files.move(tmpPath, path, REPLACE_EXISTING, ATOMIC_MOVE); } catch (IOException e) { - e.printStackTrace(); - LOG.error("Error moving file {} to {}.", tmpPath.toString(), path.toString()); + LOG.error("Error moving file {} to {}.", tmpPath.toString(), path.toString(), e); } } @@ -165,7 +164,7 @@ private void readInternal(Path pathToFile, int bufferSize, EventDispatcher proce // TODO: Handle edge case where buffer is too small. } } catch (IOException ex) { - ex.printStackTrace(); + LOG.error("Error reading file", ex); } } }