diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b813d20..508f659d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.2.2 (unreleased) +- [PR #96](https://github.com/otoolep/rqlite/pull/96): Add build time to status output. + ## 2.2.1 (April 19th 2016) - [PR #95](https://github.com/otoolep/rqlite/pull/95): Correctly set HTTP authentication. diff --git a/cmd/rqlited/main.go b/cmd/rqlited/main.go index 9fb41470..bd8de5be 100644 --- a/cmd/rqlited/main.go +++ b/cmd/rqlited/main.go @@ -44,9 +44,10 @@ const logo = ` // These variables are populated via the Go linker. var ( - version = "2" - commit string - branch string + version = "2" + commit string + branch string + buildtime string ) var httpAddr string @@ -92,6 +93,9 @@ func init() { if branch == "" { branch = "unknown" } + if buildtime == "" { + buildtime = "unknown" + } } func main() { @@ -176,12 +180,14 @@ func main() { s.KeyFile = x509Key s.DisableRedirect = disRedirect s.Expvar = expvar - s.Version = version - s.Commit = commit - s.Branch = branch + s.BuildInfo = map[string]interface{}{ + "commit": commit, + "branch": branch, + "version": version, + "build_time": buildtime, + } if err := s.Start(); err != nil { log.Fatalf("failed to start HTTP server: %s", err.Error()) - } terminate := make(chan os.Signal, 1) diff --git a/http/service.go b/http/service.go index 8c15998a..e6618308 100644 --- a/http/service.go +++ b/http/service.go @@ -118,9 +118,8 @@ type Service struct { Expvar bool DisableRedirect bool // Disable leader-redirection. - Version string - Commit string - Branch string + + BuildInfo map[string]interface{} logger *log.Logger } @@ -296,12 +295,6 @@ func (s *Service) handleStatus(w http.ResponseWriter, r *http.Request) { return } - buildStatus := map[string]interface{}{ - "version": s.Version, - "commit": s.Commit, - "branch": s.Branch, - } - httpStatus := map[string]interface{}{ "addr": s.Addr().String(), "auth": prettyEnabled(s.credentialStore != nil), @@ -315,13 +308,15 @@ func (s *Service) handleStatus(w http.ResponseWriter, r *http.Request) { // Build the status response. status := map[string]interface{}{ "store": results, - "build": buildStatus, "http": httpStatus, "node": nodeStatus, } if !s.lastBackup.IsZero() { status["last_backup"] = s.lastBackup } + if s.BuildInfo != nil { + status["build"] = s.BuildInfo + } pretty, _ := isPretty(r) var b []byte diff --git a/package.sh b/package.sh index ae2b4d7f..020bdfe9 100755 --- a/package.sh +++ b/package.sh @@ -29,6 +29,7 @@ fi branch=`git rev-parse --abbrev-ref HEAD` commit=`git rev-parse HEAD` kernel=`uname -s` +buildtime=`date +%Y-%m-%dT%T%z` mkdir -p $tmp_build/src/github.com/otoolep export GOPATH=$tmp_build @@ -36,7 +37,7 @@ cd $tmp_build/src/github.com/otoolep git clone $REPO_URL cd rqlite go get -d ./... -go install -ldflags="-X main.version=$VERSION -X main.branch=$branch -X main.commit=$commit" ./... +go install -ldflags="-X main.version=$VERSION -X main.branch=$branch -X main.commit=$commit -X main.buildtime=$buildtime" ./... release=`echo rqlited-$VERSION-$kernel-$machine | tr '[:upper:]' '[:lower:]'` release_pkg=${release}.tar.gz