feat(platform): expose active connection capacity
This commit is contained in:
@@ -282,12 +282,13 @@ type QualityBucketStat struct {
|
||||
}
|
||||
|
||||
type OpsHealth struct {
|
||||
LinkHealth []LinkHealth `json:"linkHealth"`
|
||||
KafkaLag *int `json:"kafkaLag"`
|
||||
RedisOnlineKeys *int `json:"redisOnlineKeys"`
|
||||
TDengineWritable bool `json:"tdengineWritable"`
|
||||
MySQLWritable bool `json:"mysqlWritable"`
|
||||
Runtime RuntimeInfo `json:"runtime"`
|
||||
LinkHealth []LinkHealth `json:"linkHealth"`
|
||||
KafkaLag *int `json:"kafkaLag"`
|
||||
ActiveConnections *int `json:"activeConnections"`
|
||||
RedisOnlineKeys *int `json:"redisOnlineKeys"`
|
||||
TDengineWritable bool `json:"tdengineWritable"`
|
||||
MySQLWritable bool `json:"mysqlWritable"`
|
||||
Runtime RuntimeInfo `json:"runtime"`
|
||||
}
|
||||
|
||||
type RuntimeInfo struct {
|
||||
|
||||
@@ -905,7 +905,7 @@ func (s *ProductionStore) OpsHealth(ctx context.Context) (OpsHealth, error) {
|
||||
locationHealth := s.mysqlTableReadHealth(ctx, "vehicle_realtime_location", "读取实时位置表正常")
|
||||
tdengineHealth := s.tdengineRawFrameHealth(ctx)
|
||||
redisHealth, redisOnlineKeys := s.redisOnlineKeyHealth(ctx)
|
||||
capacityHealth, kafkaLag := s.capacityCheckHealth(ctx)
|
||||
capacityHealth, kafkaLag, activeConnections := s.capacityCheckHealth(ctx)
|
||||
mysqlWritable := mysqlStatus == "ok" && snapshotHealth.Status == "ok" && locationHealth.Status == "ok"
|
||||
return OpsHealth{
|
||||
LinkHealth: []LinkHealth{
|
||||
@@ -916,26 +916,28 @@ func (s *ProductionStore) OpsHealth(ctx context.Context) (OpsHealth, error) {
|
||||
capacityHealth,
|
||||
redisHealth,
|
||||
},
|
||||
KafkaLag: kafkaLag,
|
||||
RedisOnlineKeys: redisOnlineKeys,
|
||||
TDengineWritable: tdengineHealth.Status == "ok",
|
||||
MySQLWritable: mysqlWritable,
|
||||
KafkaLag: kafkaLag,
|
||||
ActiveConnections: activeConnections,
|
||||
RedisOnlineKeys: redisOnlineKeys,
|
||||
TDengineWritable: tdengineHealth.Status == "ok",
|
||||
MySQLWritable: mysqlWritable,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *ProductionStore) capacityCheckHealth(ctx context.Context) (LinkHealth, *int) {
|
||||
func (s *ProductionStore) capacityCheckHealth(ctx context.Context) (LinkHealth, *int, *int) {
|
||||
health := LinkHealth{Name: "Capacity check", Status: "warning", Detail: "平台暂未接入 capacity-check"}
|
||||
if s.capacityCheck == nil {
|
||||
return health, nil
|
||||
return health, nil, nil
|
||||
}
|
||||
result, err := s.capacityCheck.CheckCapacity(ctx)
|
||||
if err != nil {
|
||||
health.Status = "error"
|
||||
health.Detail = err.Error()
|
||||
return health, nil
|
||||
return health, nil, nil
|
||||
}
|
||||
kafkaLag := int(result.KafkaLag)
|
||||
detail := "active_connections=" + strconv.Itoa(int(result.ActiveConnections)) + ", kafka_lag=" + strconv.Itoa(kafkaLag)
|
||||
activeConnections := int(result.ActiveConnections)
|
||||
detail := "active_connections=" + strconv.Itoa(activeConnections) + ", kafka_lag=" + strconv.Itoa(kafkaLag)
|
||||
if len(result.Findings) > 0 {
|
||||
detail += ", findings=" + strings.Join(result.Findings, "; ")
|
||||
}
|
||||
@@ -945,7 +947,7 @@ func (s *ProductionStore) capacityCheckHealth(ctx context.Context) (LinkHealth,
|
||||
health.Status = "warning"
|
||||
}
|
||||
health.Detail = detail
|
||||
return health, &kafkaLag
|
||||
return health, &kafkaLag, &activeConnections
|
||||
}
|
||||
|
||||
func (s *ProductionStore) redisOnlineKeyHealth(ctx context.Context) (LinkHealth, *int) {
|
||||
|
||||
@@ -227,6 +227,9 @@ func TestOpsHealthUsesCapacityCheckProbeForKafkaLag(t *testing.T) {
|
||||
if health.KafkaLag == nil || *health.KafkaLag != 42 {
|
||||
t.Fatalf("OpsHealth should expose capacity-check kafka lag, got %+v", health.KafkaLag)
|
||||
}
|
||||
if health.ActiveConnections == nil || *health.ActiveConnections != 120000 {
|
||||
t.Fatalf("OpsHealth should expose capacity-check active connections, got %+v", health.ActiveConnections)
|
||||
}
|
||||
var capacityHealth *LinkHealth
|
||||
for index := range health.LinkHealth {
|
||||
if health.LinkHealth[index].Name == "Capacity check" {
|
||||
|
||||
Reference in New Issue
Block a user