Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go mod tidy can cause ambiguous import error #926

Closed
bryan-aguilar opened this issue Jan 27, 2022 · 13 comments · Fixed by #1525
Closed

go mod tidy can cause ambiguous import error #926

bryan-aguilar opened this issue Jan 27, 2022 · 13 comments · Fixed by #1525

Comments

@bryan-aguilar
Copy link
Contributor

Describe the bug
go 1.17 introduced behavior that can lead to an ambiguous import error when attempting to run go mod tidy

Steps to reproduce
This occurs when attempting to update OTel dependency versions.
run go mod tidy

What did you expect to see?
No errors

What did you see instead?

bryaag@147ddac12c15 lambdacomponents % go mod tidy
github.com/aws-observability/aws-otel-collector/pkg/lambdacomponents imports
	github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter tested by
	github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter.test imports
	github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver imports
	github.com/prometheus/prometheus/discovery/install imports
	github.com/prometheus/prometheus/discovery/gce imports
	golang.org/x/oauth2/google imports
	cloud.google.com/go/compute/metadata: ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules:
	cloud.google.com/go v0.99.0 (/Users/bryaag/go/pkg/mod/cloud.google.com/go@v0.99.0/compute/metadata)
	cloud.google.com/go/compute v1.1.0 (/Users/bryaag/go/pkg/mod/cloud.google.com/go/compute@v1.1.0/metadata)
bryaag@147ddac12c15 lambdacomponents % go mod tidy -e
github.com/aws-observability/aws-otel-collector/pkg/lambdacomponents imports
	github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter tested by
	github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusexporter.test imports
	github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver imports
	github.com/prometheus/prometheus/discovery/install imports
	github.com/prometheus/prometheus/discovery/gce imports
	golang.org/x/oauth2/google imports
	cloud.google.com/go/compute/metadata: ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules:
	cloud.google.com/go v0.99.0 (/Users/bryaag/go/pkg/mod/cloud.google.com/go@v0.99.0/compute/metadata)
	cloud.google.com/go/compute v1.1.0 (/Users/bryaag/go/pkg/mod/cloud.google.com/go/compute@v1.1.0/metadata)
cloud.google.com/go/compute/metadata failed to load from any module,
	but go 1.16 would load it from cloud.google.com/go/compute@v1.1.0

Environment
Upgrading the dependency version.

Additional context
This can be alleviated with running rm go.sum && go mod tidy -go=1.16 && go mod tidy -go=1.17

The upstream collector-contrib repository also faces the same issues and gets around it by adding a make gotidy command to their makefile.

@Aneurysm9
Copy link
Member

This is changing upstream, and will hopefully avoid these issues in the future: open-telemetry/opentelemetry-collector#4810.

@bryan-aguilar
Copy link
Contributor Author

Will this alleviate the issue downstream also or will we have to follow suit and implement compat?

@github-actions
Copy link
Contributor

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the stale label Apr 10, 2022
@github-actions
Copy link
Contributor

This issue was closed because it has been marked as stall for 30 days with no activity.

@vasireddy99 vasireddy99 reopened this Aug 12, 2022
@github-actions github-actions bot removed the stale label Aug 14, 2022
@ivanrusanov
Copy link

Have the same issue while trying to build own collector following this instruction: https://opentelemetry.io/docs/collector/custom-collector/

@manjunath-batakurki
Copy link

I'm also facing the same issue. does someone know how to resolve this ?

`Error: failed to update go.mod: exit status 1. Output: "github.com/hpe-hcss/test-opentelemetry-collector-build/src/test-otel-collector imports\n\tgo.opentelemetry.io/collector/exporter/otlpexporter imports\n\tgo.opentelemetry.io/collector/config/configgrpc imports\n\tgo.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc tested by\n\tgo.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc.test imports\n\tgoogle.golang.org/grpc/interop imports\n\tgolang.org/x/oauth2/google imports\n\tcloud.google.com/go/compute/metadata: ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules:\n\tcloud.google.com/go v0.65.0 (/home/manjuna/go/pkg/mod/cloud.google.com/go@v0.65.0/compute/metadata)\n\tcloud.google.com/go/compute v1.6.1 (/home/manjuna/go/pkg/mod/cloud.google.com/go/compute@v1.6.1/metadata)\n"
exit status 1
make: *** [Makefile:50: src/generated-gl-test-otel-collector] Error 1`

@acromc
Copy link

acromc commented Sep 28, 2022

@manjunath-batakurki have you found any solution? I just experienced this myself.

@manjunath-batakurki
Copy link

I deleted this /home/manjuna/go/pkg/mod/cloud.google.com/go/compute@v1.6.1/metadata and then it worked for me.

@llussy
Copy link

llussy commented Sep 29, 2022

I encountered the same problem.

cloud.google.com/go/compute/metadata: ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules:
cloud.google.com/go v0.97.0 (C:\Users\xxx\go\pkg\mod\cloud.google.com\go@v0.97.0\compute\metadata)
cloud.google.com/go/compute v1.7.0 (C:\Users\xxx\go\pkg\mod\cloud.google.com\go\compute@v1.7.0\metadata)  

@vasireddy99
Copy link
Contributor

Thank you so much for explaining the problem, i hope this would work

run go clean -modcache before running go mod tidy -compat=1.18

@bryan-aguilar
Copy link
Contributor Author

Just so that no one has to sort through the PR. This replace statement was added to the offending go.mod file which alleviates the error for now.

replace cloud.google.com/go => cloud.google.com/go v0.100.2

@acromc
Copy link

acromc commented Sep 30, 2022

@bryan-aguilar thank you! this fixed the error for me

@guettli
Copy link

guettli commented Jan 6, 2023

This helped for me: https://stackoverflow.com/a/74689094/633961

Try go get cloud.google.com/go/compute/metadata and then go mod tidy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants