health

package
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package health 检查后端的就绪状态与身份。

Index

Constants

View Source
const (
	// SecretEnvironment 是只经子进程环境注入的受监督密钥键。
	SecretEnvironment = "AUTO_MAS_SUPERVISION_SECRET"
	// ChallengeHeader、ProofHeader 和 TimestampHeader 定义 C21 的 HTTP 鉴权头。
	ChallengeHeader = "X-Auto-MAS-Challenge"
	ProofHeader     = "X-Auto-MAS-Proof"
	TimestampHeader = "X-Auto-MAS-Timestamp"
)
View Source
const (
	// DefaultPort 是受监督端口的缺省值,也是 managed 模式的缺省(增补 1 C12)。
	// Expectation.Port 为零时回退到它,使既有调用方行为不变。
	DefaultPort = 36163
	// MinPort 与 MaxPort 是受监督端口的合法范围(增补 1 C12)。
	MinPort = 1024
	MaxPort = 65535
	// HealthURL 是缺省端口下健康端点的地址;其他端口用 HealthURLForPort 派生。
	// 它与 HealthURLForPort(DefaultPort) 的相等由单测锁定。
	HealthURL = "http://127.0.0.1:36163" + healthPath
)

Variables

This section is empty.

Functions

func BaseURL

func BaseURL(port int) string

BaseURL 返回受监督后端的根地址(无结尾斜杠),是 baseUrl 与两个接口地址的唯一来源。

func CloseProof added in v0.1.21

func CloseProof(secret, challenge, timestamp string, port int) string

CloseProof 使用独立域绑定关闭端点、端口、时间与挑战,不传输密钥。

func HealthProof added in v0.1.21

func HealthProof(secret, challenge string, body []byte) string

HealthProof 绑定本次挑战与原始健康正文,避免 JSON 序列化差异。

func HealthURLForPort

func HealthURLForPort(port int) string

HealthURLForPort 返回指定端口下健康端点的地址。

func NewChallenge added in v0.1.21

func NewChallenge() (string, error)

NewChallenge 为单次请求生成随机挑战,防止复用健康证明。

func NewSupervisionSecret added in v0.1.21

func NewSupervisionSecret() (string, error)

NewSupervisionSecret 为一次启动生成独立密钥。

func ValidPort

func ValidPort(port int) bool

ValidPort 报告端口是否落在增补 1 C12 的合法范围内。

func ValidSupervisionSecret added in v0.1.21

func ValidSupervisionSecret(secret string) bool

ValidSupervisionSecret 校验密钥的受控编码,不把密钥带入错误信息。

func VerifyHealthProof added in v0.1.21

func VerifyHealthProof(secret, challenge string, body []byte, received string) bool

VerifyHealthProof 以常量时间比较证明,并拒绝非契约编码。

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker 轮询后端健康端点并执行协议、身份和 Job 探针校验。

func NewChecker

func NewChecker(config Config) *Checker

NewChecker 创建一个健康检查器;空配置项使用架构默认值。

func (*Checker) Check

func (c *Checker) Check(ctx context.Context, expected Expectation, probe Probe) error

Check 轮询后端直至连续满足健康条件或返回稳定失败分类。

type Clock

type Clock interface {
	Now() time.Time
	NewTimer(time.Duration) Timer
}

Clock 为健康检查提供当前时间和计时器。

type Config

type Config struct {
	Transport            Transport
	Clock                Clock
	TotalTimeout         time.Duration
	PollInterval         time.Duration
	RequestTimeout       time.Duration
	ConsecutiveSuccesses int
}

Config 配置健康检查的传输、时钟和预算。

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error 表示健康检查失败及其稳定协议分类。

func (*Error) Code

func (e *Error) Code() protocol.Code

Code 返回稳定错误码。

func (*Error) Details

func (e *Error) Details() map[string]any

Details 返回诊断细节的防御性副本。

func (*Error) Error

func (e *Error) Error() string

Error 返回面向诊断日志的稳定错误文本。

func (*Error) Message

func (e *Error) Message() string

Message 返回不含错误码的诊断消息。

func (*Error) Stage

func (e *Error) Stage() protocol.Stage

Stage 返回固定的健康检查阶段。

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap 保留取消、传输或探针的原始错误。

type Expectation

type Expectation struct {
	// LegacyReady 允许旧后端在原有检查通过后就绪,并记录一次兼容提示;nil 禁止降级。
	LegacyReady func(context.Context) error
	// Secret 只用于本次启动的健康证明,不进入诊断。
	Secret   string
	Mode     Mode
	Protocol int
	Version  string
	Commit   string
	// Port 是受监督后端的监听端口(增补 1 C12);健康端点地址由它派生,
	// 零值回退 DefaultPort,非零但越界失败关闭。
	Port int
}

Expectation 描述本次健康检查的受管身份期望。

type Mode

type Mode string

Mode 是健康检查的身份校验模式。

const (
	// ModeManaged 要求 version、commit 与 Runtime 期望值完全相等。
	ModeManaged Mode = "managed"
	// ModeDevelopment 只校验协议版本,不比较工作区身份。
	ModeDevelopment Mode = "development"
)

type Probe

type Probe interface {
	Exited() <-chan struct{}
	// Healthy 必须尊重 ctx,并在返回前释放其临时快照资源。
	Healthy(context.Context) (bool, error)
}

Probe 验证受管 Job 中的 uv/Python 身份和存活状态。

type Timer

type Timer interface {
	C() <-chan time.Time
	Stop() bool
}

Timer 是健康检查使用的可注入计时器。

type Transport

type Transport interface {
	// RoundTrip 必须尊重请求 context;返回的 Body 必须允许 Close 中断正在进行的 Read。
	RoundTrip(*http.Request) (*http.Response, error)
}

Transport 是可注入的 HTTP 请求执行器。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL