Optimized CCMS healthcheck

This commit is contained in:
Aditya Ujeniya
2026-02-04 10:24:45 +01:00
parent 42ce598865
commit 39b8356683
5 changed files with 52 additions and 290 deletions

View File

@@ -135,45 +135,3 @@ func debugMetrics(rw http.ResponseWriter, r *http.Request) {
return
}
}
// handleHealthCheck godoc
// @summary HealthCheck endpoint
// @tags healthcheck
// @description This endpoint allows the users to check if a node is healthy
// @produce json
// @param selector query string false "Selector"
// @success 200 {string} string "Debug dump"
// @failure 400 {object} api.ErrorResponse "Bad Request"
// @failure 401 {object} api.ErrorResponse "Unauthorized"
// @failure 403 {object} api.ErrorResponse "Forbidden"
// @failure 500 {object} api.ErrorResponse "Internal Server Error"
// @security ApiKeyAuth
// @router /healthcheck/ [get]
func metricsHealth(rw http.ResponseWriter, r *http.Request) {
rawCluster := r.URL.Query().Get("cluster")
rawSubCluster := r.URL.Query().Get("subcluster")
rawNode := r.URL.Query().Get("node")
if rawCluster == "" || rawNode == "" {
handleError(errors.New("'cluster' and 'node' are required query parameter"), http.StatusBadRequest, rw)
return
}
rw.Header().Add("Content-Type", "application/json")
selector := []string{rawCluster, rawNode}
ms := metricstore.GetMemoryStore()
response, err := ms.HealthCheck(selector, rawSubCluster)
if err != nil {
handleError(err, http.StatusBadRequest, rw)
return
}
jsonData, err := json.Marshal(response)
if err != nil {
cclog.Errorf("Error marshaling HealthCheckResponse JSON: %s", err)
}
rw.Write(jsonData)
}