Skip to content

Commit

Permalink
Merge pull request #202 from yunheL/health-check-api
Browse files Browse the repository at this point in the history
Support health check API
  • Loading branch information
karimra authored Aug 10, 2023
2 parents 1a12326 + ed01699 commit a462b66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ func (a *App) handleClusteringGet(w http.ResponseWriter, r *http.Request) {
w.Write(b)
}

func (a *App) handleHealthzGet(w http.ResponseWriter, r *http.Request) {
s := map[string]string{"status": "healthy",}
b, err := json.Marshal(s)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(APIErrors{Errors: []string{err.Error()}})
return
}
w.Write(b)
}

func (a *App) handleClusteringMembersGet(w http.ResponseWriter, r *http.Request) {
if a.Config.Clustering == nil {
return
Expand Down
6 changes: 5 additions & 1 deletion app/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (a *App) routes() {
a.clusterRoutes(apiV1)
a.configRoutes(apiV1)
a.targetRoutes(apiV1)

a.healthRoutes(apiV1)
}

func (a *App) clusterRoutes(r *mux.Router) {
Expand Down Expand Up @@ -59,3 +59,7 @@ func (a *App) targetRoutes(r *mux.Router) {
r.HandleFunc("/targets/{id}", a.handleTargetsPost).Methods(http.MethodPost)
r.HandleFunc("/targets/{id}", a.handleTargetsDelete).Methods(http.MethodDelete)
}

func (a *App) healthRoutes(r *mux.Router) {
r.HandleFunc("/healthz", a.handleHealthzGet).Methods(http.MethodGet)
}

0 comments on commit a462b66

Please sign in to comment.