aws-otel-collector icon indicating copy to clipboard operation
aws-otel-collector copied to clipboard

go mod tidy can cause ambiguous import error

Open bryan-aguilar opened this issue 3 years ago • 4 comments

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/[email protected]/compute/metadata)
	cloud.google.com/go/compute v1.1.0 (/Users/bryaag/go/pkg/mod/cloud.google.com/go/[email protected]/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/[email protected]/compute/metadata)
	cloud.google.com/go/compute v1.1.0 (/Users/bryaag/go/pkg/mod/cloud.google.com/go/[email protected]/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/[email protected]

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.

bryan-aguilar avatar Jan 27 '22 17:01 bryan-aguilar

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

Aneurysm9 avatar Feb 08 '22 00:02 Aneurysm9

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

bryan-aguilar avatar Feb 08 '22 01:02 bryan-aguilar

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[bot] avatar Apr 10 '22 20:04 github-actions[bot]

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

github-actions[bot] avatar May 15 '22 20:05 github-actions[bot]

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

ivanrusanov avatar Aug 15 '22 11:08 ivanrusanov

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/[email protected]/compute/metadata)\n\tcloud.google.com/go/compute v1.6.1 (/home/manjuna/go/pkg/mod/cloud.google.com/go/[email protected]/metadata)\n"
exit status 1
make: *** [Makefile:50: src/generated-gl-test-otel-collector] Error 1`

manjunath-batakurki avatar Sep 24 '22 18:09 manjunath-batakurki

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

gr0l0rg avatar Sep 28 '22 10:09 gr0l0rg

I deleted this /home/manjuna/go/pkg/mod/cloud.google.com/go/[email protected]/metadata and then it worked for me.

manjunath-batakurki avatar Sep 28 '22 11:09 manjunath-batakurki

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\[email protected]\compute\metadata)
cloud.google.com/go/compute v1.7.0 (C:\Users\xxx\go\pkg\mod\cloud.google.com\go\[email protected]\metadata)  

llussy avatar Sep 29 '22 10:09 llussy

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

vasireddy99 avatar Sep 29 '22 15:09 vasireddy99

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

bryan-aguilar avatar Sep 30 '22 03:09 bryan-aguilar

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

gr0l0rg avatar Sep 30 '22 05:09 gr0l0rg

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

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

guettli avatar Jan 06 '23 08:01 guettli