Repository navigation
[Dataflow] Warn when the Java staging bucket has an age-based lifecycle rule - #41721
Anurag-S1ngh wants to merge 2 commits into
Conversation
…le rule Inspect staging bucket lifecycle metadata during runner construction and warn on Delete rules with an age condition. Metadata lookup failures are debug-only and never block submission.
Check only Delete lifecycle rules that apply to the staging prefix, and run the metadata lookup at submission time instead of runner construction. Keep lookup failures non-blocking and cover prefix matching with unit tests.
There was a problem hiding this comment.
📋 Review Summary
This PR adds a warning to DataflowRunner when the GCS staging bucket is configured with a Delete lifecycle rule that applies to the staging path, addressing issue #18209. The implementation is well-scoped, handles prefix matching and non-fatal metadata errors cleanly, and includes thorough unit test coverage.
🔍 General Feedback
- There is one significant issue when running with the legacy
GcsUtilV1(--experiments=disable_gcsutil_v2), whereGcsUtil.getBucketWithOptionsis not supported and throws an uncaughtUnsupportedOperationExceptionthat aborts job submission. UsingGcsUtil.getBucket(GcsPath)instead avoids this issue while supporting bothGcsUtilV1andGcsUtilV2.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
💬 Inline Findings
runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java(line 1221): 🔴 Critical:options.getGcsUtil().getBucketWithOptions(...)delegates toGcsUtilV2.getBucketWithOptions(...), which throwsUnsupportedOperationException("GcsUtil V2 is disabled by experiment...")when thedisable_gcsutil_v2experiment is enabled (falling back toGcsUtilV1). Because thecatchblock below only catchesIOExceptionandIllegalArgumentException, thatUnsupportedOperationExceptionwill escapewarnIfStagingBucketHasTtland fail Dataflow job submission wheneverdisable_gcsutil_v2is set.
Additionally, runners/google-cloud-dataflow-java/build.gradle does not declare a direct compile dependency on com.google.cloud:google-cloud-storage (it only declares google_api_services_storage), relying on transitive resolution for com.google.cloud.storage.Bucket.
Consider using options.getGcsUtil().getBucket(GcsPath.fromComponents(stagingPath.getBucket(), "")) (which returns com.google.api.services.storage.model.Bucket and is implemented for both GcsUtilV1 and GcsUtilV2, as done in GcpOptions.GcpTempLocationFactory.isSoftDeletePolicyEnabled), or at minimum catching UnsupportedOperationException (or Exception) in warnIfStagingBucketHasTtl so a non-fatal warning check can never break job submission.
runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java(line 1245): 🟢 Low: GCSDeletelifecycle rules can also delete staged objects based on conditions other thanAge(for example,CreatedBeforeorDaysSinceCustomTime), wherecondition.getAge()isnull. Furthermore, anageof0days is valid in GCS (meaning objects are eligible for deletion immediately after creation). If you want to warn on0-day TTLs as well, changeage > 0toage >= 0.
if (age == null || age < 0 || !lifecycleRuleMatchesObjectPrefix(condition, stagingPrefix)) {
|
Assigning reviewers: R: @kennknowles added as fallback since no labels match configuration 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). |
Summary
The Java Dataflow runner now checks the staging bucket lifecycle configuration when submitting a pipeline and warns when an age-based Delete rule can remove staged files.
Changes
Testing
./gradlew :runners:google-cloud-dataflow-java:test./gradlew :runners:google-cloud-dataflow-java:spotlessApply./gradlew :runners:google-cloud-dataflow-java:checkstyleMain :runners:google-cloud-dataflow-java:checkstyleTestCloses #18209