From 6aae544ac8ef511f72a6dbc9b10b6eeed08f7151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bedn=C3=A1=C5=99?= Date: Thu, 24 Jun 2021 18:33:54 +0200 Subject: [PATCH] fix(pingEndpoint): change build type to 'oss2', use correct version (#21723) Signed-off-by: Jakub Bednar --- http/legacy/backend.go | 2 +- http/legacy/influxqld_handler_test.go | 2 +- http/legacy/ping_handle_test.go | 60 +++++++++++++++++++++++++++ http/legacy/ping_handler.go | 2 +- http/platform_handler.go | 2 +- 5 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 http/legacy/ping_handle_test.go diff --git a/http/legacy/backend.go b/http/legacy/backend.go index 33c7f61aa91..287e2fa4431 100644 --- a/http/legacy/backend.go +++ b/http/legacy/backend.go @@ -45,7 +45,7 @@ type HandlerConfig struct { } func NewHandlerConfig() *HandlerConfig { - return &HandlerConfig{} + return &HandlerConfig{Version: influxdb.GetBuildInfo().Version} } // Opts returns the CLI options for use with kit/cli. diff --git a/http/legacy/influxqld_handler_test.go b/http/legacy/influxqld_handler_test.go index fb54ca76ce0..5bd07f2cbe1 100644 --- a/http/legacy/influxqld_handler_test.go +++ b/http/legacy/influxqld_handler_test.go @@ -233,7 +233,7 @@ func TestInfluxQLdHandler_HandleQuery(t *testing.T) { InfluxqldQueryService: tt.fields.ProxyQueryService, } - h := NewInfluxQLHandler(b, HandlerConfig{}) + h := NewInfluxQLHandler(b, *NewHandlerConfig()) h.Logger = zaptest.NewLogger(t) if tt.context != nil { diff --git a/http/legacy/ping_handle_test.go b/http/legacy/ping_handle_test.go new file mode 100644 index 00000000000..756935c4c2d --- /dev/null +++ b/http/legacy/ping_handle_test.go @@ -0,0 +1,60 @@ +package legacy + +import ( + "net/http" + "net/http/httptest" + "testing" +) + +func TestPingHandler(t *testing.T) { + type wants struct { + statusCode int + version string + build string + } + tests := []struct { + name string + w *httptest.ResponseRecorder + r *http.Request + wants wants + }{ + { + name: "GET request", + w: httptest.NewRecorder(), + r: httptest.NewRequest(http.MethodGet, "/ping", nil), + wants: wants{ + statusCode: http.StatusNoContent, + version: "2.0.0", + build: "oss2", + }, + }, + { + name: "HEAD request", + w: httptest.NewRecorder(), + r: httptest.NewRequest(http.MethodHead, "/ping", nil), + wants: wants{ + statusCode: http.StatusNoContent, + version: "2.0.0", + build: "oss2", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + NewPingHandler("2.0.0").pingHandler(tt.w, tt.r) + res := tt.w.Result() + build := res.Header.Get("X-Influxdb-Build") + version := res.Header.Get("X-Influxdb-Version") + + if res.StatusCode != tt.wants.statusCode { + t.Errorf("%q. PingHandler() = %v, want %v", tt.name, res.StatusCode, tt.wants.statusCode) + } + if build != tt.wants.build { + t.Errorf("%q. PingHandler() = %v, want %v", tt.name, build, tt.wants.build) + } + if version != tt.wants.version { + t.Errorf("%q. PingHandler() = %v, want %v", tt.name, version, tt.wants.version) + } + }) + } +} diff --git a/http/legacy/ping_handler.go b/http/legacy/ping_handler.go index 979afa124b5..67fdcc237a2 100644 --- a/http/legacy/ping_handler.go +++ b/http/legacy/ping_handler.go @@ -24,7 +24,7 @@ func NewPingHandler(version string) *PingHandler { // handlePostLegacyWrite is the HTTP handler for the POST /write route. func (h *PingHandler) pingHandler(w http.ResponseWriter, r *http.Request) { - w.Header().Add("X-Influxdb-Build", "cloud2") + w.Header().Add("X-Influxdb-Build", "oss2") w.Header().Add("X-Influxdb-Version", h.InfluxDBVersion) w.WriteHeader(http.StatusNoContent) } diff --git a/http/platform_handler.go b/http/platform_handler.go index 31154505742..0e9cc80d3f4 100644 --- a/http/platform_handler.go +++ b/http/platform_handler.go @@ -40,7 +40,7 @@ func NewPlatformHandler(b *APIBackend, opts ...APIHandlerOptFn) *PlatformHandler wrappedHandler = kithttp.SkipOptions(wrappedHandler) legacyBackend := newLegacyBackend(b) - lh := newLegacyHandler(legacyBackend, legacy.HandlerConfig{}) + lh := newLegacyHandler(legacyBackend, *legacy.NewHandlerConfig()) return &PlatformHandler{ AssetHandler: assetHandler,