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

Dependency error trying to build custom collector distribution 0.81.0 within a workspace #8127

Closed
mattsains opened this issue Jul 24, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@mattsains
Copy link
Contributor

mattsains commented Jul 24, 2023

Describe the bug
When building a custom collector with version 0.81.0, if the collector is built into a directory which forms part of a go workspace, the builds fails with this error:

2023-07-24T15:05:12.598-0700    INFO    internal/command.go:117 OpenTelemetry Collector Builder {"version": "dev", "date": "unknown"}
2023-07-24T15:05:12.599-0700    INFO    internal/command.go:150 Using config file       {"path": "builder-config.yaml"}
2023-07-24T15:05:12.599-0700    INFO    builder/config.go:106   Using go        {"go-executable": "/usr/local/go/bin/go"}
2023-07-24T15:05:12.599-0700    INFO    builder/main.go:69      Sources created {"path": "./"}
2023-07-24T15:05:13.177-0700    INFO    builder/main.go:121     Getting go modules
2023-07-24T15:05:13.448-0700    INFO    builder/main.go:80      Compiling
Error: failed to compile the OpenTelemetry Collector distribution: exit status 1. Output:
../../../go/pkg/mod/go.opentelemetry.io/collector/[email protected]/confmap.go:11:2: ambiguous import: found package github.com/knadh/koanf/maps in multiple modules:
        github.com/knadh/koanf v1.5.0 (/home/msainsbury/go/pkg/mod/github.com/knadh/[email protected]/maps)
        github.com/knadh/koanf/maps v0.1.1 (/home/msainsbury/go/pkg/mod/github.com/knadh/koanf/[email protected])
../../../go/pkg/mod/go.opentelemetry.io/collector/[email protected]/confmap.go:12:2: ambiguous import: found package github.com/knadh/koanf/providers/confmap in multiple modules:
        github.com/knadh/koanf v1.5.0 (/home/msainsbury/go/pkg/mod/github.com/knadh/[email protected]/providers/confmap)
        github.com/knadh/koanf/providers/confmap v0.1.0 (/home/msainsbury/go/pkg/mod/github.com/knadh/koanf/providers/[email protected])

This error does not occur on 0.80.0.

Steps to reproduce
A minimal working example can be found here: https://github.com/mattsains/otel-builder-test

Go to directory bloop and run:

go install go.opentelemetry.io/collector/cmd/[email protected]
builder --config builder-config.yaml

The error occurs.

Downgrade the builder to version 0.80.0 and change all instances of 0.81.0 in the builder-config.yaml file to 0.80.0, and try again. It succeeds.

What did you expect to see?
I expected to be able to build a custom collector in a workspace. This is a reasonable scenario if you are also building custom components to include in your distribution.

What did you see instead?
A dependency error. I am sure this is not conflicts with my own code, because, as you can see in the repro, it is a trivial workspace with only the collector build included.

What version did you use?
0.81.0

What config did you use?
See repo linked above

Environment
OS: Linux 5.19.0-43-generic #44~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon May 22 13:39:36 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Compiler(if manually compiled): go version go1.20.5 linux/amd64

Additional context
Could this be because the koanf dependency is older than workspaces? https://github.com/knadh/koanf/blob/v1.5.0/go.mod#L3

@mattsains mattsains added the bug Something isn't working label Jul 24, 2023
@dyladan
Copy link
Member

dyladan commented Jul 25, 2023

I ran into this as well. Removing the go.work file fixed the error for me, though that may not be possible for everyone. Looks like Jaeger also had the same problem (with the same solution) #7841 (comment)

@taj-p
Copy link

taj-p commented Jul 27, 2023

We were able to build the collector by adding the following to our builder-config.yaml:

excludes:
  - github.com/knadh/koanf v1.5.0

@mattsains
Copy link
Contributor Author

Nice, I was able to do the same with:

  - github.com/knadh/koanf v1.5.0
  - github.com/knadh/koanf/providers/confmap v0.1.0
  - github.com/knadh/koanf/maps v0.1.1

codeboten pushed a commit that referenced this issue Aug 16, 2023
`github.com/knadh/koanf/maps` and other koanf packages can be
ambiguously loaded from their own modules or from
`github.com/knadh/koanf` v.1.x when using Go workspaces. This PR removes
references to any koanf v1 packages to disambiguate the import path.

**Link to tracking Issue:**
#8127

I realize this change is enormous, I wasn't able to figure out how to
isolate the change to just the koanf packages. Any recommendations
welcome.

I produced these changes by running the following:

```shell
go mod edit -exclude=github.com/knadh/[email protected]
go work init
go work use -r .
go work sync
make gotidy
make genotelcorecol
```
@codeboten
Copy link
Contributor

This should be fixed by #8219, please re-open if its not the case

@mmynk
Copy link

mmynk commented Nov 30, 2023

this is still happening, i'm on v0.90.0

2023-11-30T18:05:52.074Z	INFO	builder/main.go:25	Running go subcommand.	{"arguments": ["build", "-trimpath", "-o", "oteld", "-ldflags=-s -w"]}
Error: failed to compile the OpenTelemetry Collector distribution: go subcommand failed with args '[build -trimpath -o oteld -ldflags=-s -w]': exit status 1. Output:
../../../go/pkg/mod/go.opentelemetry.io/collector/[email protected]/confmap.go:11:2: ambiguous import: found package github.com/knadh/koanf/maps in multiple modules:
	github.com/knadh/koanf v1.5.0 (/home/ubuntu/go/pkg/mod/github.com/knadh/[email protected]/maps)
	github.com/knadh/koanf/maps v0.1.1 (/home/ubuntu/go/pkg/mod/github.com/knadh/koanf/[email protected])
../../../go/pkg/mod/go.opentelemetry.io/collector/[email protected]/confmap.go:12:2: ambiguous import: found package github.com/knadh/koanf/providers/confmap in multiple modules:
	github.com/knadh/koanf v1.5.0 (/home/ubuntu/go/pkg/mod/github.com/knadh/[email protected]/providers/confmap)
	github.com/knadh/koanf/providers/confmap v0.1.0 (/home/ubuntu/go/pkg/mod/github.com/knadh/koanf/providers/[email protected])

@mattsains
Copy link
Contributor Author

@mmynk if it's still happening, please re-open this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants