Skip to content

Commit

Permalink
include build time and revision in version information
Browse files Browse the repository at this point in the history
  • Loading branch information
graphaelli committed Jan 4, 2018
1 parent ad812ec commit ff7fa5a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
9 changes: 7 additions & 2 deletions libbeat/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ 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())
buildTime := "unknown"
if bt := version.BuildTime(); !bt.IsZero() {
buildTime = bt.String()
}
fmt.Printf("%s version %s (%s), libbeat %s [%s built %s]\n",
beat.Info.Beat, beat.Info.Version, runtime.GOARCH, version.GetDefaultVersion(),
version.Commit(), buildTime)
return nil
}),
}
Expand Down
3 changes: 2 additions & 1 deletion libbeat/scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:%SZ')
GOBUILD_FLAGS?=-i -ldflags "-X github.com/elastic/beats/libbeat/version.buildTime=$(NOW) -X github.com/elastic/beats/libbeat/version.commit=$(COMMIT_ID)"
GOIMPORTS=goimports
GOIMPORTS_REPO?=golang.org/x/tools/cmd/goimports
GOIMPORTS_LOCAL_PREFIX?=github.com/elastic
Expand Down
22 changes: 22 additions & 0 deletions libbeat/version/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
package version

import "time"

const defaultBeatVersion = "7.0.0-alpha1"

var (
buildTime = "unknown"
commit = "unknown"
)

// BuildTime exposes the compile-time build time information.
// It will represent the zero time instant if parsing fails.
func BuildTime() time.Time {
t, err := time.Parse(time.RFC3339, buildTime)
if err != nil {
return time.Time{}
}
return t
}

// Commit exposes the compile-time commit hash.
func Commit() string {
return commit
}

0 comments on commit ff7fa5a

Please sign in to comment.