Include Go version, platform, and other build info in version string

Additionally update MatchesServerVersion to only check GitVersion,
GitCommit, and GitTreeState.
This commit is contained in:
Jeff Grafton
2016-01-20 18:33:34 -08:00
parent 4c2d129bdb
commit fb663f2cd5
5 changed files with 26 additions and 11 deletions

View File

@@ -54,4 +54,6 @@ var (
gitVersion string = "v0.0.0-master+$Format:%h$"
gitCommit string = "$Format:%H$" // sha1 from git, output of $(git rev-parse HEAD)
gitTreeState string = "not a git tree" // state of git tree, either "clean" or "dirty"
buildDate string = "1970-01-01T00:00:00Z" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
)

View File

@@ -16,7 +16,12 @@ limitations under the License.
package version
import "github.com/prometheus/client_golang/prometheus"
import (
"fmt"
"runtime"
"github.com/prometheus/client_golang/prometheus"
)
// Info contains versioning information.
// TODO: Add []string of api versions supported? It's still unclear
@@ -27,6 +32,10 @@ type Info struct {
GitVersion string `json:"gitVersion"`
GitCommit string `json:"gitCommit"`
GitTreeState string `json:"gitTreeState"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
}
// Get returns the overall codebase version. It's for detecting
@@ -40,6 +49,10 @@ func Get() Info {
GitVersion: gitVersion,
GitCommit: gitCommit,
GitTreeState: gitTreeState,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}
@@ -52,12 +65,12 @@ func init() {
buildInfo := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "kubernetes_build_info",
Help: "A metric with a constant '1' value labeled by major, minor, git version, git commit and git tree state from which Kubernetes was built.",
Help: "A metric with a constant '1' value labeled by major, minor, git version, git commit, git tree state, build date, Go version, and compiler from which Kubernetes was built, and platform on which it is running.",
},
[]string{"major", "minor", "gitVersion", "gitCommit", "gitTreeState"},
[]string{"major", "minor", "gitVersion", "gitCommit", "gitTreeState", "buildDate", "goVersion", "compiler", "platform"},
)
info := Get()
buildInfo.WithLabelValues(info.Major, info.Minor, info.GitVersion, info.GitCommit, info.GitTreeState).Set(1)
buildInfo.WithLabelValues(info.Major, info.Minor, info.GitVersion, info.GitCommit, info.GitTreeState, info.BuildDate, info.GoVersion, info.Compiler, info.Platform).Set(1)
prometheus.MustRegister(buildInfo)
}