-
Notifications
You must be signed in to change notification settings - Fork 501
[FLINK-37730] Improve exception recording ts initialization + 2.0 compatibility #983
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
Changes from 2 commits
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 |
|---|---|---|
|
|
@@ -36,3 +36,5 @@ buildNumber.properties | |
| .idea | ||
| *.iml | ||
| *.DS_Store | ||
|
|
||
| .kube | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,7 @@ | |||||
| import org.apache.flink.kubernetes.operator.controller.FlinkResourceContext; | ||||||
| import org.apache.flink.kubernetes.operator.reconciler.ReconciliationUtils; | ||||||
| import org.apache.flink.kubernetes.operator.utils.EventRecorder; | ||||||
| import org.apache.flink.kubernetes.operator.utils.EventUtils; | ||||||
| import org.apache.flink.kubernetes.operator.utils.ExceptionUtils; | ||||||
| import org.apache.flink.kubernetes.operator.utils.K8sAnnotationsSanitizer; | ||||||
| import org.apache.flink.runtime.client.JobStatusMessage; | ||||||
|
|
@@ -35,12 +36,11 @@ | |||||
| import org.slf4j.Logger; | ||||||
| import org.slf4j.LoggerFactory; | ||||||
|
|
||||||
| import java.time.Duration; | ||||||
| import java.time.Instant; | ||||||
| import java.time.ZoneId; | ||||||
| import java.util.ArrayList; | ||||||
| import java.util.Comparator; | ||||||
| import java.util.HashMap; | ||||||
| import java.util.List; | ||||||
| import java.util.Map; | ||||||
| import java.util.Objects; | ||||||
| import java.util.concurrent.TimeoutException; | ||||||
|
|
@@ -53,6 +53,8 @@ public class JobStatusObserver<R extends AbstractFlinkResource<?, ?>> { | |||||
| private static final Logger LOG = LoggerFactory.getLogger(JobStatusObserver.class); | ||||||
|
|
||||||
| public static final String JOB_NOT_FOUND_ERR = "Job Not Found"; | ||||||
| public static final String EXCEPTION_TIMESTAMP = "exception-timestamp"; | ||||||
| public static final Duration MAX_K8S_EVENT_AGE = Duration.ofMinutes(30); | ||||||
|
|
||||||
| protected final EventRecorder eventRecorder; | ||||||
|
|
||||||
|
|
@@ -132,8 +134,50 @@ protected void observeJobManagerExceptions(FlinkResourceContext<R> ctx) { | |||||
| } | ||||||
|
|
||||||
| var exceptionHistory = history.getExceptionHistory(); | ||||||
| List<JobExceptionsInfoWithHistory.RootExceptionInfo> exceptions = | ||||||
| exceptionHistory.getEntries(); | ||||||
| var exceptions = exceptionHistory.getEntries(); | ||||||
|
|
||||||
| String currentJobId = jobStatus.getJobId(); | ||||||
| var cacheEntry = ctx.getExceptionCacheEntry(); | ||||||
|
|
||||||
| if (!cacheEntry.isInitialized()) { | ||||||
|
|
||||||
| Instant lastExceptionTs; | ||||||
| if (exceptions == null || exceptions.isEmpty()) { | ||||||
| // If the job doesn't have any exceptions set to MIN as we always have to record | ||||||
| // the next | ||||||
| lastExceptionTs = Instant.MIN; | ||||||
| } else { | ||||||
| var k8sExpirationTs = Instant.now().minus(MAX_K8S_EVENT_AGE); | ||||||
| var maxJobExceptionTs = | ||||||
| exceptions.stream() | ||||||
| .map(e -> Instant.ofEpochMilli(e.getTimestamp())) | ||||||
| .max(Comparator.naturalOrder()) | ||||||
| .orElseThrow(); | ||||||
|
|
||||||
| if (maxJobExceptionTs.isBefore(k8sExpirationTs)) { | ||||||
| // If the last job exception was a long time ago, then there is no point in | ||||||
| // checking in k8s. | ||||||
| lastExceptionTs = maxJobExceptionTs; | ||||||
|
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. Any reason for this optimization? It complicates the code by adding another setting. It also requires the user to tune just another setting. There is no harm in calling out to the k8s api regularly to fetch events.
Contributor
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. there is no config for this (nothing to tune) and the optimization can be very important when the operator starts up because then the cache is empty and it would fetch events for every single job. In most cases this filter completely eliminates that so this greatly reduces the startup api server load
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. Fair point. The value is hardcoded. We would only query for the jobs with exceptions, but still those could amount to quite some jobs. |
||||||
| } else { | ||||||
| // If there were recent exceptions, we check the triggered events from kube | ||||||
| // to make sure we don't double trigger | ||||||
| lastExceptionTs = | ||||||
| EventUtils.findLastJobExceptionTsFromK8s( | ||||||
| ctx.getKubernetesClient(), resource) | ||||||
| .orElse(Instant.now().minus(MAX_K8S_EVENT_AGE)); | ||||||
|
||||||
| .orElse(Instant.now().minus(MAX_K8S_EVENT_AGE)); | |
| .orElse(k8sExpirationTs); |
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.
Good catch, I cleaned up / simplified the duplicated code in the method in a new commit, please check :)
Uh oh!
There was an error while loading. Please reload this page.