Repository navigation
Increase TestDataflowRunner state timeout and retry FailedPrecondition on cancel while non-terminal - #41627
Conversation
…recondition on cancel
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR increases WAIT_IN_STATE_TIMEOUT in TestDataflowRunner from 10 minutes to 20 minutes to accommodate longer worker startup latencies under concurrent load, and adds retry logic in DataflowApplicationClient.modify_job_state for transient FailedPrecondition errors during job cancellation or draining. The changes are well-scoped, properly preserve fast failure on terminal preconditions, and include solid unit test coverage.
🔍 General Feedback
- The
_retry_on_modify_job_state_errorfilter cleanly delegates server errors toretry_on_server_errors_filterwhile specifically matching the transient control-plane messages ('not yet ready for canceling'and'no backend assigned'). - Unit tests in
apiclient_test.pyverify both transient retry behavior and non-retryable terminalFailedPreconditionbehavior.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #41627 +/- ##
============================================
+ Coverage 58.04% 58.19% +0.15%
Complexity 2844 2844
============================================
Files 1210 1211 +1
Lines 173261 173793 +532
Branches 2329 2329
============================================
+ Hits 100561 101145 +584
+ Misses 69987 69935 -52
Partials 2713 2713
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…f error message strings
|
/gemini review |
There was a problem hiding this comment.
📋 Review Summary
This PR resolves flaky Dataflow E2E tests by increasing WAIT_IN_STATE_TIMEOUT in TestDataflowRunner from 10 to 20 minutes and retrying FailedPrecondition errors in DataflowApplicationClient.modify_job_state when canceling a job that is still in a non-terminal state. The changes are well-scoped, properly bounded with exponential backoff, and accompanied by comprehensive unit tests.
🔍 General Feedback
- Gating
FailedPreconditionretries onJobStateviaget_job()rather than matching error message strings is a clean, resilient design. - One edge case worth considering in
DataflowPipelineResult.cancel()/modify_job_state: if a job transitions into a terminal or cancelling state concurrently with theupdate_jobcall (resulting in aFailedPreconditionwithcurrent_stateinJOB_STATE_CANCELLEDorJOB_STATE_CANCELLING),modify_job_statewill re-raiseFailedPreconditioneven though the cancellation goal has effectively been met.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
This should help us avoid failures, but maybe more importantly will avoid us failing to cancelled completed jobs in some cases |
|
Assigning reviewers: R: @tvalentyn for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
| return (Job, (self.options, )) | ||
|
|
||
|
|
||
| _NON_RETRYABLE_CANCEL_STATES = frozenset({ |
There was a problem hiding this comment.
_NON_RETRYABLE_CANCEL_STATES is confusing to me since the elements in the set don't seem to be cancel states.
There was a problem hiding this comment.
perhaps: _NON_RETRYABLE_FOR_CANCEL_STATES is slightly better.
There was a problem hiding this comment.
Renamed to _NON_RETRYABLE_FOR_CANCEL_STATES in f17fa51 — thanks!
Note: this PR was auto-generated by tooling. Before moving it out of draft, the author has done a full review of the PR, specifically evaluating it on the following criteria:
Full details of the methodology of generation and review can be found here - https://docs.google.com/document/d/14lj7ECVov4T4EdwmIzNlWrRGE3lLDMOwX5xUMGzaLoc/edit?usp=sharing
If you have concerns with the PR or with the underlying methodology used to generate this, please comment below - they will be addressed by the author not the tooling :)
Summary
Increases
WAIT_IN_STATE_TIMEOUTinTestDataflowRunnerfrom 10 minutes to 20 minutes and retries Dataflow400 FailedPreconditionerrors inDataflowApplicationClient.modify_job_statewhen canceling a job that is still in a non-terminalJobState.Production Impact
This changes production code in
DataflowApplicationClient.modify_job_state(sdks/python/apache_beam/runners/dataflow/internal/apiclient.py), which backsDataflowPipelineResult.cancel(). Previously, callingcancel()while a newly created Dataflow job was still initializing (e.g.'Job is not yet ready for canceling') or during a brief control-plane backend reassignment window (e.g.'Job has no backend assigned') immediately failed with an unretriedgoogle.api_core.exceptions.FailedPrecondition. With this change,FailedPreconditionerrors onJOB_STATE_CANCELLEDare retried with bounded exponential backoff wheneverget_job()reports a non-terminal state (independent of error-message wording), while already-terminal / already-cancelling / resource-cleaning-up jobs and non-cancel transitions (e.g. draining a batch job) fail immediately without retrying.Root Cause
apache-beam-testing, streaming Dataflow jobs can spend slightly more than 10 minutes inJOB_STATE_PENDINGbefore transitioning toJOB_STATE_RUNNING, trippingTestDataflowRunner.WAIT_IN_STATE_TIMEOUT = 10 * 60.TestDataflowRunner(or any user code) cancels a job that is still initializing or briefly unassigned to a workflow backend, the Dataflowupdate_jobAPI returns400 FAILED_PRECONDITION.modify_job_statepreviously used the defaultretry.retry_on_server_errors_filter, which does not retry HTTP 400 /FailedPrecondition.Fix
WAIT_IN_STATE_TIMEOUTinsdks/python/apache_beam/runners/dataflow/test_dataflow_runner.pyfrom10 * 60to20 * 60.DataflowApplicationClient.modify_job_stateinsdks/python/apache_beam/runners/dataflow/internal/apiclient.pyto wrapupdate_jobin bounded exponential backoff (num_retries=10,initial_delay_secs=5.0,max_delay_secs=30.0,stop_after_secs=180.0) that retries server errors and, forJOB_STATE_CANCELLED+FailedPrecondition, queriesself.get_job(job_id)and retries only ifcurrent_stateis not in_NON_RETRYABLE_CANCEL_STATES(DONE,FAILED,CANCELLED,CANCELLING,UPDATED,DRAINED,RESOURCE_CLEANING_UP). Ifget_job()fails or the requested transition is notJOB_STATE_CANCELLED, the originalFailedPreconditionis raised immediately.UtilTest.test_modify_job_state_retries_failed_precondition_by_job_stateinsdks/python/apache_beam/runners/dataflow/internal/apiclient_test.pycovering retryable states (PENDING,RUNNING,UNKNOWN), non-retryable states (DONE,FAILED,CANCELLED,CANCELLING,RESOURCE_CLEANING_UP), non-cancel transitions (DRAINING), andget_job()error propagation.Verification
yapf --style setup.cfg --diffacross modified files (clean).pytest apache_beam/runners/dataflow/internal/apiclient_test.py apache_beam/runners/dataflow/dataflow_runner_test.pylocally (101 passed, 2 skipped).PostCommit Python ValidatesRunner Dataflow: https://github.com/apache/beam/actions/runs/45688455700Recent Occurrences
4 failing
masterworkflow runs in the past 3 weeks:PostCommit Python ValidatesRunner Dataflow(3 runs):PostCommit Python(1 run,'Job has no backend assigned'on cancel):