envoyproxy / envoy

Cloud-native high-performance edge/middle/service proxy
https://www.envoyproxy.io
Apache License 2.0
24.3k stars 4.7k forks source link

filters Go module issue - ambiguous import #35081

Open veggiemonk opened 1 week ago

veggiemonk commented 1 week ago

Title: Go filters module issue - ambiguous import

Description:

When trying to create a basic filter in Go, there is an issue with Envoy's Go module.

github.com/envoyproxy/envoy main module see pkg.go.dev github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go different module, not sub

Go complains that it is ambiguous.

See the error:

❯ go mod tidy
go: finding module for package github.com/envoyproxy/envoy/contrib/golang/common/go/api
go: finding module for package google.golang.org/protobuf/types/known/anypb
go: finding module for package github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go/pkg/http
go: finding module for package github.com/cncf/xds/go/xds/type/v3
go: found github.com/cncf/xds/go/xds/type/v3 in github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b
go: found github.com/envoyproxy/envoy/contrib/golang/common/go/api in github.com/envoyproxy/envoy v1.30.4
go: found github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go/pkg/http in github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go v0.0.0-20230324062628-466cf15f1790
go: found google.golang.org/protobuf/types/known/anypb in google.golang.org/protobuf v1.34.2
go: github.com/veggiemonk/envoy-filters-go/basic imports
        github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go/pkg/http: ambiguous import: found package github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go/pkg/http in multiple modules:
        github.com/envoyproxy/envoy v1.30.4 (/Users/julienb/go/pkg/mod/github.com/envoyproxy/envoy@v1.30.4/contrib/golang/filters/http/source/go/pkg/http)
        github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go v0.0.0-20230324062628-466cf15f1790 (/Users/julienb/go/pkg/mod/github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go@v0.0.0-20230324062628-466cf15f1790/pkg/http)

Repro steps:

git clone https://github.com/envoyproxy/envoy
go clean -modcache
mkdir example
cp ../envoy/examples/golang-http/simple/filter.go ../envoy/examples/golang-http/simple/config.go example/
cd example
go mod init example.com
go mod tidy

Workaround

add this replace directive in go.mod

replace github.com/envoyproxy/envoy => github.com/envoyproxy/envoy v1.30.1-0.20240702172845-dbe8cca3787c

related to https://github.com/golang/go/issues/27899

Admin and Stats Output: N/A

Config: N/A

Logs: N/A

Call Stack: N/A

doujiang24 commented 1 week ago

Thanks for your investigation and report. The root cause is that we used the module named github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go

Unfortunately, we have to work around in this way:

go get github.com/envoyproxy/envoy # or, suffix with a specified version
go mod tidy

It could be resolved when we move it into the standard core extension, there won't be a module named github.com/envoyproxy/envoy/contrib/golang/filters/http/source/go.

veggiemonk commented 1 week ago

Thank you for your reply @doujiang24. I'm sure the next person will be grateful to find your solution 👍 It is totally fine for now since it is still in alpha.