From 008b3a138f452a7a1769c3f83a946eabbd0b165d Mon Sep 17 00:00:00 2001 From: Thomas Jackson Date: Thu, 27 Sep 2018 09:35:22 -0700 Subject: [PATCH] Add version flag to promxy Fixes #40 --- build.bash | 4 ++-- cmd/promxy/main.go | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/build.bash b/build.bash index 1f4bb1b0e..0b659752f 100755 --- a/build.bash +++ b/build.bash @@ -1,6 +1,6 @@ #!/usr/bin/env bash -VERSION=`git describe --tags` +VERSION=`git describe --tags --dirty` package=$1 destination=$2 @@ -23,7 +23,7 @@ do output_name+='.exe' fi - env GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build -o $destination/$output_name $package + env GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build -x -ldflags="-X main.Version=$VERSION" -o $destination/$output_name $package if [ $? -ne 0 ]; then echo 'An error has occurred! Aborting the script execution...' exit 1 diff --git a/cmd/promxy/main.go b/cmd/promxy/main.go index 980cc45ff..4a6abdd31 100644 --- a/cmd/promxy/main.go +++ b/cmd/promxy/main.go @@ -49,11 +49,14 @@ var ( Name: "process_reload_time_seconds", Help: "Last reload (SIGHUP) time of the process since unix epoch in seconds.", }) + Version = "" ) type CLIOpts struct { + Version bool `long:"version" short:"v" description:"print out version and exit"` + BindAddr string `long:"bind-addr" description:"address for promxy to listen on" default:":8082"` - ConfigFile string `long:"config" description:"path to the config file" required:"true"` + ConfigFile string `long:"config" description:"path to the config file" default:"config.yaml"` LogLevel string `long:"log-level" description:"Log level" default:"info"` ExternalURL string `long:"web.external-url" description:"The URL under which Prometheus is externally reachable (for example, if Prometheus is served via a reverse proxy). Used for generating relative and absolute links back to Prometheus itself. If the URL has a path portion, it will be used to prefix all HTTP endpoints served by Prometheus. If omitted, relevant URL components will be derived automatically."` @@ -118,6 +121,11 @@ func main() { logrus.Fatalf("Error parsing flags: %v", err) } + if opts.Version { + fmt.Println("Version", Version) + os.Exit(0) + } + // Use log level level := logrus.InfoLevel switch strings.ToLower(opts.LogLevel) {