Skip to content

Commit

Permalink
Rework healthcheck endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffail committed Jun 23, 2022
1 parent cb8394b commit c536995
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions internal/stream/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,21 @@ func New(conf Config, mgr bundle.NewManagement, opts ...func(*Type)) (*Type, err
}

healthCheck := func(w http.ResponseWriter, r *http.Request) {
connected := true
if !t.inputLayer.Connected() {
connected = false
w.WriteHeader(http.StatusServiceUnavailable)
inputConnected := t.inputLayer.Connected()
outputConnected := t.outputLayer.Connected()

if inputConnected && outputConnected {
_, _ = w.Write([]byte("OK"))
return
}

w.WriteHeader(http.StatusServiceUnavailable)
if !inputConnected {
_, _ = w.Write([]byte("input not connected\n"))
}
if !t.outputLayer.Connected() && connected {
connected = false
w.WriteHeader(http.StatusServiceUnavailable)
if !outputConnected {
_, _ = w.Write([]byte("output not connected\n"))
}
if connected {
_, _ = w.Write([]byte("OK"))
}
}
t.manager.RegisterEndpoint(
"/ready",
Expand Down
2 changes: 1 addition & 1 deletion internal/stream/type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,5 @@ func TestHealthCheck(t *testing.T) {

assert.NoError(t, strm.StopUnordered(time.Minute))

validateHealthCheckResponse(t, mockAPIReg.server.URL, "input not connected\n")
validateHealthCheckResponse(t, mockAPIReg.server.URL, "input not connected\noutput not connected\n")
}

0 comments on commit c536995

Please sign in to comment.