open-telemetry / opentelemetry-collector-releases

OpenTelemetry Collector Official Releases
https://opentelemetry.io
Apache License 2.0
252 stars 162 forks source link

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

Closed jackgopack4 closed 1 month ago

jackgopack4 commented 2 months ago

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"}
dosubot[bot] commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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: https://github.com/open-telemetry/opentelemetry-collector/pull/11208

jackgopack4 commented 1 month ago

https://github.com/open-telemetry/opentelemetry-collector-releases/pull/665 still needs to be merged in order to fix version before v0.111.0