Skip to content

Commit 9692743

Browse files
author
张启航
committed
fix: add health check
Signed-off-by: 张启航 <12344192+zhangsetsail@user.noreply.gitee.com>
1 parent 68d33d5 commit 9692743

6 files changed

Lines changed: 567 additions & 0 deletions

File tree

api/api/api_interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
// ClusterInterface -
2626
type ClusterInterface interface {
27+
GetPlatformHealth(w http.ResponseWriter, r *http.Request)
2728
GetClusterInfo(w http.ResponseWriter, r *http.Request)
2829
MavenSettingList(w http.ResponseWriter, r *http.Request)
2930
MavenSettingAdd(w http.ResponseWriter, r *http.Request)

api/api_routers/version2/v2Routers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ func ChangePluginStatus(w http.ResponseWriter, r *http.Request) {
375375
func (v2 *V2) clusterRouter() chi.Router {
376376
r := chi.NewRouter()
377377
r.Get("/", controller.GetManager().GetClusterInfo)
378+
r.Get("/health", controller.GetManager().GetPlatformHealth)
378379
r.Get("/builder/mavensetting", controller.GetManager().MavenSettingList)
379380
r.Post("/builder/mavensetting", controller.GetManager().MavenSettingAdd)
380381
r.Get("/builder/mavensetting/{name}", controller.GetManager().MavenSettingDetail)

api/controller/cluster.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ import (
4949
type ClusterController struct {
5050
}
5151

52+
// GetPlatformHealth 获取平台健康状态
53+
func (c *ClusterController) GetPlatformHealth(w http.ResponseWriter, r *http.Request) {
54+
healthData, err := handler.GetPlatformHealthHandler().GetPlatformHealth(r.Context())
55+
if err != nil {
56+
logrus.Errorf("Failed to get platform health: %v", err)
57+
httputil.ReturnError(r, w, 500, err.Error())
58+
return
59+
}
60+
61+
httputil.ReturnSuccess(r, w, healthData)
62+
}
63+
5264
// GetClusterInfo -
5365
func (c *ClusterController) GetClusterInfo(w http.ResponseWriter, r *http.Request) {
5466
nodes, err := handler.GetClusterHandler().GetClusterInfo(r.Context())

api/handler/handler.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func InitAPIHandle() error {
5353
defApplicationHandler = NewApplicationHandler()
5454
defRegistryAuthSecretHandler = CreateRegistryAuthSecretManager()
5555
defNodesHandler = NewNodesHandler()
56+
defPlatformHealthHandler = NewPlatformHealthHandler()
5657

5758
// 初始化 TarImageHandle
5859
// 镜像的加载和推送在 builder 服务中异步完成
@@ -224,3 +225,10 @@ var defRegistryAuthSecretHandler RegistryAuthSecretHandler
224225
func GetRegistryAuthSecretHandler() RegistryAuthSecretHandler {
225226
return defRegistryAuthSecretHandler
226227
}
228+
229+
var defPlatformHealthHandler PlatformHealthHandler
230+
231+
// GetPlatformHealthHandler returns the default platform health handler.
232+
func GetPlatformHealthHandler() PlatformHealthHandler {
233+
return defPlatformHealthHandler
234+
}

0 commit comments

Comments
 (0)