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

OCB v0.107.0 and onward no longer report version on command line #664

Closed
jackgopack4 opened this issue Sep 18, 2024 · 4 comments · Fixed by #665
Closed

OCB v0.107.0 and onward no longer report version on command line #664

jackgopack4 opened this issue Sep 18, 2024 · 4 comments · Fixed by #665
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@jackgopack4
Copy link
Contributor

After merging #608 and releasing ocb version v0.107.0, ocb binary no longer shows the version and date from v0.106.1 and earlier, instead displaying devel

Issue first raised by @Tim Chan on the CNCF Slack:

hey everyone, quick question, does anyone know why the verison says: (devel) for v107 and newer? i ran v106.1 and it doesn't show up as (devel)

downloaded/run v0.107:

➜  ~ curl -L -o "/Users/timothy.chan/bin/opentelemetry-collector-builder" https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/cmd/builder/v0.107.0/ocb_0.107.0_darwin_arm64

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 7254k  100 7254k    0     0  6117k      0  0:00:01  0:00:01 --:--:-- 11.0M

➜  ~ /Users/timothy.chan/bin/opentelemetry-collector-builder                                                                                                                                       

2024-09-17T15:58:47.244-0700	INFO	internal/command.go:125	OpenTelemetry Collector Builder	{"version": "(devel)"}
2024-09-17T15:58:47.244-0700	INFO	internal/command.go:136	Using default build configuration
2024-09-17T15:58:47.245-0700	INFO	builder/config.go:142	Using go	{"go-executable": "/opt/homebrew/bin/go"}

v0.106.1:

➜  ~ curl -L -o "/Users/timothy.chan/bin/opentelemetry-collector-builder" https://github.com/open-telemetry/opentelemetry-collector/releases/download/cmd/builder/v0.106.1/ocb_0.106.1_darwin_arm64 

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 7237k  100 7237k    0     0  4748k      0  0:00:01  0:00:01 --:--:-- 9494k

➜  ~ /Users/timothy.chan/bin/opentelemetry-collector-builder                                                                                                                                       

2024-09-17T15:57:41.029-0700	INFO	internal/command.go:125	OpenTelemetry Collector Builder	{"version": "0.106.1", "date": "2024-07-30T18:19:16Z"}
2024-09-17T15:57:41.029-0700	INFO	internal/command.go:136	Using default build configuration
2024-09-17T15:57:41.030-0700	INFO	builder/config.go:142	Using go	{"go-executable": "/opt/homebrew/bin/go"}
Copy link

dosubot bot commented Sep 18, 2024

Hey @jackgopack4, I'm a bot designed to help you solve bugs, answer questions, and become a contributor. I'm here to assist you while waiting for a human maintainer. 🤖

The OCB binary on version 0.107.0 and onward shows "devel" instead of the appropriate version number because the go install command used in the Makefile does not specify the version correctly. The -ldflags option should include the version information, but it is currently set to -s -w which strips debug information and reduces binary size, but does not set the version.

Here is the relevant part of the Makefile:

CGO_ENABLED=0 go install -trimpath -ldflags="-s -w" go.opentelemetry.io/collector/cmd/builder@v$(OTELCOL_BUILDER_VERSION)

To fix this, you need to modify the -ldflags to include the version information. For example:

CGO_ENABLED=0 go install -trimpath -ldflags="-s -w -X main.version=$(OTELCOL_BUILDER_VERSION)" go.opentelemetry.io/collector/cmd/builder@v$(OTELCOL_BUILDER_VERSION)

This will embed the version number into the binary, ensuring that it shows the correct version instead of "devel" [1].

To continue talking to Dosu, mention @dosu.

@TylerHelmuth
Copy link
Member

I believe our goreleaser file isn't correct. It is missing:

    ldflags:
      - -s -w -X go.opentelemetry.io/collector/cmd/builder/internal.version={{.Version}} -X go.opentelemetry.io/collector/cmd/builder/internal.date={{.Date}}

Old PR: https://github.com/open-telemetry/opentelemetry-collector/pull/10710/files#diff-707c9d3ba33af8bafe1fce966f4f7f6f6a756061e9798d2fcf5f58a517c28682

@jackgopack4
Copy link
Contributor Author

yes @TylerHelmuth you're right; working on the PR to re-add that. Also had to submit a PR for opentelemetry-collector; some code was removed in version.go that was actually enabling setting/viewing the version number when running the binary: open-telemetry/opentelemetry-collector#11208

@jackgopack4 jackgopack4 changed the title OCB Binary on version 0.107.0 and onward shows "devel" version instead of appropriate version number OCB v0.107.0 and onward no longer report version on command line Sep 19, 2024
bogdandrutu pushed a commit to open-telemetry/opentelemetry-collector that referenced this issue Sep 24, 2024
Revert "[chore] delete code to set a version and date, as it it not used
(#10715)"
Remove date string but re-add functions that check for version number
This (mostly) reverts commit b53f57d.

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
This re-enables the functionality to set a version number for ocb binary
(cmd/builder). It was erroneously removed. It also adds unit tests for
this functionality, as a warning is given on CI with no code coverage.

<!-- Issue number if applicable -->
#### Link to tracking issue
Relates to
open-telemetry/opentelemetry-collector-releases#664.
Closes #11220 along with
open-telemetry/opentelemetry-collector-releases#665

<!--Describe what testing was performed and which tests were added.-->
#### Testing
ran build and release cycles inside personal fork repositories
(jackgopack4/opentelemetry-collector and
jackgopack4/opentelemetry-collector-releases)
<!--Describe the documentation added.-->
#### Documentation
.chloggen file
<!--Please delete paragraphs that you did not use before submitting.-->
@jackgopack4
Copy link
Contributor Author

jackgopack4 commented Sep 27, 2024

#665 still needs to be merged in order to fix version before v0.111.0

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

Successfully merging a pull request may close this issue.

2 participants