Skip to content

Commit d923ee8

Browse files
authored
Merge pull request prometheus-community#6 from nlamirault/version-flag
Add: flag to print version of the application
2 parents 5f53668 + f26f4da commit d923ee8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ GO_SRC := dbms_exporter.go $(shell find ${GO_DIRS} -name '*.go')
55
CONTAINER_NAME = ncabatoff/dbms_exporter:latest
66
FREETDS_VERSION = 1.1.5
77
BUILD_CONTAINER_NAME = ncabatoff/dbms_exporter_builder:${FREETDS_VERSION}
8+
TAG_VERSION ?= $(shell git describe --tags --abbrev=0)
9+
810
# Possible BUILDTAGS settings are postgres, freetds, and odbc.
911
DRIVERS = postgres freetds
1012
# Use make LDFLAGS= if you want to build with tag ODBC.
@@ -14,7 +16,7 @@ all: vet test dbms_exporter
1416

1517
# Simple go build
1618
dbms_exporter: $(GO_SRC)
17-
go build -ldflags '$(LDFLAGS) -X main.Version=git:$(shell git rev-parse HEAD)' -o dbms_exporter -tags '$(DRIVERS)' .
19+
go build -ldflags '$(LDFLAGS) -X main.Version=$(TAG_VERSION)' -o dbms_exporter -tags '$(DRIVERS)' .
1820

1921
docker: Dockerfile $(GO_SRC)
2022
docker build --build-arg drivers="$(DRIVERS)" --build-arg ldflags="$(LDFLAGS)" -t $(CONTAINER_NAME) .
@@ -24,7 +26,7 @@ vet:
2426

2527
test:
2628
go test -v . ./config ./common ./db ./recipes
27-
29+
2830
test-integration:
2931
tests/test-smoke
3032

dbms_exporter.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import (
1919
"github.com/prometheus/common/log"
2020
)
2121

22-
var Version string = "0.0.1"
22+
// Version is set at build time use ldflags.
23+
var Version string
2324

2425
var (
26+
version = flag.Bool("version", false, "print version and exit")
2527
listenAddress = flag.String(
2628
"web.listen-address", ":9113",
2729
"Address to listen on for web interface and telemetry.",
@@ -458,6 +460,10 @@ func main() {
458460
fmt.Fprintf(os.Stderr, usage)
459461
}
460462
flag.Parse()
463+
if *version {
464+
fmt.Printf("dbms-exporter version %s\n", Version)
465+
os.Exit(0)
466+
}
461467

462468
if *queriesPath == "" {
463469
log.Fatalf("-queryfile is a required argument")
@@ -508,7 +514,7 @@ func main() {
508514

509515
var usage = `
510516
The DATA_SOURCE_NAME enviroment variable specifies connection details. Examples:
511-
517+
512518
Sybase FreeTDS example (driver=freetds):
513519
compatibility_mode=sybase;user=myuser;pwd=mypassword;server=myhostname
514520

0 commit comments

Comments
 (0)