Skip to content

Commit 996cb83

Browse files
thorfourThorpracucci
authored
include Cortex version in cortex_build_info (#2468)
* include build info in cortex_build_info metric Signed-off-by: Thor <[email protected]> * Added CHANGELOG entry Signed-off-by: Marco Pracucci <[email protected]> Co-authored-by: Thor <[email protected]> Co-authored-by: Marco Pracucci <[email protected]>
1 parent 74ea373 commit 996cb83

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* [BUGFIX] Experimental TSDB: fixed response status code from `422` to `500` when an error occurs while iterating chunks with the experimental blocks storage. #2402
3131
* [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
3232
* [BUGFIX] Distributor: `/all_user_stats` now show API and Rule Ingest Rate correctly. #2457
33+
* [BUGFIX] Fixed `version`, `revision` and `branch` labels exported by the `cortex_build_info` metric. #2468
3334

3435
## 1.0.0 / 2020-04-02
3536

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
.PHONY: all test clean images protos exes dist
22
.DEFAULT_GOAL := all
33

4+
# Version number
5+
VERSION=$(shell cat "./VERSION" 2> /dev/null)
6+
47
# Boiler plate for building Docker containers.
58
# All this must go at top of file I'm afraid.
69
IMAGE_PREFIX ?= quay.io/cortexproject/
710
# Use CIRCLE_TAG if present for releases.
811
IMAGE_TAG ?= $(if $(CIRCLE_TAG),$(CIRCLE_TAG),$(shell ./tools/image-tag))
9-
GIT_REVISION := $(shell git rev-parse HEAD)
12+
GIT_REVISION := $(shell git rev-parse --short HEAD)
13+
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
1014
UPTODATE := .uptodate
1115

1216
# Support gsed on OSX (installed via brew), falling back to sed. On Linux
@@ -82,7 +86,7 @@ RM := --rm
8286
# as it currently disallows TTY devices. This value needs to be overridden
8387
# in any custom cloudbuild.yaml files
8488
TTY := --tty
85-
GO_FLAGS := -ldflags "-extldflags \"-static\" -s -w" -tags netgo
89+
GO_FLAGS := -ldflags "-X main.Branch=$(GIT_BRANCH) -X main.Revision=$(GIT_REVISION) -X main.Version=$(VERSION) -extldflags \"-static\" -s -w" -tags netgo
8690

8791
ifeq ($(BUILD_IN_CONTAINER),true)
8892

cmd/cortex/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ import (
2222
"github.com/cortexproject/cortex/pkg/util/flagext"
2323
)
2424

25+
// Version is set via build flag -ldflags -X main.Version
26+
var (
27+
Version string
28+
Branch string
29+
Revision string
30+
)
31+
2532
func init() {
33+
version.Version = Version
34+
version.Branch = Branch
35+
version.Revision = Revision
2636
prometheus.MustRegister(version.NewCollector("cortex"))
2737
}
2838

0 commit comments

Comments
 (0)