Savonitar commented on code in PR #28226:
URL: https://github.com/apache/flink/pull/28226#discussion_r3303381113
##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/application/ApplicationExceptionsHandlerTest.java:
##########
@@ -143,6 +159,116 @@ void testExceptionWithJobId() throws Exception {
assertThat(exceptionInfo.getJobId()).isEqualTo(jobId);
}
+ @Test
+ void testMaxExceptionsLimitsHistorySize() throws Exception {
+ final List<ApplicationExceptionHistoryEntry> exceptionHistory = new
ArrayList<>();
+ for (int i = 0; i < 5; i++) {
+ exceptionHistory.add(
+ new ApplicationExceptionHistoryEntry(
+ new RuntimeException("exception #" + i),
+ System.currentTimeMillis(),
+ null));
+ }
+
+ final ArchivedApplication applicationWithExceptions =
+ new ArchivedApplication(
+ archivedApplication.getApplicationId(),
+ archivedApplication.getApplicationName(),
+ ApplicationState.FAILED,
+ new long[] {1L, 1L, 1L, 1L, 1L, 1L, 1L},
+ Collections.emptyMap(),
+ exceptionHistory);
+
+ testingRestfulGateway =
+ new TestingRestfulGateway.Builder()
+ .setRequestApplicationFunction(
+ applicationId ->
+ CompletableFuture.completedFuture(
+ applicationWithExceptions))
+ .build();
+
+ final HandlerRequest<EmptyRequestBody> limitedRequest =
+ createRequest(archivedApplication.getApplicationId(), 2);
+
+ final ApplicationExceptionsInfoWithHistory response =
+ handler.handleRequest(limitedRequest,
testingRestfulGateway).get();
+
+ assertThat(response.getExceptionHistory().getEntries()).hasSize(2);
+ }
+
+ @Test
+ void testDefaultCapAppliedWhenMaxExceptionsNotProvided() throws Exception {
+ final int totalExceptions =
ApplicationExceptionsHandler.MAX_NUMBER_EXCEPTION_TO_REPORT + 5;
+ final List<ApplicationExceptionHistoryEntry> exceptionHistory = new
ArrayList<>();
+ for (int i = 0; i < totalExceptions; i++) {
+ exceptionHistory.add(
+ new ApplicationExceptionHistoryEntry(
+ new RuntimeException("exception #" + i),
+ System.currentTimeMillis(),
+ null));
+ }
+
+ final ArchivedApplication applicationWithExceptions =
+ new ArchivedApplication(
+ archivedApplication.getApplicationId(),
+ archivedApplication.getApplicationName(),
+ ApplicationState.FAILED,
+ new long[] {1L, 1L, 1L, 1L, 1L, 1L, 1L},
+ Collections.emptyMap(),
+ exceptionHistory);
+
+ testingRestfulGateway =
+ new TestingRestfulGateway.Builder()
+ .setRequestApplicationFunction(
+ applicationId ->
+ CompletableFuture.completedFuture(
+ applicationWithExceptions))
+ .build();
+
+ final ApplicationExceptionsInfoWithHistory response =
+ handler.handleRequest(handlerRequest,
testingRestfulGateway).get();
+
+ assertThat(response.getExceptionHistory().getEntries())
+
.hasSize(ApplicationExceptionsHandler.MAX_NUMBER_EXCEPTION_TO_REPORT);
+ }
+
+ @Test
+ void testMaxExceptionsLargerThanHistorySizeReturnsAllEntries() throws
Exception {
+ final List<ApplicationExceptionHistoryEntry> exceptionHistory = new
ArrayList<>();
+ for (int i = 0; i < 3; i++) {
Review Comment:
nit: the loop iterates `i < 3` and the assertion is `.hasSize(3)` these are
two independent literals that are conceptually the same value. Maybe we can
extract this to a variable with a meaningful name.
##########
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/application/ApplicationExceptionsHandlerTest.java:
##########
@@ -143,6 +159,116 @@ void testExceptionWithJobId() throws Exception {
assertThat(exceptionInfo.getJobId()).isEqualTo(jobId);
}
+ @Test
+ void testMaxExceptionsLimitsHistorySize() throws Exception {
+ final List<ApplicationExceptionHistoryEntry> exceptionHistory = new
ArrayList<>();
+ for (int i = 0; i < 5; i++) {
+ exceptionHistory.add(
+ new ApplicationExceptionHistoryEntry(
+ new RuntimeException("exception #" + i),
+ System.currentTimeMillis(),
+ null));
+ }
+
+ final ArchivedApplication applicationWithExceptions =
+ new ArchivedApplication(
+ archivedApplication.getApplicationId(),
+ archivedApplication.getApplicationName(),
+ ApplicationState.FAILED,
+ new long[] {1L, 1L, 1L, 1L, 1L, 1L, 1L},
+ Collections.emptyMap(),
+ exceptionHistory);
+
+ testingRestfulGateway =
+ new TestingRestfulGateway.Builder()
+ .setRequestApplicationFunction(
+ applicationId ->
+ CompletableFuture.completedFuture(
+ applicationWithExceptions))
+ .build();
+
+ final HandlerRequest<EmptyRequestBody> limitedRequest =
+ createRequest(archivedApplication.getApplicationId(), 2);
+
+ final ApplicationExceptionsInfoWithHistory response =
+ handler.handleRequest(limitedRequest,
testingRestfulGateway).get();
+
+ assertThat(response.getExceptionHistory().getEntries()).hasSize(2);
Review Comment:
Shouldn't we also verify/assert the intended order?
##########
flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/application/ApplicationExceptionsHandler.java:
##########
@@ -47,17 +49,19 @@ public class ApplicationExceptionsHandler
RestfulGateway,
EmptyRequestBody,
ApplicationExceptionsInfoWithHistory,
- ApplicationMessageParameters>
+ ApplicationExceptionsMessageParameters>
implements ApplicationJsonArchivist {
+ static final int MAX_NUMBER_EXCEPTION_TO_REPORT = 20;
Review Comment:
just an observation, that in
https://github.com/apache/flink/blob/master/flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/job/JobExceptionsHandler.java#L63
we also have same constant. maybe worth extracting if we revisit default in
the future. however, it is just an observation (not a blocker).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]