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

[chore] delete code to set a version and date, as it it not used #10715

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/builder/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ configuration is provided, ocb will generate a default Collector.

func initConfig(flags *flag.FlagSet) error {
cfg.Logger.Info("OpenTelemetry Collector Builder",
zap.String("version", version), zap.String("date", date))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

date is never set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it was set by ldflags in goreleaser.yml, which was now moved to opentelemetry-collector-releases. Dealing with issue open-telemetry/opentelemetry-collector-releases#664 now and am trying to narrow down why adding the ldflags back doesn't work, wondering if it has to do with version.go below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it wasn't used, so it had to go. If it's in usage, let's make sure it has tests and is exercised in this repository, and then it will be maintained and we can use it in the -releases repository. This might deserve its own issue in this repository.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote some tests for it and opened a PR, happy to open an issue to mirror the one in releases

zap.String("version", version))

var provider koanf.Provider

Expand Down
21 changes: 4 additions & 17 deletions cmd/builder/internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,12 @@ import (

var (
version = ""
date = "unknown"
)

// binVersion returns the version of the binary.
// If the version is not set, it attempts to read the build information.
// Returns an error if the build information cannot be read.
func binVersion() (string, error) {
if version != "" {
return version, nil
}
info, ok := debug.ReadBuildInfo()
if !ok {
return "", fmt.Errorf("failed to read build info")
}
return info.Main.Version, nil
func init() {
// the second returned value is a boolean, which is true if the binaries are built with module support.
info, _ := debug.ReadBuildInfo()
version = info.Main.Version
}

func versionCommand() *cobra.Command {
Expand All @@ -35,10 +26,6 @@ func versionCommand() *cobra.Command {
Short: "Version of ocb",
Long: "Prints the version of the ocb binary",
RunE: func(cmd *cobra.Command, _ []string) error {
version, err := binVersion()
if err != nil {
return err
}
cmd.Println(fmt.Sprintf("%s version %s", cmd.Parent().Name(), version))
return nil
},
Expand Down
Loading