Skip to content

Commit 6aae544

Browse files
authored
fix(pingEndpoint): change build type to 'oss2', use correct version (#21723)
Signed-off-by: Jakub Bednar <[email protected]>
1 parent 156e55a commit 6aae544

File tree

5 files changed

+64
-4
lines changed

5 files changed

+64
-4
lines changed

http/legacy/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type HandlerConfig struct {
4545
}
4646

4747
func NewHandlerConfig() *HandlerConfig {
48-
return &HandlerConfig{}
48+
return &HandlerConfig{Version: influxdb.GetBuildInfo().Version}
4949
}
5050

5151
// Opts returns the CLI options for use with kit/cli.

http/legacy/influxqld_handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func TestInfluxQLdHandler_HandleQuery(t *testing.T) {
233233
InfluxqldQueryService: tt.fields.ProxyQueryService,
234234
}
235235

236-
h := NewInfluxQLHandler(b, HandlerConfig{})
236+
h := NewInfluxQLHandler(b, *NewHandlerConfig())
237237
h.Logger = zaptest.NewLogger(t)
238238

239239
if tt.context != nil {

http/legacy/ping_handle_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package legacy
2+
3+
import (
4+
"net/http"
5+
"net/http/httptest"
6+
"testing"
7+
)
8+
9+
func TestPingHandler(t *testing.T) {
10+
type wants struct {
11+
statusCode int
12+
version string
13+
build string
14+
}
15+
tests := []struct {
16+
name string
17+
w *httptest.ResponseRecorder
18+
r *http.Request
19+
wants wants
20+
}{
21+
{
22+
name: "GET request",
23+
w: httptest.NewRecorder(),
24+
r: httptest.NewRequest(http.MethodGet, "/ping", nil),
25+
wants: wants{
26+
statusCode: http.StatusNoContent,
27+
version: "2.0.0",
28+
build: "oss2",
29+
},
30+
},
31+
{
32+
name: "HEAD request",
33+
w: httptest.NewRecorder(),
34+
r: httptest.NewRequest(http.MethodHead, "/ping", nil),
35+
wants: wants{
36+
statusCode: http.StatusNoContent,
37+
version: "2.0.0",
38+
build: "oss2",
39+
},
40+
},
41+
}
42+
for _, tt := range tests {
43+
t.Run(tt.name, func(t *testing.T) {
44+
NewPingHandler("2.0.0").pingHandler(tt.w, tt.r)
45+
res := tt.w.Result()
46+
build := res.Header.Get("X-Influxdb-Build")
47+
version := res.Header.Get("X-Influxdb-Version")
48+
49+
if res.StatusCode != tt.wants.statusCode {
50+
t.Errorf("%q. PingHandler() = %v, want %v", tt.name, res.StatusCode, tt.wants.statusCode)
51+
}
52+
if build != tt.wants.build {
53+
t.Errorf("%q. PingHandler() = %v, want %v", tt.name, build, tt.wants.build)
54+
}
55+
if version != tt.wants.version {
56+
t.Errorf("%q. PingHandler() = %v, want %v", tt.name, version, tt.wants.version)
57+
}
58+
})
59+
}
60+
}

http/legacy/ping_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NewPingHandler(version string) *PingHandler {
2424

2525
// handlePostLegacyWrite is the HTTP handler for the POST /write route.
2626
func (h *PingHandler) pingHandler(w http.ResponseWriter, r *http.Request) {
27-
w.Header().Add("X-Influxdb-Build", "cloud2")
27+
w.Header().Add("X-Influxdb-Build", "oss2")
2828
w.Header().Add("X-Influxdb-Version", h.InfluxDBVersion)
2929
w.WriteHeader(http.StatusNoContent)
3030
}

http/platform_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func NewPlatformHandler(b *APIBackend, opts ...APIHandlerOptFn) *PlatformHandler
4040
wrappedHandler = kithttp.SkipOptions(wrappedHandler)
4141

4242
legacyBackend := newLegacyBackend(b)
43-
lh := newLegacyHandler(legacyBackend, legacy.HandlerConfig{})
43+
lh := newLegacyHandler(legacyBackend, *legacy.NewHandlerConfig())
4444

4545
return &PlatformHandler{
4646
AssetHandler: assetHandler,

0 commit comments

Comments
 (0)