Merge pull request #3274 from tinyspeck/expose-build-number-in-stats

Export BUILD_NUMBER in stats.
This commit is contained in:
Sugu Sougoumarane 2017-10-26 10:53:12 -07:00 коммит произвёл GitHub
Родитель 57bb57db7a 695fd29ff8
Коммит b19b692281
2 изменённых файлов: 39 добавлений и 24 удалений

Просмотреть файл

@ -20,17 +20,19 @@ import (
"flag"
"fmt"
"runtime"
"strconv"
"time"
"github.com/youtube/vitess/go/stats"
)
var (
buildHost = ""
buildUser = ""
buildTime = ""
buildGitRev = ""
buildGitBranch = ""
buildHost = ""
buildUser = ""
buildTime = ""
buildGitRev = ""
buildGitBranch = ""
jenkinsBuildNumberStr = ""
// Version registers the command line flag to expose build info.
Version = flag.Bool("version", false, "print binary version")
@ -40,19 +42,24 @@ var (
var AppVersion versionInfo
type versionInfo struct {
buildHost string
buildUser string
buildTime int64
buildTimePretty string
buildGitRev string
buildGitBranch string
goVersion string
goOS string
goArch string
buildHost string
buildUser string
buildTime int64
buildTimePretty string
buildGitRev string
buildGitBranch string
jenkinsBuildNumber int64
goVersion string
goOS string
goArch string
}
func (v *versionInfo) Print() {
fmt.Printf("Version: %s (Git branch '%s') built on %s by %s@%s using %s %s/%s\n", v.buildGitRev, v.buildGitBranch, v.buildTimePretty, v.buildUser, v.buildHost, v.goVersion, v.goOS, v.goArch)
version := fmt.Sprintf("Version: %s", v.buildGitRev)
if v.jenkinsBuildNumber != 0 {
version = fmt.Sprintf("Version: %s (Jenkins build %d)", v.buildGitRev, v.jenkinsBuildNumber)
}
fmt.Printf("%s (Git branch '%s') built on %s by %s@%s using %s %s/%s\n", version, v.buildGitBranch, v.buildTimePretty, v.buildUser, v.buildHost, v.goVersion, v.goOS, v.goArch)
}
func init() {
@ -61,16 +68,22 @@ func init() {
panic(fmt.Sprintf("Couldn't parse build timestamp %q: %v", buildTime, err))
}
jenkinsBuildNumber, err := strconv.ParseInt(jenkinsBuildNumberStr, 10, 64)
if err != nil {
jenkinsBuildNumber = 0
}
AppVersion = versionInfo{
buildHost: buildHost,
buildUser: buildUser,
buildTime: t.Unix(),
buildTimePretty: buildTime,
buildGitRev: buildGitRev,
buildGitBranch: buildGitBranch,
goVersion: runtime.Version(),
goOS: runtime.GOOS,
goArch: runtime.GOARCH,
buildHost: buildHost,
buildUser: buildUser,
buildTime: t.Unix(),
buildTimePretty: buildTime,
buildGitRev: buildGitRev,
buildGitBranch: buildGitBranch,
jenkinsBuildNumber: jenkinsBuildNumber,
goVersion: runtime.Version(),
goOS: runtime.GOOS,
goArch: runtime.GOARCH,
}
stats.NewString("BuildHost").Set(AppVersion.buildHost)
@ -78,6 +91,7 @@ func init() {
stats.NewInt("BuildTimestamp").Set(AppVersion.buildTime)
stats.NewString("BuildGitRev").Set(AppVersion.buildGitRev)
stats.NewString("BuildGitBranch").Set(AppVersion.buildGitBranch)
stats.NewInt("BuildNumber").Set(AppVersion.jenkinsBuildNumber)
stats.NewString("GoVersion").Set(AppVersion.goVersion)
stats.NewString("GoOS").Set(AppVersion.goOS)
stats.NewString("GoArch").Set(AppVersion.goArch)

Просмотреть файл

@ -23,4 +23,5 @@ echo "\
-X 'github.com/youtube/vitess/go/vt/servenv.buildGitRev=$(git rev-parse --short HEAD)' \
-X 'github.com/youtube/vitess/go/vt/servenv.buildGitBranch=$(git rev-parse --abbrev-ref HEAD)' \
-X 'github.com/youtube/vitess/go/vt/servenv.buildTime=$(LC_ALL=C date)' \
-X 'github.com/youtube/vitess/go/vt/servenv.jenkinsBuildNumberStr=${BUILD_NUMBER}' \
"