Skip to content

Commit

Permalink
control-service: include details in error message (#2122)
Browse files Browse the repository at this point in the history
# Why
When the job fails we want to see the error in the failure stacktrace. 
# What
If the result is not 200 we include the response body in the error

# How was this tested
Locally

---------

Signed-off-by: murphp15 <[email protected]>
Co-authored-by: github-actions <>
  • Loading branch information
murphp15 authored May 25, 2023
1 parent 20417fe commit 3bca09a
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;

Expand Down Expand Up @@ -111,12 +112,12 @@ public static void checkDataJobExecutionStatus(
} catch (Error e) {
try {
// print logs in case execution has failed
MvcResult dataJobExecutionLogsResult =
MockHttpServletResponse dataJobExecutionLogsResult =
getExecuteLogs(executionId, jobName, teamName, username, mockMvc);
log.info(
"Job Execution {} logs:\n{}",
executionId,
dataJobExecutionLogsResult.getResponse().getContentAsString());
dataJobExecutionLogsResult.getContentAsString());
} catch (Error ignore) {
}
throw e;
Expand Down Expand Up @@ -280,22 +281,29 @@ public static String generateJobName(String className) {
private static void testDataJobExecutionLogs(
String executionId, String jobName, String teamName, String username, MockMvc mockMvc)
throws Exception {
MvcResult dataJobExecutionLogsResult =
MockHttpServletResponse dataJobExecutionLogsResult =
getExecuteLogs(executionId, jobName, teamName, username, mockMvc);
assertFalse(dataJobExecutionLogsResult.getResponse().getContentAsString().isEmpty());
assertFalse(dataJobExecutionLogsResult.getContentAsString().isEmpty());
}

private static MvcResult getExecuteLogs(
private static MockHttpServletResponse getExecuteLogs(
String executionId, String jobName, String teamName, String username, MockMvc mockMvc)
throws Exception {
String dataJobExecutionListUrl =
String.format(
"/data-jobs/for-team/%s/jobs/%s/executions/%s/logs", teamName, jobName, executionId);
MvcResult dataJobExecutionLogsResult =
MockHttpServletResponse dataJobExecutionLogsResult =
mockMvc
.perform(get(dataJobExecutionListUrl).with(user(username)))
.andExpect(status().isOk())
.andReturn();
.andReturn()
.getResponse();
if (dataJobExecutionLogsResult.getStatus() != 200) {
throw new Exception(
"status is "
+ dataJobExecutionLogsResult.getStatus()
+ "\nbody is "
+ dataJobExecutionLogsResult.getContentAsString());
}
return dataJobExecutionLogsResult;
}

Expand Down

0 comments on commit 3bca09a

Please sign in to comment.