From 58a2a82d527d2147bd3c71f84598deee0f6dbc92 Mon Sep 17 00:00:00 2001 From: gunnaraasen Date: Fri, 13 Jan 2017 15:10:50 -0800 Subject: [PATCH] Add X-Chronograf-Version header --- CHANGELOG.md | 1 + Makefile | 2 +- server/server.go | 2 ++ server/version.go | 13 +++++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 server/version.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b50bafb9..088442da6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ 4. [#706](https://github.com/influxdata/chronograf/issues/706): Alerts on threshold where value is inside of range 5. [#707](https://github.com/influxdata/chronograf/issues/707): Alerts on threshold where value is outside of range 6. [#766](https://github.com/influxdata/chronograf/pull/766): Add click-to-insert functionality to rule message templates + 7. [#766](https://github.com/influxdata/chronograf/pull/772): Add X-Chronograf-Version header to all requests ## v1.1.0-beta5 [2017-01-05] diff --git a/Makefile b/Makefile index 4ce051212..996dded34 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ COMMIT ?= $(shell git rev-parse --short=8 HEAD) SOURCES := $(shell find . -name '*.go') -LDFLAGS=-ldflags "-s -X main.Version=${VERSION} -X main.Commit=${COMMIT}" +LDFLAGS=-ldflags "-s -X main.version=${VERSION} -X main.commit=${COMMIT}" BINARY=chronograf default: dep build diff --git a/server/server.go b/server/server.go index 0db88ad19..363b1bbcc 100644 --- a/server/server.go +++ b/server/server.go @@ -76,6 +76,8 @@ func (s *Server) Serve() error { UseAuth: s.useAuth(), }, service) + s.handler = Version(s.BuildInfo.Version, s.handler) + var err error s.Listener, err = net.Listen("tcp", net.JoinHostPort(s.Host, strconv.Itoa(s.Port))) if err != nil { diff --git a/server/version.go b/server/version.go new file mode 100644 index 000000000..6bf7dbe9d --- /dev/null +++ b/server/version.go @@ -0,0 +1,13 @@ +package server + +import ( + "net/http" +) + +func Version(version string, h http.Handler) http.Handler { + fn := func(w http.ResponseWriter, r *http.Request) { + w.Header().Add("X-Chronograf-Version", version) + h.ServeHTTP(w, r) + } + return http.HandlerFunc(fn) +}