refactor: use nginx -s reload instead of systemd
- doc: add comment
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Package healthcheck 提供针对 Spring Boot Actuator 健康端点的采样与等待能力,
|
||||
// 供更新执行器在启动容器后确认工作负载是否就绪。
|
||||
package healthcheck
|
||||
|
||||
import (
|
||||
@@ -11,23 +13,29 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// maximumResponseBytes 限制 Actuator 响应体的最大读取字节数,防止异常大响应。
|
||||
const maximumResponseBytes = 1 << 20
|
||||
|
||||
// ErrWorkloadStopped 表示工作负载在变为健康之前已经停止。
|
||||
var ErrWorkloadStopped = errors.New("workload stopped before becoming healthy")
|
||||
|
||||
// RunningProbe 在每次健康采样前核对容器是否仍处于运行状态。
|
||||
type RunningProbe func(context.Context) (bool, error)
|
||||
|
||||
// ActuatorReport 是一次成功健康采样的非敏感摘要。
|
||||
// ActuatorReport 一次成功健康采样的非敏感摘要。
|
||||
type ActuatorReport struct {
|
||||
Status string
|
||||
// Status 表示顶层健康状态,例如 UP、DOWN。
|
||||
Status string
|
||||
// Components 表示各子组件的健康状态映射。
|
||||
Components map[string]string
|
||||
}
|
||||
|
||||
// ActuatorChecker 等待 Spring Boot Actuator 顶层状态进入 UP。
|
||||
// 它只采样健康状态,不负责重启容器。
|
||||
type ActuatorChecker struct {
|
||||
client *http.Client
|
||||
// client 执行健康检查 HTTP 请求的客户端。
|
||||
client *http.Client
|
||||
// interval 相邻两次采样之间的间隔。
|
||||
interval time.Duration
|
||||
}
|
||||
|
||||
@@ -88,6 +96,7 @@ func (c *ActuatorChecker) Wait(ctx context.Context, endpoint string, timeout tim
|
||||
}
|
||||
}
|
||||
|
||||
// validateEndpoint 校验 Actuator 端点必须是合法的 http URL 且包含主机部分。
|
||||
func validateEndpoint(endpoint string) error {
|
||||
parsed, err := url.ParseRequestURI(endpoint)
|
||||
if err != nil || parsed.Scheme != "http" || parsed.Host == "" {
|
||||
@@ -96,6 +105,9 @@ func validateEndpoint(endpoint string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// sample 执行一次完整健康采样:先核对容器仍在运行,
|
||||
// 再向 Actuator 端点发起 GET 请求并解析返回的 JSON 状态。
|
||||
// 返回的报告在状态非 UP 时仍会携带实际采样到的状态信息。
|
||||
func (c *ActuatorChecker) sample(ctx context.Context, endpoint string, running RunningProbe) (ActuatorReport, bool, error) {
|
||||
isRunning, err := running(ctx)
|
||||
if err != nil {
|
||||
@@ -140,11 +152,13 @@ func (c *ActuatorChecker) sample(ctx context.Context, endpoint string, running R
|
||||
return report, true, nil
|
||||
}
|
||||
|
||||
// actuatorPayload Actuator health 端点的顶层 JSON 结构。
|
||||
type actuatorPayload struct {
|
||||
Status string `json:"status"`
|
||||
Components map[string]actuatorComponent `json:"components"`
|
||||
}
|
||||
|
||||
// actuatorComponent 健康检查组件的 JSON 结构,这里只关心其状态。
|
||||
type actuatorComponent struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user