You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
3.7 KiB
53 lines
3.7 KiB
package comm
|
|
|
|
// 第三方服务巡检(svc_health)的共享数据结构。
|
|
//
|
|
// 巡检器(modules/console/inspect.go)定时把 svc_config × 区域覆盖 的每份「有效配置」跑一遍
|
|
// 配置校验 + 可用性探测,结果覆盖写本表;admin 后台的「服务巡检」页与仪表盘顶部告警条读它。
|
|
// 表存 console 主库(postgres),与 svc_config 同库。
|
|
//
|
|
// 结构放 comm 而非 modules/console,是沿用 svcpool.go 的约定:业务服务日后若要读巡检结论
|
|
// (如选路时跳过已知不可用的服务)无需反向依赖 console 模块。
|
|
|
|
// 巡检结论状态。前端按此着色,仪表盘告警条只取 error/warn。
|
|
const (
|
|
HealthOK = "ok" // 配置完整且探测通过
|
|
HealthWarn = "warn" // 服务可能可用但有隐患:配置有瑕疵,或无法探测(未覆盖的服务商)
|
|
HealthError = "error" // 明确不可用:必填配置缺失、解密失败、探测失败
|
|
HealthSkip = "skip" // 服务已停用(enable=false),不参与巡检与告警
|
|
)
|
|
|
|
// 探测方式,标明这条结论的证据强度——避免把「没探到」当成「是好的」。
|
|
const (
|
|
ProbeNone = "none" // 未探测:没有可用的探针,也没有可探测的地址
|
|
ProbeReachable = "reachable" // 仅连通性:地址能建连,不代表凭据有效
|
|
ProbeCredential = "credential" // 真实调用:带凭据请求服务商接口并被接受,证据最强
|
|
)
|
|
|
|
// SvcHealth 一份「有效配置」的巡检结果快照(表 TableSvcHealth)。
|
|
// 主键语义 (app_name, svc_id, region) 唯一:region=0 表示服务的默认配置,
|
|
// region>0 表示该服务在某区域的覆盖配置(区域覆盖行的凭据可能与默认不同,故分别探测)。
|
|
type SvcHealth struct {
|
|
RowId uint64 `gorm:"primaryKey;autoIncrement;column:row_id" json:"row_id"`
|
|
AppName string `gorm:"column:app_name;size:64;uniqueIndex:uidx_svc_health,priority:1" json:"app_name"` // ''=全局默认
|
|
SvcId string `gorm:"column:svc_id;size:64;uniqueIndex:uidx_svc_health,priority:2" json:"svc_id"`
|
|
Region int32 `gorm:"column:region;uniqueIndex:uidx_svc_health,priority:3" json:"region"` // 0=默认配置,>0=区域覆盖
|
|
|
|
// 冗余自 svc_config,供前端直接展示与筛选,免去二次查询。
|
|
Name string `gorm:"column:name;size:64" json:"name"`
|
|
Provider string `gorm:"column:provider;size:64" json:"provider"`
|
|
Categories string `gorm:"column:categories;size:64" json:"categories"`
|
|
Enable bool `gorm:"column:enable" json:"enable"`
|
|
|
|
Status string `gorm:"column:status;size:16" json:"status"` // HealthOK/Warn/Error/Skip
|
|
// ConfigIssues 静态配置校验发现的问题(必填字段空、密文解密失败等),空数组表示配置无问题。
|
|
ConfigIssues []string `gorm:"column:config_issues;type:jsonb;serializer:json" json:"config_issues"`
|
|
ProbeKind string `gorm:"column:probe_kind;size:16" json:"probe_kind"` // ProbeNone/Reachable/Credential
|
|
ProbeOk bool `gorm:"column:probe_ok" json:"probe_ok"`
|
|
ProbeMsg string `gorm:"column:probe_msg" json:"probe_msg"` // 探测结论描述(失败时含服务商返回的原因)
|
|
LatencyMs int64 `gorm:"column:latency_ms" json:"latency_ms"` // 探测耗时,仅 ProbeKind!=none 时有意义
|
|
FailStreak int32 `gorm:"column:fail_streak" json:"fail_streak"` // 连续判定为 error 的轮次,用于区分抖动与持续故障
|
|
LastOkAt int64 `gorm:"column:last_ok_at" json:"last_ok_at"` // 最近一次 status=ok 的毫秒时间戳,0=从未成功
|
|
CheckedAt int64 `gorm:"column:checked_at" json:"checked_at"` // 本次巡检时间(毫秒)
|
|
DurationMs int64 `gorm:"column:duration_ms" json:"duration_ms"` // 本条巡检总耗时(校验+探测)
|
|
}
|
|
|