diff --git a/src/main/java/com/autotune/Autotune.java b/src/main/java/com/autotune/Autotune.java index 029f84ea9..4cdd1f4f5 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,13 @@ public class Autotune { public static void main(String[] args) { + 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; disableServerLogging(); diff --git a/src/main/java/com/autotune/analyzer/exceptions/KruizeErrorHandler.java b/src/main/java/com/autotune/analyzer/exceptions/KruizeErrorHandler.java index f43cf223f..0f7de32a8 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,25 @@ 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); - } + // 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(); } 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); diff --git a/src/main/java/com/autotune/operator/InitializeDeployment.java b/src/main/java/com/autotune/operator/InitializeDeployment.java index 8dd60dd92..9c8d66c66 100644 --- a/src/main/java/com/autotune/operator/InitializeDeployment.java +++ b/src/main/java/com/autotune/operator/InitializeDeployment.java @@ -95,21 +95,21 @@ 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.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() { }