Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix][log]Fix log returns interface issue and adds test code #8387

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading