From 033533c4c542cb7317602481293b3f72cb89d63d Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Thu, 25 Apr 2013 11:47:48 +0200 Subject: [PATCH 1/8] Capture build information and print with -version --- Makefile | 18 ++++++++++++++++-- build_info.go | 38 ++++++++++++++++++++++++++++++++++++++ main.go | 7 +++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 build_info.go diff --git a/Makefile b/Makefile index ee895f8f8..12d8e68b3 100644 --- a/Makefile +++ b/Makefile @@ -17,16 +17,30 @@ TEST_ARTIFACTS = prometheus prometheus.build search_index include Makefile.INCLUDE +REV := $(shell git rev-parse --short HEAD) +BRANCH := $(shell git rev-parse --abbrev-ref HEAD) +HOSTNAME := $(shell hostname) +BUILD_DATE := $(shell date) +BUILDFLAGS := -ldflags \ + " -X main.buildVersion $(REV)\ + -X main.buildBranch $(BRANCH)\ + -X main.buildUser $(USER)@$(HOSTNAME)\ + -X main.buildDate '$(BUILD_DATE)'\ + -X main.goVersion '$(GO_VERSION)'\ + -X main.leveldbVersion '$(LEVELDB_VERSION)'\ + -X main.protobufVersion '$(PROTOCOL_BUFFERS_VERSION)'\ + -X main.snappyVersion '$(SNAPPY_VERSION)'" + all: test advice: go tool vet . binary: build - go build -o prometheus.build + go build $(BUILDFLAGS) -o prometheus.build build: preparation model web - go build . + go build $(BUILDFLAGS) . clean: $(MAKE) -C build clean diff --git a/build_info.go b/build_info.go new file mode 100644 index 000000000..0231a8387 --- /dev/null +++ b/build_info.go @@ -0,0 +1,38 @@ +package main + +import ( + "text/template" +) + +// Build information. Populated by Makefile. +var ( + buildVersion string + buildBranch string + buildUser string + buildDate string + goVersion string + leveldbVersion string + protobufVersion string + snappyVersion string +) + +var BuildInfo = map[string]string{ + "version": buildVersion, + "branch": buildBranch, + "user": buildUser, + "date": buildDate, + "go_version": goVersion, + "leveldb_version": leveldbVersion, + "protobuf_version": protobufVersion, + "snappy_version": snappyVersion, +} + +var versionInfoTmpl = template.Must(template.New("version").Parse( + `prometheus, version {{.version}} ({{.branch}}) + build user: {{.user}} + build date: {{.date}} + go version: {{.go_version}} + leveldb version: {{.leveldb_version}} + protobuf version: {{.protobuf_version}} + snappy version: {{.snappy_version}} +`)) diff --git a/main.go b/main.go index 85bbee144..a1cb15c0b 100644 --- a/main.go +++ b/main.go @@ -34,6 +34,7 @@ import ( var ( _ = fmt.Sprintf("") + printVersion = flag.Bool("version", false, "print version information") configFile = flag.String("configFile", "prometheus.conf", "Prometheus configuration file name.") metricsStoragePath = flag.String("metricsStoragePath", "/tmp/metrics", "Base path for metrics storage.") scrapeResultsQueueCapacity = flag.Int("scrapeResultsQueueCapacity", 4096, "The size of the scrape results queue.") @@ -45,6 +46,12 @@ var ( func main() { flag.Parse() + + if *printVersion { + versionInfoTmpl.Execute(os.Stdout, BuildInfo) + os.Exit(0) + } + conf, err := config.LoadFromFile(*configFile) if err != nil { log.Fatalf("Error loading configuration from %s: %v", *configFile, err) From a2a4f94aae1d610c185ca56f079dbfc005ed9461 Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Thu, 25 Apr 2013 11:57:08 +0200 Subject: [PATCH 2/8] StatusHandler renders build info --- appstate/appstate.go | 1 + main.go | 1 + web/status.go | 2 ++ web/templates/status.html | 34 +++++++++++++++++++++++----------- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/appstate/appstate.go b/appstate/appstate.go index 7938227b3..792529623 100644 --- a/appstate/appstate.go +++ b/appstate/appstate.go @@ -28,4 +28,5 @@ type ApplicationState struct { RuleManager rules.RuleManager Storage metric.Storage TargetManager retrieval.TargetManager + BuildInfo map[string]string } diff --git a/main.go b/main.go index a1cb15c0b..baa3075a2 100644 --- a/main.go +++ b/main.go @@ -91,6 +91,7 @@ func main() { RuleManager: ruleManager, Storage: ts, TargetManager: targetManager, + BuildInfo: BuildInfo, } web.StartServing(appState) diff --git a/web/status.go b/web/status.go index 2874fe9d7..b20bb9b4f 100644 --- a/web/status.go +++ b/web/status.go @@ -24,6 +24,7 @@ type PrometheusStatus struct { Rules string Status string TargetPools map[string]*retrieval.TargetPool + BuildInfo map[string]string } type StatusHandler struct { @@ -36,6 +37,7 @@ func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { Rules: "TODO: list rules here", Status: "TODO: add status information here", TargetPools: h.appState.TargetManager.Pools(), + BuildInfo: h.appState.BuildInfo, } executeTemplate(w, "status", status) } diff --git a/web/templates/status.html b/web/templates/status.html index 26b27b6a4..e1a239eb1 100644 --- a/web/templates/status.html +++ b/web/templates/status.html @@ -2,23 +2,23 @@ {{define "content"}}

