Skip to content

Commit

Permalink
[fix][log]Fix log returns interface issue and adds test code (#8387)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangshenghang authored Dec 27, 2024
1 parent 4af5bdb commit ebe6207
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.seatunnel.engine.e2e.joblog;

import org.apache.seatunnel.common.constants.JobMode;
import org.apache.seatunnel.common.utils.JsonUtils;
import org.apache.seatunnel.e2e.common.util.ContainerUtil;
import org.apache.seatunnel.engine.e2e.SeaTunnelEngineContainer;
import org.apache.seatunnel.engine.server.rest.RestConstant;
Expand Down Expand Up @@ -117,6 +118,8 @@ public void testJobLogFile() throws Exception {

assertConsoleLog();
assertFileLog();
assertLogFormatType();

List<Tuple2<Boolean, String>> before =
Lists.newArrayList(
Tuple2.tuple2(false, "job-" + CUSTOM_JOB_ID + ".log"),
Expand Down Expand Up @@ -160,6 +163,30 @@ private void assertConsoleLog() {
});
}

private void assertLogFormatType() throws IOException, InterruptedException {
final String baseUrl = "curl http://localhost:8080/logs";
final String htmlUrl = baseUrl;
final String jsonUrl = baseUrl + "?format=JSON";
final String expectedHtmlTitle = "<html><head><title>Seatunnel log</title></head>";

// Execute commands and get results for both HTML and JSON logs
Container.ExecResult htmlExecResult = server.execInContainer("sh", "-c", htmlUrl);
Container.ExecResult jsonExecResult = server.execInContainer("sh", "-c", jsonUrl);

// Get the stdout of each execution result
String htmlOutput = htmlExecResult.getStdout();
String jsonOutput = jsonExecResult.getStdout();

// Verify HTML response contains expected title
Assertions.assertTrue(htmlOutput.contains(expectedHtmlTitle));

// Verify JSON response is valid JSON
Assertions.assertDoesNotThrow(
() -> JsonUtils.parseArray(jsonOutput),
"JSON format log list interface exception, returned type is not JSON, content:"
+ jsonOutput);
}

private void assertFileLog() throws IOException, InterruptedException {
String catLog = "cat /tmp/seatunnel/logs/job-862969647010611201.log";
String apiGetLog = "curl http://localhost:8080/log/job-862969647010611201.log";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
FormatType formatType = FormatType.fromString(req.getParameter("format"));
switch (formatType) {
case JSON:
writeJson(resp, logService.allNodeLogFormatHtml(jobId));
writeJson(resp, logService.allNodeLogFormatJson(jobId));
return;
case HTML:
default:
Expand Down

0 comments on commit ebe6207

Please sign in to comment.