Remove MetaClient.Ping from `/ping` and move it to `/status`
parent
697f48b4e6
commit
06e91dfca1
|
@ -117,6 +117,14 @@ func NewHandler(requireAuthentication, loggingEnabled, writeTrace bool, statMap
|
|||
"ping-head",
|
||||
"HEAD", "/ping", true, true, h.servePing,
|
||||
},
|
||||
route{ // Ping w/ status
|
||||
"status",
|
||||
"GET", "/status", true, true, h.serveStatus,
|
||||
},
|
||||
route{ // Ping w/ status
|
||||
"status-head",
|
||||
"HEAD", "/status", true, true, h.serveStatus,
|
||||
},
|
||||
route{ // Tell data node to run CQs that should be run
|
||||
"process_continuous_queries",
|
||||
"POST", "/data/process_continuous_queries", false, false, h.serveProcessContinuousQueries,
|
||||
|
@ -567,6 +575,12 @@ func (h *Handler) serveOptions(w http.ResponseWriter, r *http.Request) {
|
|||
// servePing returns a simple response to let the client know the server is running.
|
||||
func (h *Handler) servePing(w http.ResponseWriter, r *http.Request) {
|
||||
h.statMap.Add(statPingRequest, 1)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// serveStatus returns a simple response to let the client know the whole cluster is running.
|
||||
func (h *Handler) serveStatus(w http.ResponseWriter, r *http.Request) {
|
||||
h.statMap.Add(statPingRequest, 1)
|
||||
|
||||
if err := h.MetaClient.Ping(false); err != nil {
|
||||
w.WriteHeader(http.StatusServiceUnavailable)
|
||||
|
|
|
@ -305,6 +305,7 @@ func TestHandler_Query_ErrResult(t *testing.T) {
|
|||
}
|
||||
|
||||
// Ensure the handler handles ping requests correctly.
|
||||
// TODO: This should be expanded to verify the MetaClient check in servePing is working correctly
|
||||
func TestHandler_Ping(t *testing.T) {
|
||||
h := NewHandler(false)
|
||||
w := httptest.NewRecorder()
|
||||
|
@ -318,6 +319,20 @@ func TestHandler_Ping(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// Ensure the handler handles status requests correctly.
|
||||
func TestHandler_Status(t *testing.T) {
|
||||
h := NewHandler(false)
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, MustNewRequest("GET", "/status", nil))
|
||||
if w.Code != http.StatusNoContent {
|
||||
t.Fatalf("unexpected status: %d", w.Code)
|
||||
}
|
||||
h.ServeHTTP(w, MustNewRequest("HEAD", "/status", nil))
|
||||
if w.Code != http.StatusNoContent {
|
||||
t.Fatalf("unexpected status: %d", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure write endpoint can handle bad requests
|
||||
func TestHandler_HandleBadRequestBody(t *testing.T) {
|
||||
b := bytes.NewReader(make([]byte, 10))
|
||||
|
|
Loading…
Reference in New Issue