Status

-
+
{{.Status}} -
+
-

Configuration

-
-
+    

Configuration

+
+
 {{.Config}}
-		
-
+
+

Rules

-
+
{{.Rules}} -
+
-

Targets

+

Targets

    {{range $job, $pool := .TargetPools}} @@ -33,5 +33,17 @@ {{end}}
-
+ + +

Build Info

+
+ + {{range $key, $value := .BuildInfo}} + + + + + {{end}} +
{{$key}}{{$value}}
+
{{end}} From 862054e88bf1760b73c95de1b0402d59d950e79e Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Thu, 25 Apr 2013 11:59:39 +0200 Subject: [PATCH 3/8] web.StartServing prints listening address --- web/web.go | 1 + 1 file changed, 1 insertion(+) diff --git a/web/web.go b/web/web.go index 721219346..5917f626e 100644 --- a/web/web.go +++ b/web/web.go @@ -56,6 +56,7 @@ func StartServing(appState *appstate.ApplicationState) { exp.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler))) } + log.Printf("listening on %s", *listenAddress) go http.ListenAndServe(*listenAddress, exp.DefaultCoarseMux) } From 45243ac2da10c138ad9ca5e22c3f4fb5d47f6d46 Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Thu, 25 Apr 2013 12:11:21 +0200 Subject: [PATCH 4/8] Print flags on status page. --- web/static/css/prometheus.css | 4 ++++ web/status.go | 9 +++++++++ web/templates/status.html | 28 ++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/web/static/css/prometheus.css b/web/static/css/prometheus.css index d46ae56b8..7e76a5b32 100644 --- a/web/static/css/prometheus.css +++ b/web/static/css/prometheus.css @@ -35,6 +35,10 @@ input:not([type=submit]):not([type=file]):not([type=button]) { float: right; } +table tbody th { + text-align: left; +} + input { margin: 0; border: 1px solid gray; diff --git a/web/status.go b/web/status.go index b20bb9b4f..fb60905f4 100644 --- a/web/status.go +++ b/web/status.go @@ -14,6 +14,7 @@ package web import ( + "flag" "github.com/prometheus/prometheus/appstate" "github.com/prometheus/prometheus/retrieval" "net/http" @@ -25,6 +26,7 @@ type PrometheusStatus struct { Status string TargetPools map[string]*retrieval.TargetPool BuildInfo map[string]string + Flags map[string]string } type StatusHandler struct { @@ -32,12 +34,19 @@ type StatusHandler struct { } func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + flags := map[string]string{} + + flag.VisitAll(func(f *flag.Flag) { + flags[f.Name] = f.Value.String() + }) + status := &PrometheusStatus{ Config: h.appState.Config.ToString(0), Rules: "TODO: list rules here", Status: "TODO: add status information here", TargetPools: h.appState.TargetManager.Pools(), BuildInfo: h.appState.BuildInfo, + Flags: flags, } executeTemplate(w, "status", status) } diff --git a/web/templates/status.html b/web/templates/status.html index e1a239eb1..b8a63a69c 100644 --- a/web/templates/status.html +++ b/web/templates/status.html @@ -38,12 +38,28 @@

Build Info

- {{range $key, $value := .BuildInfo}} - - - - - {{end}} + + {{range $key, $value := .BuildInfo}} + + + + + {{end}} + +
{{$key}}{{$value}}
{{$key}}{{$value}}
+
+ +

Startup Flags

+
+ + + {{range $key, $value := .Flags}} + + + + + {{end}} +
{{$key}}{{$value}}
{{end}} From c152aa514fdb8781bfbedfd00e6e38c2e0276ae2 Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Thu, 25 Apr 2013 13:14:50 +0200 Subject: [PATCH 5/8] Always print version information when starting up --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index baa3075a2..95ab3ef54 100644 --- a/main.go +++ b/main.go @@ -47,8 +47,9 @@ var ( func main() { flag.Parse() + versionInfoTmpl.Execute(os.Stdout, BuildInfo) + if *printVersion { - versionInfoTmpl.Execute(os.Stdout, BuildInfo) os.Exit(0) } From 9dde9302a8a258bacace35b7edeba7b28a5824fb Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Thu, 25 Apr 2013 13:19:35 +0200 Subject: [PATCH 6/8] Explicitly include domain info in build hostname --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 12d8e68b3..4a9a28b2f 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ include Makefile.INCLUDE REV := $(shell git rev-parse --short HEAD) BRANCH := $(shell git rev-parse --abbrev-ref HEAD) -HOSTNAME := $(shell hostname) +HOSTNAME := $(shell hostname -f) BUILD_DATE := $(shell date) BUILDFLAGS := -ldflags \ " -X main.buildVersion $(REV)\ From 378e494433dbc5a45188a80181dd78fe700c78ba Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Thu, 25 Apr 2013 15:07:35 +0200 Subject: [PATCH 7/8] Date format for build info doesn't include spaces go 1.0.3 doesn't support spaces in -X linker options. --- Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 4a9a28b2f..5c0e666e0 100644 --- a/Makefile +++ b/Makefile @@ -20,16 +20,16 @@ include Makefile.INCLUDE REV := $(shell git rev-parse --short HEAD) BRANCH := $(shell git rev-parse --abbrev-ref HEAD) HOSTNAME := $(shell hostname -f) -BUILD_DATE := $(shell date) +BUILD_DATE := $(shell date +%Y%m%d-%H:%M:%S) BUILDFLAGS := -ldflags \ " -X main.buildVersion $(REV)\ -X main.buildBranch $(BRANCH)\ -X main.buildUser $(USER)@$(HOSTNAME)\ - -X main.buildDate '$(BUILD_DATE)'\ - -X main.goVersion '$(GO_VERSION)'\ - -X main.leveldbVersion '$(LEVELDB_VERSION)'\ - -X main.protobufVersion '$(PROTOCOL_BUFFERS_VERSION)'\ - -X main.snappyVersion '$(SNAPPY_VERSION)'" + -X main.buildDate $(BUILD_DATE)\ + -X main.goVersion $(GO_VERSION)\ + -X main.leveldbVersion $(LEVELDB_VERSION)\ + -X main.protobufVersion $(PROTOCOL_BUFFERS_VERSION)\ + -X main.snappyVersion $(SNAPPY_VERSION)" all: test From 2fd9b8180d49cc444de3d7d0467747c09dbc33d1 Mon Sep 17 00:00:00 2001 From: Bernerd Schaefer Date: Thu, 25 Apr 2013 16:14:58 +0200 Subject: [PATCH 8/8] Add license header to build_info.go --- build_info.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/build_info.go b/build_info.go index 0231a8387..fe00fa49d 100644 --- a/build_info.go +++ b/build_info.go @@ -1,3 +1,16 @@ +// Copyright 2013 Prometheus Team +// 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 +// limitations under the License. + package main import (