diff --git a/Makefile b/Makefile index e222803..beb5d32 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ REPOSITORY := mattdeboer/mpp DOCKER_IMAGE = ${REPOSITORY}:${VERSION} BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) REVISION ?= $(shell git rev-parse HEAD) -LD_FLAGS ?= -s -X main.Name=$(TARGET) -X main.Revision=$(REVISION) -X main.Branch=$(BRANCH) -X main.Version=$(VERSION) +LD_FLAGS ?= -s -X version.Name=$(TARGET) -X version.Revision=$(REVISION) -X version.Branch=$(BRANCH) -X version.Version=$(VERSION) default: test build diff --git a/pkg/router/metrics.go b/pkg/router/metrics.go index 77bb49e..b5248ab 100644 --- a/pkg/router/metrics.go +++ b/pkg/router/metrics.go @@ -1,8 +1,8 @@ package router -import "github.com/prometheus/client_golang/prometheus" - -const metricsNamespace = "mpp" +import ( + "github.com/prometheus/client_golang/prometheus" +) type metrics struct { selectedBackends prometheus.Gauge diff --git a/pkg/router/router.go b/pkg/router/router.go index f6f49a8..7813b73 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -12,6 +12,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/matt-deboer/mpp/pkg/locator" "github.com/matt-deboer/mpp/pkg/selector" + "github.com/matt-deboer/mpp/pkg/version" "github.com/vulcand/oxy/buffer" "github.com/vulcand/oxy/forward" ) @@ -58,7 +59,7 @@ func NewRouter(interval time.Duration, affinityOptions []AffinityOption, selector: sel, affinityOptions: affinityOptions, interval: interval, - metrics: newMetrics(metricsNamespace), + metrics: newMetrics(version.Name), theConch: make(chan struct{}, 1), } diff --git a/pkg/server/handler.go b/pkg/server/handler.go index 8619204..ec947ca 100644 --- a/pkg/server/handler.go +++ b/pkg/server/handler.go @@ -9,6 +9,7 @@ import ( log "github.com/Sirupsen/logrus" "github.com/matt-deboer/mpp/pkg/router" + "github.com/matt-deboer/mpp/pkg/version" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) @@ -31,10 +32,10 @@ func newMPPHandler(r *router.Router) *mppHandler { Name: "build_info", Help: "The number of currently selected backends", ConstLabels: prometheus.Labels{ - "branch": Branch, + "branch": version.Branch, "goversion": runtime.Version(), - "version": Version, - "revision": Revision, + "version": version.Version, + "revision": version.Revision, }, }) buildInfo.Set(1) @@ -56,7 +57,7 @@ func (p *mppHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { data := &templateData{ RouterStatus: p.router.Status(), Uptime: time.Now().Sub(p.started), - Version: Version, + Version: version.Version, GoVersion: runtime.Version(), } if log.GetLevel() >= log.DebugLevel { diff --git a/pkg/server/main.go b/pkg/server/main.go index 5b81824..18424db 100644 --- a/pkg/server/main.go +++ b/pkg/server/main.go @@ -1,4 +1,4 @@ -package main +package main // import "github.com/matt-deboer/mpp/pkg/server" import ( "fmt" @@ -16,29 +16,19 @@ import ( _ "github.com/matt-deboer/mpp/pkg/selector/strategy/minimumhistory" _ "github.com/matt-deboer/mpp/pkg/selector/strategy/random" _ "github.com/matt-deboer/mpp/pkg/selector/strategy/singlemostdata" + "github.com/matt-deboer/mpp/pkg/version" "github.com/urfave/cli" ) -var ( - // Name is set at compile time based on the git repository - Name string - // Version is set at compile time with the git version - Version string - // Branch is set at compile time with the git version - Branch string - // Revision is set at compile time with the git version - Revision string -) - func main() { app := cli.NewApp() - app.Name = Name + app.Name = version.Name app.Usage = ` Launch a dynamically configured proxy over multiple prometheus endpoints which selects a single endpoint based on configurable criteria. ` - app.Version = Version + app.Version = version.Version app.Flags = []cli.Flag{ cli.StringFlag{ Name: "kubeconfig", diff --git a/pkg/version/doc.go b/pkg/version/doc.go new file mode 100644 index 0000000..5fcfb1c --- /dev/null +++ b/pkg/version/doc.go @@ -0,0 +1,13 @@ +// Package version contains build-time version info +package version // import "github.com/matt-deboer/mpp/pkg/version" + +var ( + // Name is set at compile time based on the git repository + Name string + // Version is set at compile time with the git version + Version string + // Branch is set at compile time with the git version + Branch string + // Revision is set at compile time with the git version + Revision string +)