Skip to content

Commit

Permalink
Merge pull request #1201 from shreyabiradar07/add_updateRecomm_log
Browse files Browse the repository at this point in the history
Log updateRecommendations failure message
  • Loading branch information
dinogun committed Jun 18, 2024
2 parents cac92d7 + 9f6562f commit 1167215
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,16 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
statusValue = KruizeConstants.APIMessages.SUCCESS;
} else {
LOGGER.error(String.format(AnalyzerErrorConstants.APIErrors.UpdateRecommendationsAPI.UPDATE_RECOMMENDATIONS_FAILED_COUNT, calCount));
LOGGER.error(String.format(KruizeConstants.APIMessages.UPDATE_RECOMMENDATIONS_FAILURE, experiment_name, intervalEndTimeStr));
sendErrorResponse(response, null, kruizeObject.getValidation_data().getErrorCode(), kruizeObject.getValidation_data().getMessage());
sendErrorResponse(response, null, kruizeObject.getValidation_data().getErrorCode(), kruizeObject.getValidation_data().getMessage(), experiment_name, intervalEndTimeStr);
}
} else {
LOGGER.error(String.format(KruizeConstants.APIMessages.UPDATE_RECOMMENDATIONS_VALIDATION_FAILURE, validationMessage,
experiment_name, intervalEndTimeStr));
sendErrorResponse(response, null, HttpServletResponse.SC_BAD_REQUEST, validationMessage);
sendErrorResponse(response, null, HttpServletResponse.SC_BAD_REQUEST, validationMessage, experiment_name, intervalEndTimeStr);
}

} catch (Exception e) {
LOGGER.error(String.format(AnalyzerErrorConstants.APIErrors.UpdateRecommendationsAPI.UPDATE_RECOMMENDATIONS_FAILED_COUNT, calCount));
LOGGER.error(String.format(AnalyzerErrorConstants.APIErrors.UpdateRecommendationsAPI.RECOMMENDATION_EXCEPTION,
experiment_name, intervalEndTimeStr, e.getMessage()));
e.printStackTrace();
sendErrorResponse(response, e, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
sendErrorResponse(response, e, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), experiment_name, intervalEndTimeStr);
} finally {
LOGGER.debug(String.format(AnalyzerErrorConstants.APIErrors.UpdateRecommendationsAPI.UPDATE_RECOMMENDATIONS_COMPLETED_COUNT, calCount));
if (null != timerBUpdateRecommendations) {
Expand Down Expand Up @@ -180,13 +175,14 @@ public boolean shouldSkipClass(Class<?> clazz) {
response.getWriter().close();
}

public void sendErrorResponse(HttpServletResponse response, Exception e, int httpStatusCode, String errorMsg) throws
IOException {
public void sendErrorResponse(HttpServletResponse response, Exception e, int httpStatusCode, String errorMsg,
String experiment_name, String intervalEndTimeStr) throws IOException {
if (null != e) {
e.printStackTrace();
LOGGER.error(e.toString());
if (null == errorMsg) errorMsg = e.getMessage();
}
LOGGER.error(String.format(KruizeConstants.APIMessages.UPDATE_RECOMMENDATIONS_FAILURE_MSG, experiment_name, intervalEndTimeStr, errorMsg));
response.sendError(httpStatusCode, errorMsg);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/autotune/utils/KruizeConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public static class APIMessages {
public static final String UPDATE_RECOMMENDATIONS_INPUT_PARAMS = "experiment_name : %s and interval_start_time : %s and interval_end_time : %s ";
public static final String UPDATE_RECOMMENDATIONS_SUCCESS = "Update Recommendation API success response, experiment_name: %s and interval_end_time : %s";
public static final String UPDATE_RECOMMENDATIONS_FAILURE = "UpdateRecommendations API failure response, experiment_name: %s and intervalEndTimeStr : %s";
public static final String UPDATE_RECOMMENDATIONS_VALIDATION_FAILURE = "Validation failed: %s for experiment_name: %s and interval_end_time: %s";
public static final String UPDATE_RECOMMENDATIONS_RESPONSE = "Update Recommendation API response: %s";
public static final String UPDATE_RECOMMENDATIONS_FAILURE_MSG = "UpdateRecommendations API failed for experiment_name: %s and intervalEndTimeStr : %s due to %s";
}


Expand Down

0 comments on commit 1167215

Please sign in to comment.