Skip to content

Commit

Permalink
fix: add payload to readiness endpoint (#4601)
Browse files Browse the repository at this point in the history
Co-authored-by: Acha Bill <[email protected]>
  • Loading branch information
notanatol and acha-bill authored Sep 23, 2024
1 parent e7f2734 commit 80a927a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
21 changes: 18 additions & 3 deletions pkg/api/readiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@

package api

import "net/http"
import (
"net/http"

"github.com/ethersphere/bee/v2"
"github.com/ethersphere/bee/v2/pkg/jsonhttp"
)

type ReadyStatusResponse healthStatusResponse

func (s *Service) readinessHandler(w http.ResponseWriter, _ *http.Request) {
if s.probe.Ready() == ProbeStatusOK {
w.WriteHeader(http.StatusOK)
jsonhttp.OK(w, ReadyStatusResponse{
Status: "ready",
Version: bee.Version,
APIVersion: Version,
})
} else {
w.WriteHeader(http.StatusBadRequest)
jsonhttp.BadRequest(w, ReadyStatusResponse{
Status: "notReady",
Version: bee.Version,
APIVersion: Version,
})
}
}
14 changes: 12 additions & 2 deletions pkg/api/readiness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,20 @@ func TestReadiness(t *testing.T) {

// When we set readiness probe to OK it should indicate that API is ready
probe.SetReady(api.ProbeStatusOK)
jsonhttptest.Request(t, testServer, http.MethodGet, "/readiness", http.StatusOK)
jsonhttptest.Request(t, testServer, http.MethodGet, "/readiness", http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(api.ReadyStatusResponse{
Status: "ready",
Version: "-dev",
APIVersion: "0.0.0",
}))

// When we set readiness probe to NOK it should indicate that API is not ready
probe.SetReady(api.ProbeStatusNOK)
jsonhttptest.Request(t, testServer, http.MethodGet, "/readiness", http.StatusBadRequest)
jsonhttptest.Request(t, testServer, http.MethodGet, "/readiness", http.StatusBadRequest,
jsonhttptest.WithExpectedJSONResponse(api.ReadyStatusResponse{
Status: "notReady",
Version: "-dev",
APIVersion: "0.0.0",
}))
})
}

0 comments on commit 80a927a

Please sign in to comment.