Skip to content

[Go] Avoid importing gcpopts in gcsx and dataflowlib to prevent flag collisions - #40729

Merged
derrickaw merged 5 commits into
apache:masterfrom
derrickaw:20261022_regionflagFix
Oct 23, 2026
Merged

derrickaw merged 5 commits into
apache:masterfrom
derrickaw:20261022_regionflagFix

Conversation

@derrickaw

@derrickaw derrickaw commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Problem: Importing gcpopts in gcsx and dataflowlib (#40686) transitively registers gcpopts's global --region and --project flags on flag.CommandLine, causing flag redefined panics in binaries that define their own --region or --project flags.

Fix: This PR removes the gcpopts dependency from gcsx and dataflowlib by:

  • Moving GetUniverseDomain into a new flag-free util/gcpx package (sdks/go/pkg/beam/util/gcpx), which gcsx, dataflowlib, and other GCP packages can import without registering global flags.
  • Moving GetGcsEndpoint to gcsx (using flag.Lookup("gcs_endpoint") instead of referencing *gcpopts.GcsEndpoint directly).
  • Keeping delegating wrappers in gcpopts to preserve its public API.

#40730

@derrickaw

Copy link
Copy Markdown
Collaborator Author

/gemini review

@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 cleanly resolves global flag collisions (--region and --project) caused by importing gcpopts in gcsx and dataflowlib. By relocating GetUniverseDomain and GetGcsEndpoint (using flag.Lookup) to gcsx while retaining delegating wrappers in gcpopts, the change breaks the problematic transitive dependency while preserving backward compatibility.

🔍 General Feedback

  • The package dependency direction (gcpopts -> gcsx) and use of flag.Lookup("gcs_endpoint") effectively prevent unintended registration of global flags on flag.CommandLine for consumers of gcsx and dataflowlib.
  • Unit tests have been appropriately migrated and updated to cover both the core implementation in gcsx and the delegating wrappers in gcpopts.

💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 56.42%. Comparing base (a8d6afd) to head (76e7846).
⚠️ Report is 61 commits behind head on master.

Files with missing lines Patch % Lines
sdks/go/pkg/beam/options/gcpopts/options.go 0.00% 2 Missing ⚠️
sdks/go/pkg/beam/util/gcsx/gcs.go 83.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #40729       +/-   ##
===========================================
- Coverage   80.04%   56.42%   -23.63%     
===========================================
  Files         490      872      +382     
  Lines       82916   154080    +71164     
===========================================
+ Hits        66373    86937    +20564     
- Misses      16543    65285    +48742     
- Partials        0     1858     +1858     
Flag Coverage Δ
go 28.93% <88.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@derrickaw
derrickaw marked this pull request as ready for review October 22, 2026 16:30
@derrickaw

Copy link
Copy Markdown
Collaborator Author

Will fix CodeQL failure in another PR since its not related to this one.

@github-actions

Copy link
Copy Markdown
Contributor

Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment assign set of reviewers

@derrickaw
derrickaw requested a review from shunping October 22, 2026 16:37
Comment thread sdks/go/pkg/beam/util/gcsx/gcs.go Outdated
@derrickaw
derrickaw requested a review from shunping October 22, 2026 20:27
@github-actions github-actions Bot added Next Action: Reviewers size/m M: 50-249 lines changed labels Oct 23, 2026
Comment thread sdks/go/pkg/beam/options/gcpopts/universe_test.go Outdated
@github-actions

Copy link
Copy Markdown
Contributor

Assigning reviewers:

R: @jrmccluskey for label go.
Backup reviewer: lostluck (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).

@github-actions
github-actions Bot requested a review from jrmccluskey October 23, 2026 15:15
@derrickaw
derrickaw removed the request for review from jrmccluskey October 23, 2026 15:23
@derrickaw
derrickaw requested a review from shunping October 23, 2026 17:16

@shunping shunping left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks!

@derrickaw
derrickaw merged commit 509c333 into apache:master Oct 23, 2026
14 checks passed
@derrickaw
derrickaw deleted the 20261022_regionflagFix branch October 23, 2026 19:11
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.

2 participants