Skip to content

Commit

Permalink
Merge pull request #1070 from khansaad/suppress-sqlException-logs
Browse files Browse the repository at this point in the history
Suppress sqlExceptionError logs from console
  • Loading branch information
dinogun authored Dec 14, 2023
2 parents b9695d4 + 0d75805 commit 26e278a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/autotune/Autotune.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<UpdateResultsAPIObject> myList = (List<UpdateResultsAPIObject>) request.getAttribute("data");
List<FailedUpdateResultsAPIObject> myList = (List<FailedUpdateResultsAPIObject>) request.getAttribute("data");
PrintWriter out = response.getWriter();
Gson gsonObj = new GsonBuilder()
.disableHtmlEscaping()
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,7 +25,7 @@ public class KruizeResponse {
private String documentationLink;
private String status;

private List<UpdateResultsAPIObject> data;
private List<FailedUpdateResultsAPIObject> data;


public KruizeResponse(String message, int httpcode, String documentationLink, String status) {
Expand All @@ -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<UpdateResultsAPIObject> data) {
public KruizeResponse(String message, int httpcode, String documentationLink, String status, List<FailedUpdateResultsAPIObject> data) {
this.message = message;
this.httpcode = httpcode;
this.documentationLink = documentationLink;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public class FailedUpdateResultsAPIObject extends BaseSO {

private List<KruizeResponse> errors;

public List<KruizeResponse> getErrors() {
return errors;
}

public void setErrors(List<KruizeResponse> errors) {
this.errors = errors;
}

public FailedUpdateResultsAPIObject(String version, String experiment_name, Timestamp startTimestamp, Timestamp endTimestamp, List<KruizeResponse> errors) {
this.setApiVersion(version);
this.setExperimentName(experiment_name);
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/autotune/operator/InitializeDeployment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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());
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/autotune/utils/KruizeConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}
Expand Down

0 comments on commit 26e278a

Please sign in to comment.