Skip to content

Commit

Permalink
Merge pull request #5459 from influxdata/tp-ping-to-status
Browse files Browse the repository at this point in the history
Remove MetaClient.Ping from `/ping` and move it to `/status`
  • Loading branch information
toddboom committed Jan 27, 2016
2 parents 1255bb9 + 66e6375 commit 308323f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions services/httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(statStatusRequest, 1)

if err := h.MetaClient.Ping(false); err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
Expand Down
15 changes: 15 additions & 0 deletions services/httpd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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))
Expand Down
1 change: 1 addition & 0 deletions services/httpd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
statQueryRequest = "queryReq" // Number of query requests served
statWriteRequest = "writeReq" // Number of write requests serverd
statPingRequest = "pingReq" // Number of ping requests served
statStatusRequest = "statusReq" // Number of status requests served
statWriteRequestBytesReceived = "writeReqBytes" // Sum of all bytes in write requests
statQueryRequestBytesTransmitted = "queryRespBytes" // Sum of all bytes returned in query reponses
statPointsWrittenOK = "pointsWrittenOK" // Number of points written OK
Expand Down

0 comments on commit 308323f

Please sign in to comment.