Add health check at /status
There are times where it would be good to monitor that osbuild-composer is up and running. Add a very simple status check that always returns 200/OK. This can be expanded later to verify that other parts of osbuild-composer are working properly. Signed-off-by: Major Hayden <major@redhat.com>
This commit is contained in:
parent
e503b0a4d4
commit
0921643fa3
3 changed files with 23 additions and 0 deletions
|
|
@ -49,6 +49,10 @@ func NewServer(logger *log.Logger, jobs jobqueue.JobQueue, artifactsDir string)
|
|||
s.router.MethodNotAllowed = http.HandlerFunc(methodNotAllowedHandler)
|
||||
s.router.NotFound = http.HandlerFunc(notFoundHandler)
|
||||
|
||||
// Add a basic status handler for checking if osbuild-composer is alive.
|
||||
s.router.GET("/status", s.statusHandler)
|
||||
|
||||
// Add handlers for managing jobs.
|
||||
s.router.POST("/job-queue/v1/jobs", s.addJobHandler)
|
||||
s.router.PATCH("/job-queue/v1/jobs/:job_id", s.updateJobHandler)
|
||||
s.router.POST("/job-queue/v1/jobs/:job_id/artifacts/:name", s.addJobImageHandler)
|
||||
|
|
@ -134,6 +138,15 @@ func notFoundHandler(writer http.ResponseWriter, request *http.Request) {
|
|||
jsonErrorf(writer, http.StatusNotFound, "not found")
|
||||
}
|
||||
|
||||
func (s *Server) statusHandler(writer http.ResponseWriter, request *http.Request, _ httprouter.Params) {
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
|
||||
// Send back a status message.
|
||||
_ = json.NewEncoder(writer).Encode(&statusResponse{
|
||||
Status: "OK",
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) addJobHandler(writer http.ResponseWriter, request *http.Request, _ httprouter.Params) {
|
||||
contentType := request.Header["Content-Type"]
|
||||
if len(contentType) != 1 || contentType[0] != "application/json" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue