From 37d34e95d0a8f9b517debdde0d8471a05c54dcd7 Mon Sep 17 00:00:00 2001 From: Thor Date: Wed, 15 Apr 2020 10:56:19 -0500 Subject: [PATCH 1/2] include build info in cortex_build_info metric Signed-off-by: Thor --- Makefile | 8 ++++++-- cmd/cortex/main.go | 10 ++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2d91f14829a..27facde157f 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,16 @@ .PHONY: all test clean images protos exes dist .DEFAULT_GOAL := all +# Version number +VERSION=$(shell cat "./VERSION" 2> /dev/null) + # Boiler plate for building Docker containers. # All this must go at top of file I'm afraid. IMAGE_PREFIX ?= quay.io/cortexproject/ # Use CIRCLE_TAG if present for releases. IMAGE_TAG ?= $(if $(CIRCLE_TAG),$(CIRCLE_TAG),$(shell ./tools/image-tag)) -GIT_REVISION := $(shell git rev-parse HEAD) +GIT_REVISION := $(shell git rev-parse --short HEAD) +GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD) UPTODATE := .uptodate # Support gsed on OSX (installed via brew), falling back to sed. On Linux @@ -82,7 +86,7 @@ RM := --rm # as it currently disallows TTY devices. This value needs to be overridden # in any custom cloudbuild.yaml files TTY := --tty -GO_FLAGS := -ldflags "-extldflags \"-static\" -s -w" -tags netgo +GO_FLAGS := -ldflags "-X main.Branch=$(GIT_BRANCH) -X main.Revision=$(GIT_REVISION) -X main.Version=$(VERSION) -extldflags \"-static\" -s -w" -tags netgo ifeq ($(BUILD_IN_CONTAINER),true) diff --git a/cmd/cortex/main.go b/cmd/cortex/main.go index ccb17cd7a67..4c0e0cd382e 100644 --- a/cmd/cortex/main.go +++ b/cmd/cortex/main.go @@ -22,7 +22,17 @@ import ( "github.com/cortexproject/cortex/pkg/util/flagext" ) +// Version is set via build flag -ldflags -X main.Version +var ( + Version string + Branch string + Revision string +) + func init() { + version.Version = Version + version.Branch = Branch + version.Revision = Revision prometheus.MustRegister(version.NewCollector("cortex")) } From c7c5e8a9119f8b6bb01e4a825a1f9b356c132482 Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Fri, 17 Apr 2020 10:58:48 +0200 Subject: [PATCH 2/2] Added CHANGELOG entry Signed-off-by: Marco Pracucci --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a095b7f75c6..23bd61b7007 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ * [BUGFIX] Experimental TSDB: fixed response status code from `422` to `500` when an error occurs while iterating chunks with the experimental blocks storage. #2402 * [BUGFIX] Ring: Fixed a situation where upgrading from pre-1.0 cortex with a rolling strategy caused new 1.0 ingesters to lose their zone value in the ring until manually forced to re-register. #2404 * [BUGFIX] Distributor: `/all_user_stats` now show API and Rule Ingest Rate correctly. #2457 +* [BUGFIX] Fixed `version`, `revision` and `branch` labels exported by the `cortex_build_info` metric. #2468 ## 1.0.0 / 2020-04-02