-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[FLINK-39730][runtime] Honor maxExceptions on ApplicationExceptionsHandler #28226
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
base: master
Are you sure you want to change the base?
Changes from all commits
4777372
904e76b
2783bcc
c3ffd11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,10 +91,11 @@ public String toString() { | |
| } | ||
|
|
||
| public static ApplicationExceptionsInfoWithHistory fromApplicationExceptionHistory( | ||
| Collection<ApplicationExceptionHistoryEntry> exceptions) { | ||
| Collection<ApplicationExceptionHistoryEntry> exceptions, int maxSize) { | ||
| return new ApplicationExceptionsInfoWithHistory( | ||
| new ApplicationExceptionHistory( | ||
| exceptions.stream() | ||
| .limit(maxSize) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that change the existing behavior (the return order)?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But which part/slice of history that gives us in the result? After this PR the user of this API will receive the most oldest one (it drops the most recent). And it looks inconsistent with JobExceptions history, which reverses first and as a result returns newest. |
||
| .map( | ||
| exception -> | ||
| new ApplicationExceptionInfo( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,9 +27,10 @@ | |
| import org.apache.flink.runtime.rest.handler.HandlerRequestException; | ||
| import org.apache.flink.runtime.rest.messages.ApplicationExceptionsInfoWithHistory; | ||
| import org.apache.flink.runtime.rest.messages.ApplicationIDPathParameter; | ||
| import org.apache.flink.runtime.rest.messages.ApplicationMessageParameters; | ||
| import org.apache.flink.runtime.rest.messages.EmptyRequestBody; | ||
| import org.apache.flink.runtime.rest.messages.application.ApplicationExceptionsHeaders; | ||
| import org.apache.flink.runtime.rest.messages.application.ApplicationExceptionsMessageParameters; | ||
| import org.apache.flink.runtime.rest.messages.job.UpperLimitExceptionParameter; | ||
| import org.apache.flink.runtime.webmonitor.RestfulGateway; | ||
| import org.apache.flink.runtime.webmonitor.TestingRestfulGateway; | ||
| import org.apache.flink.runtime.webmonitor.retriever.GatewayRetriever; | ||
|
|
@@ -57,13 +58,28 @@ class ApplicationExceptionsHandlerTest { | |
|
|
||
| private static HandlerRequest<EmptyRequestBody> createRequest(ApplicationID applicationId) | ||
| throws HandlerRequestException { | ||
| return createRequest(applicationId, Collections.emptyMap()); | ||
| } | ||
|
|
||
| private static HandlerRequest<EmptyRequestBody> createRequest( | ||
| ApplicationID applicationId, int maxExceptions) throws HandlerRequestException { | ||
| Map<String, List<String>> queryParameters = new HashMap<>(); | ||
| queryParameters.put( | ||
| UpperLimitExceptionParameter.KEY, | ||
| Collections.singletonList(Integer.toString(maxExceptions))); | ||
| return createRequest(applicationId, queryParameters); | ||
| } | ||
|
|
||
| private static HandlerRequest<EmptyRequestBody> createRequest( | ||
| ApplicationID applicationId, Map<String, List<String>> queryParameters) | ||
| throws HandlerRequestException { | ||
| Map<String, String> pathParameters = new HashMap<>(); | ||
| pathParameters.put(ApplicationIDPathParameter.KEY, applicationId.toString()); | ||
| return HandlerRequest.resolveParametersAndCreate( | ||
| EmptyRequestBody.getInstance(), | ||
| new ApplicationMessageParameters(), | ||
| new ApplicationExceptionsMessageParameters(), | ||
| pathParameters, | ||
| Collections.emptyMap(), | ||
| queryParameters, | ||
| Collections.emptyList()); | ||
| } | ||
|
|
||
|
|
@@ -143,6 +159,116 @@ void testExceptionWithJobId() throws Exception { | |
| assertThat(exceptionInfo.getJobId()).isEqualTo(jobId); | ||
| } | ||
|
|
||
| @Test | ||
| void testMaxExceptionsLimitsHistorySize() throws Exception { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could u please clarify, whether there are tests for:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, they were both missing as explicit cases. Added two tests in ApplicationExceptionsHandlerTest.java:
|
||
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we also verify/assert the intended order? |
||
| } | ||
|
|
||
| @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++) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the loop iterates |
||
| 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> oversizedRequest = | ||
| createRequest(archivedApplication.getApplicationId(), 10); | ||
|
|
||
| final ApplicationExceptionsInfoWithHistory response = | ||
| handler.handleRequest(oversizedRequest, testingRestfulGateway).get(); | ||
|
|
||
| assertThat(response.getExceptionHistory().getEntries()).hasSize(3); | ||
| } | ||
|
|
||
| @Test | ||
| void testExceptionWithoutJobId() throws Exception { | ||
| final RuntimeException rootCause = new RuntimeException("exception #0"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).