Skip to content

[Dataflow] Warn when the Java staging bucket has an age-based lifecycle rule - #41721

Open
Anurag-S1ngh wants to merge 2 commits into
apache:masterfrom
Anurag-S1ngh:fix/18209-dataflow-staging-bucket-ttl-v2
Open

Anurag-S1ngh wants to merge 2 commits into
apache:masterfrom
Anurag-S1ngh:fix/18209-dataflow-staging-bucket-ttl-v2

Conversation

@Anurag-S1ngh

Copy link
Copy Markdown
Contributor

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

  • Check bucket lifecycle metadata just before staging artifacts.
  • Warn only for Delete rules with an age condition that apply to the staging prefix or the whole bucket.
  • Keep lookup failures at debug level so missing permissions never block submission.
  • Add unit coverage for matching prefixes, unrelated prefixes, empty rules, local paths, and lookup failures.

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:checkstyleTest

Closes #18209

…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.
@github-actions github-actions Bot added runners dataflow size/m M: 50-249 lines changed labels Nov 27, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 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), where GcsUtil.getBucketWithOptions is not supported and throws an uncaught UnsupportedOperationException that aborts job submission. Using GcsUtil.getBucket(GcsPath) instead avoids this issue while supporting both GcsUtilV1 and GcsUtilV2.

💡 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 to GcsUtilV2.getBucketWithOptions(...), which throws UnsupportedOperationException("GcsUtil V2 is disabled by experiment...") when the disable_gcsutil_v2 experiment is enabled (falling back to GcsUtilV1). Because the catch block below only catches IOException and IllegalArgumentException, that UnsupportedOperationException will escape warnIfStagingBucketHasTtl and fail Dataflow job submission whenever disable_gcsutil_v2 is 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: GCS Delete lifecycle rules can also delete staged objects based on conditions other than Age (for example, CreatedBefore or DaysSinceCustomTime), where condition.getAge() is null. Furthermore, an age of 0 days is valid in GCS (meaning objects are eligible for deletion immediately after creation). If you want to warn on 0-day TTLs as well, change age > 0 to age >= 0.
      if (age == null || age < 0 || !lifecycleRuleMatchesObjectPrefix(condition, stagingPrefix)) {

@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @kennknowles added as fallback since no labels match configuration
Backup reviewer: Abacn (if the main reviewer is unresponsive, you can escalate to them by tagging their username)

Note: If you would like to opt out of this review, comment assign to next reviewer.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java DataflowRunner should warn if the stagingLocation has a TTL

1 participant