Skip to content

Commit

Permalink
add a bit more data to health check
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGedd committed Oct 18, 2024
1 parent 7854f6f commit de49d41
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/pkg/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
package api

import (
"encoding/json"
"log/slog"
"net/http"
"time"

"github.com/defenseunicorns/uds-runtime/src/pkg/api/auth/local"
_ "github.com/defenseunicorns/uds-runtime/src/pkg/api/docs" //nolint:staticcheck
Expand Down Expand Up @@ -914,9 +916,22 @@ func authHandler(w http.ResponseWriter, r *http.Request) {

// @Description check the health of the application
// @Tags health
// @Success 200
// @Produce json
// @Success 200 {object} map[string]interface{}
// @Router /healthz [get]
func healthz(w http.ResponseWriter, _ *http.Request) {
slog.Debug("Health check called")

response := map[string]interface{}{
"status": "UP",
"timestamp": time.Now().UTC().Format(time.RFC3339),
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)

if err := json.NewEncoder(w).Encode(response); err != nil {
slog.Error("Failed to encode health response", "error", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
}
1 change: 1 addition & 0 deletions src/test/e2e/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ func TestClusterHealth(t *testing.T) {
// wait for the context to be done
<-ctx.Done()
require.Equal(t, http.StatusOK, rr.Code)
require.Contains(t, rr.Body.String(), "\"status\":\"UP\"")
})

t.Run("cluster connected", func(t *testing.T) {
Expand Down

0 comments on commit de49d41

Please sign in to comment.