From 9bb7b208e1594f5280fc1751aacfa1edf18bc9a8 Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Fri, 1 Dec 2023 11:59:37 +0530 Subject: [PATCH 1/5] suppress sqlExceptionError logs from console Signed-off-by: Saad Khan --- src/main/java/com/autotune/Autotune.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/autotune/Autotune.java b/src/main/java/com/autotune/Autotune.java index 029f84ea9..8b5f6ec25 100644 --- a/src/main/java/com/autotune/Autotune.java +++ b/src/main/java/com/autotune/Autotune.java @@ -34,6 +34,8 @@ import com.autotune.utils.filter.KruizeCORSFilter; import io.prometheus.client.exporter.MetricsServlet; import io.prometheus.client.hotspot.DefaultExports; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.config.Configurator; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.servlet.ServletContextHandler; @@ -59,6 +61,9 @@ public class Autotune { public static void main(String[] args) { + // Turning off the logging level for the specific package to reduce console logging + Configurator.setLevel("org.hibernate.engine.jdbc.spi", Level.OFF); + ServletContextHandler context = null; disableServerLogging(); From 6a5d4c4bb7bf52b6de6decd7d062833d6d9a485f Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Mon, 4 Dec 2023 14:43:53 +0530 Subject: [PATCH 2/5] change response logs to debug in case of error 409 and related files changes Signed-off-by: Saad Khan --- .../exceptions/KruizeErrorHandler.java | 21 ++++++++++++------- .../analyzer/exceptions/KruizeResponse.java | 6 +++--- .../FailedUpdateResultsAPIObject.java | 8 +++++++ 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/autotune/analyzer/exceptions/KruizeErrorHandler.java b/src/main/java/com/autotune/analyzer/exceptions/KruizeErrorHandler.java index f43cf223f..afe57a00a 100644 --- a/src/main/java/com/autotune/analyzer/exceptions/KruizeErrorHandler.java +++ b/src/main/java/com/autotune/analyzer/exceptions/KruizeErrorHandler.java @@ -15,7 +15,7 @@ *******************************************************************************/ package com.autotune.analyzer.exceptions; -import com.autotune.analyzer.serviceObjects.UpdateResultsAPIObject; +import com.autotune.analyzer.serviceObjects.FailedUpdateResultsAPIObject; import com.autotune.analyzer.utils.GsonUTCDateAdapter; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -50,7 +50,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques response.setCharacterEncoding(CHARACTER_ENCODING); String origMessage = (String) request.getAttribute("javax.servlet.error.message"); int errorCode = response.getStatus(); - List myList = (List) request.getAttribute("data"); + List myList = (List) request.getAttribute("data"); PrintWriter out = response.getWriter(); Gson gsonObj = new GsonBuilder() .disableHtmlEscaping() @@ -59,12 +59,17 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques .create(); String gsonStr = gsonObj.toJson(new KruizeResponse(origMessage, errorCode, "", "ERROR", myList)); - // suppress error in case of duplicate records entry and show errors for all other failed cases. - if (errorCode == HttpServletResponse.SC_CONFLICT) { - LOGGER.debug(gsonStr); - } else { - LOGGER.error(gsonStr); - } + // Log messages based on httpcode + myList.forEach(updateResult -> + updateResult.getErrors().forEach(error -> { + if (error.getHttpcode() == 409) { + LOGGER.debug(gsonObj.toJson(error)); + } else { + LOGGER.error(gsonObj.toJson(error)); + } + }) + ); + out.append(gsonStr); out.flush(); } diff --git a/src/main/java/com/autotune/analyzer/exceptions/KruizeResponse.java b/src/main/java/com/autotune/analyzer/exceptions/KruizeResponse.java index fdd177f5e..4fde55de6 100644 --- a/src/main/java/com/autotune/analyzer/exceptions/KruizeResponse.java +++ b/src/main/java/com/autotune/analyzer/exceptions/KruizeResponse.java @@ -15,7 +15,7 @@ *******************************************************************************/ package com.autotune.analyzer.exceptions; -import com.autotune.analyzer.serviceObjects.UpdateResultsAPIObject; +import com.autotune.analyzer.serviceObjects.FailedUpdateResultsAPIObject; import java.util.List; @@ -25,7 +25,7 @@ public class KruizeResponse { private String documentationLink; private String status; - private List data; + private List data; public KruizeResponse(String message, int httpcode, String documentationLink, String status) { @@ -35,7 +35,7 @@ public KruizeResponse(String message, int httpcode, String documentationLink, St this.status = status; } - public KruizeResponse(String message, int httpcode, String documentationLink, String status, List data) { + public KruizeResponse(String message, int httpcode, String documentationLink, String status, List data) { this.message = message; this.httpcode = httpcode; this.documentationLink = documentationLink; diff --git a/src/main/java/com/autotune/analyzer/serviceObjects/FailedUpdateResultsAPIObject.java b/src/main/java/com/autotune/analyzer/serviceObjects/FailedUpdateResultsAPIObject.java index 4d90f8cc3..29421c16c 100644 --- a/src/main/java/com/autotune/analyzer/serviceObjects/FailedUpdateResultsAPIObject.java +++ b/src/main/java/com/autotune/analyzer/serviceObjects/FailedUpdateResultsAPIObject.java @@ -31,6 +31,14 @@ public class FailedUpdateResultsAPIObject extends BaseSO { private List errors; + public List getErrors() { + return errors; + } + + public void setErrors(List errors) { + this.errors = errors; + } + public FailedUpdateResultsAPIObject(String version, String experiment_name, Timestamp startTimestamp, Timestamp endTimestamp, List errors) { this.setApiVersion(version); this.setExperimentName(experiment_name); From 753fb0537983632f2e0c98e7277ffd6960099220 Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Mon, 4 Dec 2023 16:14:20 +0530 Subject: [PATCH 3/5] minor change to fix response in case of createExp Signed-off-by: Saad Khan --- .../exceptions/KruizeErrorHandler.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/autotune/analyzer/exceptions/KruizeErrorHandler.java b/src/main/java/com/autotune/analyzer/exceptions/KruizeErrorHandler.java index afe57a00a..0f7de32a8 100644 --- a/src/main/java/com/autotune/analyzer/exceptions/KruizeErrorHandler.java +++ b/src/main/java/com/autotune/analyzer/exceptions/KruizeErrorHandler.java @@ -59,17 +59,25 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques .create(); String gsonStr = gsonObj.toJson(new KruizeResponse(origMessage, errorCode, "", "ERROR", myList)); - // Log messages based on httpcode - myList.forEach(updateResult -> - updateResult.getErrors().forEach(error -> { - if (error.getHttpcode() == 409) { - LOGGER.debug(gsonObj.toJson(error)); - } else { - LOGGER.error(gsonObj.toJson(error)); - } - }) - ); - + // suppress error in case of duplicate records entry and show errors for all other failed cases. + // in case of createExp API, data object will be empty so 'myList' will be null + if (myList == null) { + if (errorCode == HttpServletResponse.SC_CONFLICT) { + LOGGER.debug(gsonStr); + } else { + LOGGER.error(gsonStr); + } + } else { + myList.forEach(failedResult -> + failedResult.getErrors().forEach(error -> { + if (error.getHttpcode() == 409) { + LOGGER.debug(gsonObj.toJson(error)); + } else { + LOGGER.error(gsonObj.toJson(error)); + } + }) + ); + } out.append(gsonStr); out.flush(); } From 9227eb4c7d35e1bf49ff5f70c54e2c5df95f9fe0 Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Tue, 5 Dec 2023 10:14:26 +0530 Subject: [PATCH 4/5] suppress config variables exception logs Signed-off-by: Saad Khan --- src/main/java/com/autotune/operator/InitializeDeployment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/autotune/operator/InitializeDeployment.java b/src/main/java/com/autotune/operator/InitializeDeployment.java index 8dd60dd92..2022603e9 100644 --- a/src/main/java/com/autotune/operator/InitializeDeployment.java +++ b/src/main/java/com/autotune/operator/InitializeDeployment.java @@ -111,7 +111,7 @@ else if (deploymentInfoField.getType() == Integer.class) { } else throw new IllegalAccessException("Failed to set " + deploymentInfoField + "due to its type " + deploymentInfoField.getType()); } catch (Exception e) { - LOGGER.warn("Error while setting config variables : {} : {}", e.getClass(), e.getMessage()); + LOGGER.debug("Error while setting config variables : {} : {}", e.getClass(), e.getMessage()); } } } From 99e912b29e5d0b3edca5d1aac6cb6db440a4528c Mon Sep 17 00:00:00 2001 From: Saad Khan Date: Thu, 7 Dec 2023 10:45:10 +0530 Subject: [PATCH 5/5] changes wrt review Signed-off-by: Saad Khan --- src/main/java/com/autotune/Autotune.java | 8 +++++-- .../operator/InitializeDeployment.java | 22 +++++++++---------- .../com/autotune/utils/KruizeConstants.java | 1 + 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/autotune/Autotune.java b/src/main/java/com/autotune/Autotune.java index 8b5f6ec25..4cdd1f4f5 100644 --- a/src/main/java/com/autotune/Autotune.java +++ b/src/main/java/com/autotune/Autotune.java @@ -61,8 +61,12 @@ public class Autotune { public static void main(String[] args) { - // Turning off the logging level for the specific package to reduce console logging - Configurator.setLevel("org.hibernate.engine.jdbc.spi", Level.OFF); + try { + // Turning off the logging level for the specific package to reduce console logging + Configurator.setLevel(KruizeConstants.SQL_EXCEPTION_HELPER_PKG, Level.OFF); + } catch (Exception e) { + LOGGER.error("Exception occurred while turning the Logger off for the SQLException class: {}", e.getMessage()); + } ServletContextHandler context = null; diff --git a/src/main/java/com/autotune/operator/InitializeDeployment.java b/src/main/java/com/autotune/operator/InitializeDeployment.java index 2022603e9..9c8d66c66 100644 --- a/src/main/java/com/autotune/operator/InitializeDeployment.java +++ b/src/main/java/com/autotune/operator/InitializeDeployment.java @@ -95,23 +95,23 @@ private static void setConfigValues(String configFileName, Class envClass) { LOGGER.warn("Failed to set config using file {} due to {}. checking if corresponding environment variable is set.", configFile, exception.getMessage()); } } - List systemENVList = new ArrayList<>(); Field[] fields = envClass.getFields(); for (Field field : fields) { try { Field deploymentInfoField = KruizeDeploymentInfo.class.getDeclaredField(field.getName().toLowerCase(Locale.ROOT)); String deploymentInfoFieldValue = getKruizeConfigValue((String) field.get(null), configObject); - if (deploymentInfoField.getType() == String.class) - deploymentInfoField.set(null, deploymentInfoFieldValue); - else if (deploymentInfoField.getType() == Boolean.class) - deploymentInfoField.set(null, Boolean.parseBoolean(deploymentInfoFieldValue)); - else if (deploymentInfoField.getType() == Integer.class) { - assert deploymentInfoFieldValue != null; - deploymentInfoField.set(null, Integer.parseInt(deploymentInfoFieldValue)); - } else - throw new IllegalAccessException("Failed to set " + deploymentInfoField + "due to its type " + deploymentInfoField.getType()); + if (null != deploymentInfoFieldValue) { + if (deploymentInfoField.getType() == String.class) + deploymentInfoField.set(null, deploymentInfoFieldValue); + else if (deploymentInfoField.getType() == Boolean.class) + deploymentInfoField.set(null, Boolean.parseBoolean(deploymentInfoFieldValue)); + else if (deploymentInfoField.getType() == Integer.class) + deploymentInfoField.set(null, Integer.parseInt(deploymentInfoFieldValue)); + else + throw new IllegalAccessException("Failed to set " + deploymentInfoField + "due to its type " + deploymentInfoField.getType()); + } } catch (Exception e) { - LOGGER.debug("Error while setting config variables : {} : {}", e.getClass(), e.getMessage()); + LOGGER.warn("Error while setting config variables : {} : {}", e.getClass(), e.getMessage()); } } } diff --git a/src/main/java/com/autotune/utils/KruizeConstants.java b/src/main/java/com/autotune/utils/KruizeConstants.java index f11ea8675..42838fba9 100644 --- a/src/main/java/com/autotune/utils/KruizeConstants.java +++ b/src/main/java/com/autotune/utils/KruizeConstants.java @@ -24,6 +24,7 @@ public class KruizeConstants { public static final String MINIKUBE = "minikube"; public static final String OPENSHIFT = "openshift"; public static final String CONFIG_FILE = "KRUIZE_CONFIG_FILE"; + public static final String SQL_EXCEPTION_HELPER_PKG = "org.hibernate.engine.jdbc.spi"; private KruizeConstants() { }