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

Wrong version reported after building Telegraf #4516

Closed
kaspergrubbe opened this issue Aug 3, 2018 · 4 comments · Fixed by #4521
Closed

Wrong version reported after building Telegraf #4516

kaspergrubbe opened this issue Aug 3, 2018 · 4 comments · Fixed by #4521
Labels
area/packaging bug unexpected problem or unintended behavior

Comments

@kaspergrubbe
Copy link

kaspergrubbe commented Aug 3, 2018

Steps to reproduce:

TELEGRAF_VERSION=1.7.2

go get -d github.com/influxdata/telegraf
cd $GOPATH/src/github.com/influxdata/telegraf
git checkout "$TELEGRAF_VERSION"
make deps
GOOS=linux GOARCH=amd64 go build -o telegraf-"$TELEGRAF_VERSION" ./cmd/telegraf
./telegraf-"$TELEGRAF_VERSION" version
Telegraf v1.7.0~unknown (git: unknown unknown)

Expected behavior:

To see Telegraf v1.7.2~unknown (git: unknown unknown)

Actual behavior:

I see Telegraf v1.7.0~unknown (git: unknown unknown)

@danielnelson
Copy link
Contributor

These values are normally set in make telegraf with help from git, if you want to set them manually you can do it like:

go build -ldflags " -X main.commit=c6feb056 -X main.branch=release-1.7 -X main.version=1.7.2" ./cmd/telegraf

You might also want to add -w -s in your final build to reduce the binary size:

go build -ldflags " -w -s -X main.commit=c6feb056 -X main.branch=release-1.7 -X main.version=1.7.2" ./cmd/telegraf

@danielnelson danielnelson added the discussion Topics for discussion label Aug 3, 2018
@danielnelson
Copy link
Contributor

I misunderstood this initially, if you don't set a version then you get the last major version (set in cmd/telegraf/telegraf.go). I believe this is used in the nightly builds to set the version. I'm going to reopen and will have it set no version if non is explicitly specified.

@danielnelson danielnelson reopened this Aug 3, 2018
@danielnelson danielnelson added bug unexpected problem or unintended behavior area/packaging and removed discussion Topics for discussion labels Aug 3, 2018
@kaspergrubbe
Copy link
Author

Oh I see the lines now in cmd/telegraf/telegraf.go, I just assumed that if I had checked out the 1.7.2-tag, it would also build the 1.7.2-binary, but isn't that the case?

Am I correct that my script above will be compiling a version 1.7.2 binary, but because I didn't specify any of this: -X main.commit=c6feb056 -X main.branch=release-1.7 -X main.version=1.7.2 the code defaults to 1.7.0?

@danielnelson
Copy link
Contributor

You are building it correctly for 1.7.2, just make sure to add the appropriate linker flags to get the version string. We'll fix this in 1.8 with #4521.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/packaging bug unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants