-
Notifications
You must be signed in to change notification settings - Fork 152
Update with external checkpoints #199
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 3 commits
d92696a
0552fe9
c108c8e
0969f49
5c15785
84e650e
7b4e12d
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 |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ type FlinkAPIInterface interface { | |
| GetJobConfig(ctx context.Context, url string, jobID string) (*JobConfigResponse, error) | ||
| GetTaskManagers(ctx context.Context, url string) (*TaskManagersResponse, error) | ||
| GetCheckpointCounts(ctx context.Context, url string, jobID string) (*CheckpointResponse, error) | ||
| GetCheckpointConfig(ctx context.Context, url string, jobID string) (*CheckpointConfigResponse, error) | ||
| GetJobOverview(ctx context.Context, url string, jobID string) (*FlinkJobOverview, error) | ||
| } | ||
|
|
||
|
|
@@ -66,49 +67,53 @@ type FlinkJobManagerClient struct { | |
| } | ||
|
|
||
| type flinkJobManagerClientMetrics struct { | ||
| scope promutils.Scope | ||
| submitJobSuccessCounter labeled.Counter | ||
| submitJobFailureCounter labeled.Counter | ||
| cancelJobSuccessCounter labeled.Counter | ||
| cancelJobFailureCounter labeled.Counter | ||
| forceCancelJobSuccessCounter labeled.Counter | ||
| forceCancelJobFailureCounter labeled.Counter | ||
| checkSavepointSuccessCounter labeled.Counter | ||
| checkSavepointFailureCounter labeled.Counter | ||
| getJobsSuccessCounter labeled.Counter | ||
| getJobsFailureCounter labeled.Counter | ||
| getJobConfigSuccessCounter labeled.Counter | ||
| getJobConfigFailureCounter labeled.Counter | ||
| getClusterSuccessCounter labeled.Counter | ||
| getClusterFailureCounter labeled.Counter | ||
| getCheckpointsSuccessCounter labeled.Counter | ||
| getCheckpointsFailureCounter labeled.Counter | ||
| savepointJobSuccessCounter labeled.Counter | ||
| savepointJobFailureCounter labeled.Counter | ||
| scope promutils.Scope | ||
| submitJobSuccessCounter labeled.Counter | ||
| submitJobFailureCounter labeled.Counter | ||
| cancelJobSuccessCounter labeled.Counter | ||
| cancelJobFailureCounter labeled.Counter | ||
| forceCancelJobSuccessCounter labeled.Counter | ||
| forceCancelJobFailureCounter labeled.Counter | ||
| checkSavepointSuccessCounter labeled.Counter | ||
| checkSavepointFailureCounter labeled.Counter | ||
| getJobsSuccessCounter labeled.Counter | ||
| getJobsFailureCounter labeled.Counter | ||
| getJobConfigSuccessCounter labeled.Counter | ||
| getJobConfigFailureCounter labeled.Counter | ||
| getClusterSuccessCounter labeled.Counter | ||
| getClusterFailureCounter labeled.Counter | ||
| getCheckpointsSuccessCounter labeled.Counter | ||
| getCheckpointsFailureCounter labeled.Counter | ||
| savepointJobSuccessCounter labeled.Counter | ||
| savepointJobFailureCounter labeled.Counter | ||
| getCheckpointsConfigSuccessCounter labeled.Counter | ||
| getCheckpointsConfigFailureCounter labeled.Counter | ||
| } | ||
|
|
||
| func newFlinkJobManagerClientMetrics(scope promutils.Scope) *flinkJobManagerClientMetrics { | ||
| flinkJmClientScope := scope.NewSubScope("flink_jm_client") | ||
| return &flinkJobManagerClientMetrics{ | ||
| scope: scope, | ||
| submitJobSuccessCounter: labeled.NewCounter("submit_job_success", "Flink job submission successful", flinkJmClientScope), | ||
| submitJobFailureCounter: labeled.NewCounter("submit_job_failure", "Flink job submission failed", flinkJmClientScope), | ||
| cancelJobSuccessCounter: labeled.NewCounter("cancel_job_success", "Flink job cancellation successful", flinkJmClientScope), | ||
| cancelJobFailureCounter: labeled.NewCounter("cancel_job_failure", "Flink job cancellation failed", flinkJmClientScope), | ||
| forceCancelJobSuccessCounter: labeled.NewCounter("force_cancel_job_success", "Flink forced job cancellation successful", flinkJmClientScope), | ||
| forceCancelJobFailureCounter: labeled.NewCounter("force_cancel_job_failure", "Flink forced job cancellation failed", flinkJmClientScope), | ||
| checkSavepointSuccessCounter: labeled.NewCounter("check_savepoint_status_success", "Flink check savepoint status successful", flinkJmClientScope), | ||
| checkSavepointFailureCounter: labeled.NewCounter("check_savepoint_status_failure", "Flink check savepoint status failed", flinkJmClientScope), | ||
| getJobsSuccessCounter: labeled.NewCounter("get_jobs_success", "Get flink jobs succeeded", flinkJmClientScope), | ||
| getJobsFailureCounter: labeled.NewCounter("get_jobs_failure", "Get flink jobs failed", flinkJmClientScope), | ||
| getJobConfigSuccessCounter: labeled.NewCounter("get_job_config_success", "Get flink job config succeeded", flinkJmClientScope), | ||
| getJobConfigFailureCounter: labeled.NewCounter("get_job_config_failure", "Get flink job config failed", flinkJmClientScope), | ||
| getClusterSuccessCounter: labeled.NewCounter("get_cluster_success", "Get cluster overview succeeded", flinkJmClientScope), | ||
| getClusterFailureCounter: labeled.NewCounter("get_cluster_failure", "Get cluster overview failed", flinkJmClientScope), | ||
| getCheckpointsSuccessCounter: labeled.NewCounter("get_checkpoints_success", "Get checkpoint request succeeded", flinkJmClientScope), | ||
| getCheckpointsFailureCounter: labeled.NewCounter("get_checkpoints_failed", "Get checkpoint request failed", flinkJmClientScope), | ||
| savepointJobSuccessCounter: labeled.NewCounter("savepoint_job_success", "Savepoint job request succeeded", flinkJmClientScope), | ||
| savepointJobFailureCounter: labeled.NewCounter("savepoint_job_failed", "Savepoint job request failed", flinkJmClientScope), | ||
| scope: scope, | ||
| submitJobSuccessCounter: labeled.NewCounter("submit_job_success", "Flink job submission successful", flinkJmClientScope), | ||
| submitJobFailureCounter: labeled.NewCounter("submit_job_failure", "Flink job submission failed", flinkJmClientScope), | ||
| cancelJobSuccessCounter: labeled.NewCounter("cancel_job_success", "Flink job cancellation successful", flinkJmClientScope), | ||
| cancelJobFailureCounter: labeled.NewCounter("cancel_job_failure", "Flink job cancellation failed", flinkJmClientScope), | ||
| forceCancelJobSuccessCounter: labeled.NewCounter("force_cancel_job_success", "Flink forced job cancellation successful", flinkJmClientScope), | ||
| forceCancelJobFailureCounter: labeled.NewCounter("force_cancel_job_failure", "Flink forced job cancellation failed", flinkJmClientScope), | ||
| checkSavepointSuccessCounter: labeled.NewCounter("check_savepoint_status_success", "Flink check savepoint status successful", flinkJmClientScope), | ||
| checkSavepointFailureCounter: labeled.NewCounter("check_savepoint_status_failure", "Flink check savepoint status failed", flinkJmClientScope), | ||
| getJobsSuccessCounter: labeled.NewCounter("get_jobs_success", "Get flink jobs succeeded", flinkJmClientScope), | ||
| getJobsFailureCounter: labeled.NewCounter("get_jobs_failure", "Get flink jobs failed", flinkJmClientScope), | ||
| getJobConfigSuccessCounter: labeled.NewCounter("get_job_config_success", "Get flink job config succeeded", flinkJmClientScope), | ||
| getJobConfigFailureCounter: labeled.NewCounter("get_job_config_failure", "Get flink job config failed", flinkJmClientScope), | ||
| getClusterSuccessCounter: labeled.NewCounter("get_cluster_success", "Get cluster overview succeeded", flinkJmClientScope), | ||
| getClusterFailureCounter: labeled.NewCounter("get_cluster_failure", "Get cluster overview failed", flinkJmClientScope), | ||
| getCheckpointsSuccessCounter: labeled.NewCounter("get_checkpoints_success", "Get checkpoint request succeeded", flinkJmClientScope), | ||
| getCheckpointsFailureCounter: labeled.NewCounter("get_checkpoints_failed", "Get checkpoint request failed", flinkJmClientScope), | ||
| savepointJobSuccessCounter: labeled.NewCounter("savepoint_job_success", "Savepoint job request succeeded", flinkJmClientScope), | ||
| savepointJobFailureCounter: labeled.NewCounter("savepoint_job_failed", "Savepoint job request failed", flinkJmClientScope), | ||
| getCheckpointsConfigSuccessCounter: labeled.NewCounter("get_checkpoints_config_success", "Get checkpoint config request succeeded", flinkJmClientScope), | ||
| getCheckpointsConfigFailureCounter: labeled.NewCounter("get_checkpoints_config_failed", "Get checkpoint config request failed", flinkJmClientScope), | ||
| } | ||
|
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. I love I could add some line breaks to separate out the new, longer struct member and minimize the line change count on things like this.
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. Agreed. Not a problem, ok to leave as is :) |
||
| } | ||
|
|
||
|
|
@@ -369,6 +374,26 @@ func (c *FlinkJobManagerClient) GetCheckpointCounts(ctx context.Context, url str | |
| c.metrics.getCheckpointsSuccessCounter.Inc(ctx) | ||
| return &checkpointResponse, nil | ||
| } | ||
| func (c *FlinkJobManagerClient) GetCheckpointConfig(ctx context.Context, url string, jobID string) (*CheckpointConfigResponse, error) { | ||
| endpoint := fmt.Sprintf(url+checkpointsURL+"/config", jobID) | ||
| response, err := c.executeRequest(ctx, httpGet, endpoint, nil) | ||
| if err != nil { | ||
| c.metrics.getCheckpointsConfigFailureCounter.Inc(ctx) | ||
| return nil, GetRetryableError(err, v1beta1.GetCheckpointConfig, GlobalFailure, DefaultRetries) | ||
| } | ||
| if response != nil && !response.IsSuccess() { | ||
| c.metrics.getCheckpointsConfigFailureCounter.Inc(ctx) | ||
| return nil, GetRetryableError(err, v1beta1.GetCheckpointConfig, response.Status(), DefaultRetries) | ||
| } | ||
|
|
||
| var checkpointConfigResponse CheckpointConfigResponse | ||
| if err = json.Unmarshal(response.Body(), &checkpointConfigResponse); err != nil { | ||
| logger.Errorf(ctx, "Failed to unmarshal checkpointConfigResponse %v, err %v", response, err) | ||
| } | ||
|
|
||
| c.metrics.getCheckpointsSuccessCounter.Inc(ctx) | ||
| return &checkpointConfigResponse, nil | ||
| } | ||
|
|
||
| func (c *FlinkJobManagerClient) GetJobOverview(ctx context.Context, url string, jobID string) (*FlinkJobOverview, error) { | ||
| endpoint := fmt.Sprintf(url+GetJobsOverviewURL, jobID) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,6 +85,9 @@ type ControllerInterface interface { | |
| // able to savepoint for some reason. | ||
| FindExternalizedCheckpoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) | ||
|
|
||
| // Ensures that application is configured to externalize and *not* delete checkpoints on cancel. | ||
| FindExternalizedCheckpointForSavepoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) | ||
|
|
||
| // Logs an event to the FlinkApplication resource and to the operator log | ||
| LogEvent(ctx context.Context, app *v1beta1.FlinkApplication, eventType string, reason string, message string) | ||
|
|
||
|
|
@@ -468,8 +471,8 @@ func (f *Controller) DeleteOldResourcesForApp(ctx context.Context, app *v1beta1. | |
| return nil | ||
| } | ||
|
|
||
| func (f *Controller) FindExternalizedCheckpoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) { | ||
| checkpoint, err := f.flinkClient.GetLatestCheckpoint(ctx, f.getURLFromApp(application, hash), f.GetLatestJobID(ctx, application)) | ||
| func (f *Controller) findExternalizedCheckpoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string, checkpointMaxAge int32) (string, error) { | ||
| checkpoint, err := f.flinkClient.GetLatestCheckpoint(ctx, f.getURLFromApp(application, hash), application.Status.JobStatus.JobID) | ||
| var checkpointPath string | ||
| var checkpointTime int64 | ||
| if err != nil { | ||
|
|
@@ -490,12 +493,28 @@ func (f *Controller) FindExternalizedCheckpoint(ctx context.Context, application | |
| return "", nil | ||
| } | ||
|
|
||
| if isCheckpointOldToRecover(checkpointTime, getMaxCheckpointRestoreAgeSeconds(application)) { | ||
| if isCheckpointOldToRecover(checkpointTime, checkpointMaxAge) { | ||
| logger.Info(ctx, "Found checkpoint to restore from, but was too old") | ||
| return "", nil | ||
| } | ||
|
|
||
| return checkpointPath, nil | ||
|
|
||
| } | ||
|
|
||
| func (f *Controller) FindExternalizedCheckpoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) { | ||
| return f.findExternalizedCheckpoint(ctx, application, hash, getMaxCheckpointRestoreAgeSeconds(application)) | ||
| } | ||
|
|
||
| func (f *Controller) FindExternalizedCheckpointForSavepoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) { | ||
| checkpointConfig, err := f.flinkClient.GetCheckpointConfig(ctx, f.getURLFromApp(application, hash), application.Status.JobStatus.JobID) | ||
|
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. Is there opportunity to combine |
||
| if err != nil { | ||
| return "", err | ||
| } | ||
| if !(checkpointConfig.Externalization.Enabled && !checkpointConfig.Externalization.DeleteOnCancellation) { | ||
| return "", fmt.Errorf("Checkpoint configuration not compatable for starting from checkpoints") | ||
| } | ||
| return f.findExternalizedCheckpoint(ctx, application, hash, getMaxCheckpointDeployAgeSeconds(application)) | ||
| } | ||
|
|
||
| func isCheckpointOldToRecover(checkpointTime int64, maxCheckpointRecoveryAgeSec int32) bool { | ||
|
|
||
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.
Is
MaxCheckpointDeployAgeSecondsfunctionally different from theMaxCheckpointRestoreAgeSeconds?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.
Not functionally, no. my thinking was that these checkpoint age values could have very different acceptability thresholds since the
MaxCheckpointDeployAgeSecondswould be looking for an ideal, possibly short window. I may have read the code wrong, but my thinking was by failing this age check, the operator would effectively poll the JM API looking for the next checkpoint to run and complete (we have ours checkpointing frequently.)I may have read the state machine handler incorrectly though.