test: add comprehensive test coverage and improve code quality
- Add new test files for auth, service, and handler modules - Improve test organization and coverage - Refactor code for better maintainability - Add captcha, settings, stats, and theme handler tests - Add auth module tests (CAS, OAuth, password, SSO, state) - Add service layer tests for auth, export, permissions, roles - All Go tests pass (exit code 0) - All frontend tests pass (325 tests in 59 files)
This commit is contained in:
@@ -14,10 +14,10 @@ import (
|
||||
type HealthStatus string
|
||||
|
||||
const (
|
||||
HealthStatusUP HealthStatus = "UP"
|
||||
HealthStatusDOWN HealthStatus = "DOWN"
|
||||
HealthStatusUP HealthStatus = "UP"
|
||||
HealthStatusDOWN HealthStatus = "DOWN"
|
||||
HealthStatusDEGRADED HealthStatus = "DEGRADED"
|
||||
HealthStatusUNKNOWN HealthStatus = "UNKNOWN"
|
||||
HealthStatusUNKNOWN HealthStatus = "UNKNOWN"
|
||||
)
|
||||
|
||||
// HealthCheck 健康检查器(增强版,支持 Redis 检查)
|
||||
|
||||
@@ -126,15 +126,15 @@ func GetGlobalMetrics() *Metrics {
|
||||
globalMetricsOnce.Do(func() {
|
||||
m := NewMetrics()
|
||||
// 将私有 registry 的指标也注册到默认 registry
|
||||
prometheus.DefaultRegisterer.Register(m.httpRequestsTotal) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.httpRequestDuration) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.dbQueriesTotal) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.dbQueryDuration) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.userRegistrations) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.userLogins) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.activeUsers) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.systemMemoryUsage) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.systemGoroutines) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.httpRequestsTotal) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.httpRequestDuration) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.dbQueriesTotal) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.dbQueryDuration) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.userRegistrations) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.userLogins) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.activeUsers) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.systemMemoryUsage) //nolint:errcheck
|
||||
prometheus.DefaultRegisterer.Register(m.systemGoroutines) //nolint:errcheck
|
||||
globalMetrics = m
|
||||
})
|
||||
return globalMetrics
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
// 这些指标是 SLO 测量的基础,用于计算错误预算燃烧率
|
||||
type SLOMetrics struct {
|
||||
// 缓存命中统计(alerts.yml 引用但原来未定义)
|
||||
CacheHitsTotal *prometheus.CounterVec
|
||||
CacheHitsTotal *prometheus.CounterVec
|
||||
CacheOperationsTotal *prometheus.CounterVec
|
||||
|
||||
// 数据库连接池状态(alerts.yml 引用但原来未定义)
|
||||
@@ -21,8 +21,8 @@ type SLOMetrics struct {
|
||||
TokenRefreshTotal *prometheus.CounterVec
|
||||
|
||||
// 账号安全事件
|
||||
AccountLockTotal prometheus.Counter
|
||||
AnomalyDetectedTotal *prometheus.CounterVec
|
||||
AccountLockTotal prometheus.Counter
|
||||
AnomalyDetectedTotal *prometheus.CounterVec
|
||||
|
||||
// 错误预算燃烧率(可选,用于自定义仪表盘)
|
||||
ErrorBudgetBurnRate *prometheus.GaugeVec
|
||||
|
||||
Reference in New Issue
Block a user