Skip to content

Commit 30dba91

Browse files
authored
Print binary version info on gateway startup (observatorium#649)
Signed-off-by: Ruben Vargas <[email protected]>
1 parent 89cbeb8 commit 30dba91

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Diff for: Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ OS ?= $(shell go env GOOS)
88
ARCH ?= $(shell go env GOARCH)
99
BIN_NAME ?= observatorium-api
1010
FILES_TO_FMT ?= $(filter-out ./ratelimit/gubernator/gubernator.pb.go, $(shell find . -path ./vendor -not -prune -o -name '*.go' -print))
11+
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
12+
GIT_REVISION := $(shell git rev-parse --short HEAD)
1113

1214
VERSION := $(strip $(shell [ -d .git ] && git describe --always --tags --dirty))
1315
BUILD_DATE := $(shell date -u +"%Y-%m-%d")
@@ -79,7 +81,7 @@ benchmark.md: $(EMBEDMD) tmp/load_help.txt
7981
$(EMBEDMD) -w docs/benchmark.md
8082

8183
$(BIN_NAME): deps main.go rules/rules.go $(wildcard *.go) $(wildcard */*.go)
82-
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) GO111MODULE=on GOPROXY=https://proxy.golang.org go build -a -ldflags '-s -w' -o $(BIN_NAME) .
84+
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) GO111MODULE=on GOPROXY=https://proxy.golang.org go build -a -ldflags '-s -w -X main.Version=$(VERSION) -X main.Branch=$(GIT_BRANCH) -X main.Revision=$(GIT_REVISION)' -o $(BIN_NAME) .
8385

8486
%.y.go: %.y | $(GOYACC)
8587
$(GOYACC) -p $(basename $(notdir $<)) -o $@ $<

Diff for: main.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ const (
8282
gracePeriod = 2 * time.Minute
8383
)
8484

85+
// Version is set via build flag -ldflags -X main.Version.
86+
var (
87+
Version string
88+
Branch string
89+
Revision string
90+
)
91+
8592
type config struct {
8693
logLevel string
8794
logFormat string
@@ -258,13 +265,21 @@ type tenant struct {
258265
} `json:"rateLimits"`
259266
}
260267

268+
func init() {
269+
version.Version = Version
270+
version.Branch = Branch
271+
version.Revision = Revision
272+
}
273+
261274
//nolint:funlen,gocyclo,gocognit
262275
func main() {
263276
cfg, err := parseFlags()
264277
if err != nil {
265278
stdlog.Fatalf("parse flag: %v", err)
266279
}
267280

281+
stdlog.Println(version.Info())
282+
268283
if !cfg.metrics.enabled && !cfg.logs.enabled && !cfg.traces.enabled {
269284
stdlog.Fatal("Neither logging, metrics not traces endpoints are enabled. " +
270285
"Specifying at least a logging or a metrics endpoint is mandatory")
@@ -1018,7 +1033,6 @@ func parseFlags() (config, error) {
10181033
)
10191034

10201035
cfg := config{}
1021-
10221036
flag.StringVar(&cfg.rbacConfigPath, "rbac.config", "rbac.yaml",
10231037
"Path to the RBAC configuration file.")
10241038
flag.StringVar(&cfg.tenantsConfigPath, "tenants.config", "tenants.yaml",

0 commit comments

Comments
 (0)