Merge pull request #902 from jimmidyson/git-version
Expose git revision as well as version in version info, add Makefile
This commit is contained in:
commit
64702e7202
38
Makefile
Normal file
38
Makefile
Normal file
@ -0,0 +1,38 @@
|
||||
# Copyright 2015 Google Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
|
||||
GO := godep go
|
||||
pkgs = $(shell $(GO) list ./...)
|
||||
|
||||
all: format build test
|
||||
|
||||
test:
|
||||
@echo ">> running tests"
|
||||
@$(GO) test -short $(pkgs)
|
||||
|
||||
format:
|
||||
@echo ">> formatting code"
|
||||
@$(GO) fmt $(pkgs)
|
||||
|
||||
vet:
|
||||
@echo ">> vetting code"
|
||||
@$(GO) vet $(pkgs)
|
||||
|
||||
build:
|
||||
@echo ">> building binaries"
|
||||
@./build/build.sh
|
||||
|
||||
docker:
|
||||
@docker build -t cadvisor:$(shell git rev-parse --short HEAD) -f deploy/Dockerfile .
|
||||
|
||||
.PHONY: all format build test vet docker
|
42
build/build.sh
Executable file
42
build/build.sh
Executable file
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2015 Google Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
|
||||
set -e
|
||||
|
||||
repo_path="github.com/google/cadvisor"
|
||||
|
||||
version=$( cat version/VERSION )
|
||||
revision=$( git rev-parse --short HEAD 2> /dev/null || echo 'unknown' )
|
||||
branch=$( git rev-parse --abbrev-ref HEAD 2> /dev/null || echo 'unknown' )
|
||||
host=$( hostname -f )
|
||||
build_date=$( date +%Y%m%d-%H:%M:%S )
|
||||
go_version=$( go version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/' )
|
||||
|
||||
if [ "$(go env GOOS)" = "windows" ]; then
|
||||
› ext=".exe"
|
||||
fi
|
||||
|
||||
ldflags="
|
||||
-X ${repo_path}/version.Version=${version}
|
||||
-X ${repo_path}/version.Revision=${revision}
|
||||
-X ${repo_path}/version.Branch=${branch}
|
||||
-X ${repo_path}/version.BuildUser=${USER}@${host}
|
||||
-X ${repo_path}/version.BuildDate=${build_date}
|
||||
-X ${repo_path}/version.GoVersion=${go_version}"
|
||||
|
||||
echo " > cadvisor"
|
||||
godep go build -ldflags "${ldflags}" -o cadvisor${ext} ${repo_path}
|
||||
|
||||
exit 0
|
@ -54,7 +54,7 @@ func main() {
|
||||
flag.Parse()
|
||||
|
||||
if *versionFlag {
|
||||
fmt.Printf("cAdvisor version %s\n", version.VERSION)
|
||||
fmt.Printf("cAdvisor version %s (%s)\n", version.Info["version"], version.Info["revision"])
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ func main() {
|
||||
// Install signal handler.
|
||||
installSignalHandler(containerManager)
|
||||
|
||||
glog.Infof("Starting cAdvisor version: %q on port %d", version.VERSION, *argPort)
|
||||
glog.Infof("Starting cAdvisor version: %s-%s on port %d", version.Info["version"], version.Info["revision"], *argPort)
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", *argIp, *argPort)
|
||||
glog.Fatal(http.ListenAndServe(addr, nil))
|
||||
|
@ -179,6 +179,8 @@ type VersionInfo struct {
|
||||
|
||||
// cAdvisor version.
|
||||
CadvisorVersion string `json:"cadvisor_version"`
|
||||
// cAdvisor git revision.
|
||||
CadvisorRevision string `json:"cadvisor_revision"`
|
||||
}
|
||||
|
||||
type MachineInfoFactory interface {
|
||||
|
@ -122,7 +122,8 @@ func getVersionInfo() (*info.VersionInfo, error) {
|
||||
KernelVersion: kernel_version,
|
||||
ContainerOsVersion: container_os,
|
||||
DockerVersion: docker_version,
|
||||
CadvisorVersion: version.VERSION,
|
||||
CadvisorVersion: version.Info["version"],
|
||||
CadvisorRevision: version.Info["revision"],
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -453,7 +453,7 @@ func NewPrometheusCollector(infoProvider infoProvider) *PrometheusCollector {
|
||||
}
|
||||
|
||||
var (
|
||||
versionInfoDesc = prometheus.NewDesc("cadvisor_version_info", "A metric with a constant '1' value labeled by kernel version, OS version, docker version & cadvisor version.", []string{"kernelVersion", "osVersion", "dockerVersion", "cadvisorVersion"}, nil)
|
||||
versionInfoDesc = prometheus.NewDesc("cadvisor_version_info", "A metric with a constant '1' value labeled by kernel version, OS version, docker version, cadvisor version & cadvisor revision.", []string{"kernelVersion", "osVersion", "dockerVersion", "cadvisorVersion", "cadvisorRevision"}, nil)
|
||||
machineInfoCoresDesc = prometheus.NewDesc("machine_cpu_cores", "Number of CPU cores on the machine.", nil, nil)
|
||||
machineInfoMemoryDesc = prometheus.NewDesc("machine_memory_bytes", "Amount of memory installed on the machine.", nil, nil)
|
||||
)
|
||||
@ -534,7 +534,7 @@ func (c *PrometheusCollector) collectVersionInfo(ch chan<- prometheus.Metric) {
|
||||
glog.Warningf("Couldn't get version info: %s", err)
|
||||
return
|
||||
}
|
||||
ch <- prometheus.MustNewConstMetric(versionInfoDesc, prometheus.GaugeValue, 1, []string{versionInfo.KernelVersion, versionInfo.ContainerOsVersion, versionInfo.DockerVersion, versionInfo.CadvisorVersion}...)
|
||||
ch <- prometheus.MustNewConstMetric(versionInfoDesc, prometheus.GaugeValue, 1, []string{versionInfo.KernelVersion, versionInfo.ContainerOsVersion, versionInfo.DockerVersion, versionInfo.CadvisorVersion, versionInfo.CadvisorRevision}...)
|
||||
}
|
||||
|
||||
func (c *PrometheusCollector) collectMachineInfo(ch chan<- prometheus.Metric) {
|
||||
|
@ -35,6 +35,7 @@ func (p testSubcontainersInfoProvider) GetVersionInfo() (*info.VersionInfo, erro
|
||||
ContainerOsVersion: "Fedora 22 (Twenty Two)",
|
||||
DockerVersion: "1.8.1",
|
||||
CadvisorVersion: "0.16.0",
|
||||
CadvisorRevision: "abcdef",
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -170,7 +171,7 @@ func TestPrometheusCollector(t *testing.T) {
|
||||
// (https://github.com/prometheus/client_golang/issues/58), we simply compare
|
||||
// verbatim text-format metrics outputs, but ignore certain metric lines
|
||||
// whose value depends on the current time or local circumstances.
|
||||
includeRe := regexp.MustCompile("^(# HELP |# TYPE |)container_")
|
||||
includeRe := regexp.MustCompile("^(?:(?:# HELP |# TYPE)container_|cadvisor_version_info{)")
|
||||
ignoreRe := regexp.MustCompile("^container_last_seen{")
|
||||
for i, want := range wantLines {
|
||||
if !includeRe.MatchString(want) || ignoreRe.MatchString(want) {
|
||||
|
2
metrics/testdata/prometheus_metrics
vendored
2
metrics/testdata/prometheus_metrics
vendored
@ -1,6 +1,6 @@
|
||||
# HELP cadvisor_version_info A metric with a constant '1' value labeled by kernel version, OS version, docker version & cadvisor version.
|
||||
# TYPE cadvisor_version_info gauge
|
||||
cadvisor_version_info{cadvisorVersion="0.16.0",dockerVersion="1.8.1",kernelVersion="4.1.6-200.fc22.x86_64",osVersion="Fedora 22 (Twenty Two)"} 1
|
||||
cadvisor_version_info{cadvisorRevision="abcdef",cadvisorVersion="0.16.0",dockerVersion="1.8.1",kernelVersion="4.1.6-200.fc22.x86_64",osVersion="Fedora 22 (Twenty Two)"} 1
|
||||
# HELP container_cpu_system_seconds_total Cumulative system cpu time consumed in seconds.
|
||||
# TYPE container_cpu_system_seconds_total counter
|
||||
container_cpu_system_seconds_total{id="testcontainer",image="test",name="testcontaineralias"} 7e-09
|
||||
|
1
version/VERSION
Normal file
1
version/VERSION
Normal file
@ -0,0 +1 @@
|
||||
0.18.0
|
@ -14,5 +14,22 @@
|
||||
|
||||
package version
|
||||
|
||||
// Version of cAdvisor.
|
||||
const VERSION = "0.18.0"
|
||||
// Build information. Populated at build-time.
|
||||
var (
|
||||
Version string
|
||||
Revision string
|
||||
Branch string
|
||||
BuildUser string
|
||||
BuildDate string
|
||||
GoVersion string
|
||||
)
|
||||
|
||||
// Info provides the iterable version information.
|
||||
var Info = map[string]string{
|
||||
"version": Version,
|
||||
"revision": Revision,
|
||||
"branch": Branch,
|
||||
"buildUser": BuildUser,
|
||||
"buildDate": BuildDate,
|
||||
"goVersion": GoVersion,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user