go-genproto: New submodules: upgrade before 2024-03-01 to avoid ambiguous import errors with google.golang.org/genproto
TL;DR
Upgrade to a version of google.golang.org/genproto at or above version v0.0.0-20230526161137-0005af68ea54 with the following command:
go get google.golang.org/genproto@latest
go mod tidy
Doing this before the 9-month deadline of 2024-03-01 will avoid “ambiguous import” errors.
Background
Many of the packages in the google.golang.org/genproto module represent API surfaces belonging to Google Cloud. Since approximately the v0.0.0-20220921223823-23cae91e6737 release of google.golang.org/genproto, a change in #901 introduced dependencies on virtually every submodule in cloud.google.com/go. This change moved type definitions for Google Cloud client libraries to cloud.google.com/go, greatly improving usability of the latter. To maintain compatibility with existing code, aliases were introduced into google.golang.org/genproto that pointed to the new sources of truth in cloud.google.com/go. This added the dependencies on cloud modules.
Even though most packages in google.golang.org/genproto are Google Cloud, a few packages provide simple “common” types used in projects unrelated to Google Cloud. For users of the simpler packages, this commingled existence resulted in a large number of extra cloud modules appearing in the dependency graph. This can trigger alarms in automatic dependency checks, false positives in vulnerability checks, and adds constraints to minimum version selection when resolving acceptable versions of other dependencies.
New submodules in this repo
To improve usability for consumers that do not depend on Google Cloud modules, packages providing widely used “common” types will be published as submodules. The following packages do not depend on cloud types and are now isolated in new non-cloud submodules:
google.golang.org/genproto/googleapis/api(Note: this does not include 4 subpackages referencing cloud types, listed below)google.golang.org/genproto/googleapis/bytestreamgoogle.golang.org/genproto/googleapis/rpc
The following subpackages of google.golang.org/genproto/googleapis/api reference cloud types and are now isolated from the api package as new cloud submodules:
google.golang.org/genproto/googleapis/api/apikeysgoogle.golang.org/genproto/googleapis/api/servicecontrolgoogle.golang.org/genproto/googleapis/api/servicemanagementgoogle.golang.org/genproto/googleapis/api/serviceusage
To ease migration, these submodules initially have a “back-ref” dependency on the google.golang.org/genproto parent. After a 9-month period, this “back-ref” dependency will be removed, making it possible to once again depend on the simpler packages of this project without adding cloud modules to the dependency graph.
Avoiding ambiguous imports for submodules
The root package docs for google.golang.org/genproto state:
IMPORTANT This repository is currently experimental. The structure of the contained packages is subject to change. Please see the original source repositories (listed below) to find out the status of each protocol buffer’s associated service.
In addition to this warning, the pseudo version numbering of the module:
Signals that the module is still in development and unstable. This release carries no backward compatibility or stability guarantees.
However, despite these warnings, we know that critical infrastructure depends on many of the packages in google.golang.org/genproto. To avoid “ambiguous import” errors for consumers, we are adding a “back-ref” dependency on the google.golang.org/genproto parent to each new submodule for 9 months to allow a seamless transition.
After the 9-month deadline of 2024-03-01 has passed, the “back-ref” dependency on the google.golang.org/genproto parent will be removed from each new submodule. Client code still using a version of the google.golang.org/genproto parent earlier than v0.0.0-20230525234044-86246a831fb4 may then encounter “ambiguous import” errors when importing packages that have been moved to submodules. Those errors can be resolved by updating to a version at or above version v0.0.0-20230526161137-0005af68ea54 with the following command:
go get google.golang.org/genproto@latest
go mod tidy
References
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 30
- Comments: 17 (5 by maintainers)
Commits related to this issue
- [chore] updating google.golang.org/genproto This is to avoid issues caused by https://github.com/googleapis/go-genproto/issues/1015 Signed-off-by: Alex Boten <aboten@lightstep.com> — committed to codeboten/opentelemetry-go-contrib by deleted user 3 years ago
- [chore] updating google.golang.org/genproto This is to avoid issues caused by https://github.com/googleapis/go-genproto/issues/1015 Signed-off-by: Alex Boten <aboten@lightstep.com> — committed to codeboten/opentelemetry-go-contrib by deleted user 3 years ago
- [chore] updating google.golang.org/genproto (#3968) * [chore] updating google.golang.org/genproto This is to avoid issues caused by https://github.com/googleapis/go-genproto/issues/1015 Signed-... — committed to open-telemetry/opentelemetry-go-contrib by deleted user 3 years ago
- deps: Upgrade google.golang.org/genproto Updates to the latest version of google.golang.org/genproto in all submodules in the repository. This is necessary because in a recent change, genproto split... — committed to pulumi/pulumi by abhinav 3 years ago
- deps: Upgrade google.golang.org/genproto Updates to the latest version of google.golang.org/genproto in all submodules in the repository. This is necessary because in a recent change, genproto split... — committed to pulumi/pulumi by abhinav 3 years ago
- Merge #13593 13593: deps: Upgrade google.golang.org/genproto r=abhinav a=abhinav Updates to the latest version of google.golang.org/genproto in all submodules in the repository. This is necessar... — committed to pulumi/pulumi by bors[bot] 3 years ago
- Merge #13593 #13598 13593: deps: Upgrade google.golang.org/genproto r=abhinav a=abhinav Updates to the latest version of google.golang.org/genproto in all submodules in the repository. This is n... — committed to pulumi/pulumi by bors[bot] 3 years ago
- deps: Upgrade google.golang.org/genproto Updates to the latest version of google.golang.org/genproto in all submodules in the repository. This is necessary because in a recent change, genproto split... — committed to pulumi/pulumi by abhinav 3 years ago
- go.mod: use carved out googleapis/apis sub module See https://github.com/googleapis/go-genproto/issues/1015 Several new submodules were carved out of the large genproto module, This is causing an am... — committed to trufnetwork/kwil-db by chappjc 3 years ago
- Merge #13593 #13596 13593: deps: Upgrade google.golang.org/genproto r=abhinav a=abhinav Updates to the latest version of google.golang.org/genproto in all submodules in the repository. This is n... — committed to pulumi/pulumi by bors[bot] 3 years ago
- Merge #13593 13593: deps: Upgrade google.golang.org/genproto r=abhinav a=abhinav Updates to the latest version of google.golang.org/genproto in all submodules in the repository. This is necessar... — committed to pulumi/pulumi by bors[bot] 3 years ago
- Merge #13593 #13596 13593: deps: Upgrade google.golang.org/genproto r=abhinav a=abhinav Updates to the latest version of google.golang.org/genproto in all submodules in the repository. This is n... — committed to pulumi/pulumi by bors[bot] 3 years ago
- Merge #13593 13593: deps: Upgrade google.golang.org/genproto r=abhinav a=abhinav Updates to the latest version of google.golang.org/genproto in all submodules in the repository. This is necessar... — committed to pulumi/pulumi by bors[bot] 3 years ago
- deps: Upgrade google.golang.org/{genproto, grpc} Updates to the latest versions of google.golang.org/genproto and google.golang.org/grpc in all submodules in the repository. This is necessary becaus... — committed to pulumi/pulumi by abhinav 3 years ago
- deps: Upgrade google.golang.org/{genproto, grpc} Updates to the latest versions of google.golang.org/genproto and google.golang.org/grpc in all submodules in the repository. This is necessary becaus... — committed to pulumi/pulumi by abhinav 3 years ago
- Merge #13593 13593: deps: Upgrade google.golang.org/{genproto, grpc} r=abhinav a=abhinav Updates to the latest versions of google.golang.org/genproto and google.golang.org/grpc in all submodules in ... — committed to pulumi/pulumi by bors[bot] 3 years ago
- Merge #13593 13593: deps: Upgrade google.golang.org/{genproto, grpc} r=abhinav a=abhinav Updates to the latest versions of google.golang.org/genproto and google.golang.org/grpc in all submodules in ... — committed to pulumi/pulumi by bors[bot] 3 years ago
- go.mod: use carved out googleapis/apis sub module See https://github.com/googleapis/go-genproto/issues/1015 Several new submodules were carved out of the large genproto module, This is causing an am... — committed to trufnetwork/kwil-db by chappjc 3 years ago
- go.mod: use carved out googleapis/apis sub module See https://github.com/googleapis/go-genproto/issues/1015 Several new submodules were carved out of the large genproto module, This is causing an am... — committed to trufnetwork/kwil-db by chappjc 3 years ago
- go.mod: use carved out googleapis/apis sub module See https://github.com/googleapis/go-genproto/issues/1015 Several new submodules were carved out of the large genproto module, This is causing an am... — committed to trufnetwork/kwil-db by chappjc 3 years ago
With
go mod tidyremoving mygoogle.golang.org/genprotorequire (that I don’t actually need except to work around this issue), I now have to add a worthless file to my code to eliminate the ambiguous import:Is there a more reliable path I can point to? Simply importing
google.golang.org/genprotodoes not work since there is no importable package there.Hardly a week goes by without hitting an ambiguous import error from genproto. Usually I manage to resolve this by updating a google/protobuf/grpc module, sometimes to an unreleased revision. In this case, I was completely stuck.
The frustrating thing about this issue is that it’s often some seemingly harmless dependency update (e.g. telemetry, grpc_gateway, swagger, etc.) that brings this on. I have learned to quarantine my use of such modules by creating tainted submodules of my own, or outright avoid them at all costs.
I think the ship has sailed on this, but it would be best if carved out unstable submodules find their way to entirely new import paths such that there is no possibility for ambiguous imports.
If you’re here because your builds are now breaking within your Google framework dependencies, this is a good example of what happens when a Go project doesn’t practice standard Go versioning.
EDIT: In the end, my issue was a dependency on the old api/idtoken that, in some circumstances, created dependency resolution ambiguity. Moving to a combination of
cloud.google.com/go/auth/credentials/idtokenandcloud.google.com/go/auth.While this repository is marked as experimental (Alpha? Beta?), there are versioned, production Google modules that reference this repository via un-versioned tags. IMHO, there’s cognitive dissonance here, where either the other modules are actually tainted to Alpha, or this repository really isn’t.
Just to point out in case it helps someone, that I had a build suddenly break out of the blue… (way past the deadline) and the fix was https://github.com/fortio/fortiotel/pull/254/commits/e5572ad176041f84c638d4a9a8a40b7011ca58b2
ie
but not do
go mod tidywhich removes somehow theentry
It isn’t a matter of the old module versions being removed or becoming unavailable, they would still be available via module proxy or git sha.
The “ambiguous import” issue happens when some dependencies in your dependency graph refer to a version of genproto prior to the carveout, some things refer to a version after the carveout along with some of the submodules, and dependency resolution can’t figure out which module is supposed to be providing the package.
Making sure you require a version of genproto after the carveout makes it unambiguous which module provides that package.
I have filed https://github.com/envoyproxy/go-control-plane/issues/1014. In the meantime another workaround would be to underscore import genproto in your project so that you can control the version of the dependency and there is no ambiguity.