-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
include build time and revision in version information #5973
Conversation
libbeat/version/version.go
Outdated
return buildTime | ||
} | ||
|
||
func Commit() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function Commit should have comment or be unexported
libbeat/version/version.go
Outdated
commit = "unknown" | ||
) | ||
|
||
func BuildTime() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exported function BuildTime should have comment or be unexported
libbeat/version/version.go
Outdated
return buildTime | ||
} | ||
|
||
// BuildTime exposes the compile-time commit information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment on exported function Commit should be of the form "Commit ..."
13c484e
to
36212e1
Compare
libbeat/version/version.go
Outdated
) | ||
|
||
// BuildTime exposes the compile-time build time information | ||
func BuildTime() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about returning a time.Time
instead of string? And if the value is not set appropriately then return a zero value (time.Time{}
). This will save callers that need the time in a certain format from having to learn the format and parse it themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that but concerned about how to handle parse failure, in case of user error. At the risk of overkill, what about a versionTime
type with func String() string
and func Parse() (time.Time, error)
methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking to only have version.BuildTime() time.Time
. If the value was not set or was set incorrectly then return time.Time{}
. For me this would be adequate (I could check for validity if my use case required it with time.IsZero()
). I'd clearly state in the godocs that the zero value could be returned if the version.buildTime variable was not set or set incorrectly.
But if you want to be more explicit in stating that the build time value is bogus then I'd use version.BuildTime() (time.Time, error)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated as requested, now:
# valid time
$ go build -i -ldflags "-X github.com/elastic/beats/libbeat/version.buildTime=2018-01-03T17:30:56Z -X github.com/elastic/beats/libbeat/version.commit=1234"
$ ./libbeat version
mockbeat version 9.9.9 (amd64), libbeat 7.0.0-alpha1 [1234 built 2018-01-03 17:30:56 +0000 UTC]
# invalid time
$ go build -i -ldflags "-X github.com/elastic/beats/libbeat/version.buildTime=XXX -X github.com/elastic/beats/libbeat/version.commit=1234"
$ ./libbeat version
mockbeat version 9.9.9 (amd64), libbeat 7.0.0-alpha1 [1234 built unknown]
libbeat/scripts/Makefile
Outdated
@@ -36,7 +36,8 @@ COVERAGE_TOOL?=${BEAT_GOPATH}/bin/gotestcover | |||
COVERAGE_TOOL_REPO?=github.com/elastic/beats/vendor/github.com/pierrre/gotestcover | |||
TESTIFY_TOOL_REPO?=github.com/elastic/beats/vendor/github.com/stretchr/testify | |||
LIBCOMPOSE_TOOL_REPO?=github.com/docker/libcompose | |||
GOBUILD_FLAGS?=-i | |||
NOW=$(shell date -u '+%Y-%m-%dT%H:%M:%S') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks to be very close to RFC3339. Can you add the Zulu timezone identifier (e.g. date -u +"%Y-%m-%dT%H:%M:%SZ"
). This will make the value parse nicely like time.Parse(time.RFC3339, "2018-01-03T16:03:28Z")
.
libbeat/version/version.go
Outdated
func BuildTime() time.Time { | ||
if t, err := time.Parse(time.RFC3339, buildTime); err != nil { | ||
return time.Time{} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
libbeat/version/version.go
Outdated
func BuildTime() time.Time { | ||
if t, err := time.Parse(time.RFC3339, buildTime); err != nil { | ||
return time.Time{} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
a3a148f
to
3acba2a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM in its current state. Left a few nit comments. Thanks for making this change upstream.
libbeat/version/version.go
Outdated
commit = "unknown" | ||
) | ||
|
||
// BuildTime exposes the compile-time build time information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should document the conditions under which a zero value can be returned.
libbeat/version/version.go
Outdated
return t | ||
} | ||
|
||
// Commit exposes the compile-time commit information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should mention "hash" or "commit ID".
libbeat/cmd/version.go
Outdated
@@ -22,8 +22,15 @@ func genVersionCmd(name, beatVersion string) *cobra.Command { | |||
return fmt.Errorf("error initializing beat: %s", err) | |||
} | |||
|
|||
fmt.Printf("%s version %s (%s), libbeat %s\n", | |||
beat.Info.Beat, beat.Info.Version, runtime.GOARCH, version.GetDefaultVersion()) | |||
var buildTime string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider initializing buildTime := "unknown"
. I think it could make this a bit more concise.
Regarding testing, we should probably add a check to beats-tester to verify that the .build_hash.txt file matches the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I think it needs a rebase to pull in the fix for the NOTICE.txt year.
2d22382
to
a1613b3
Compare
a1613b3
to
ff7fa5a
Compare
This reverts commit a3970ee. Revert "Include build time and revision in version information (elastic#5973)" This reverts commit 54d6b4c.
This reverts commit a3970ee. Revert "Include build time and revision in version information (#5973)" This reverts commit 54d6b4c. Temporarily remove version info that is not provided by the current release process. before: ``` $ ./libbeat version mockbeat version 9.9.9 (amd64), libbeat 6.2.0 [unknown built unknown] ``` after: ``` $ ./libbeat version mockbeat version 9.9.9 (amd64), libbeat 6.2.0 ``` for #6051
I couldn't find a clever way to hook up tests for this, here's one way to verify the changes:
I got caught up for awhile getting this to work for apps that vendor libbeat, like apm-server. This worked there, note the
github.com/elastic/apm-server/vendor/
prefix: