feat(platform): expose amap runtime health

This commit is contained in:
lingniu
2026-07-04 15:30:51 +08:00
parent 5bbd110743
commit 1f069178d6
6 changed files with 64 additions and 10 deletions

View File

@@ -52,7 +52,11 @@ func NewServer(cfg config.Config) http.Handler {
}
}
api := platform.NewHandler(platform.NewServiceWithRuntime(store, platform.RuntimeInfo{
RequestTimeoutMs: int(cfg.RequestTimeout / time.Millisecond),
RequestTimeoutMs: int(cfg.RequestTimeout / time.Millisecond),
AMapWebJSConfigured: strings.TrimSpace(cfg.AMapWebJSKey) != "",
AMapSecurityProxyEnabled: strings.TrimSpace(cfg.AMapSecurityCode) != "" && strings.TrimSpace(cfg.AMapServiceHost) != "",
AMapSecurityCodeExposed: exposedAMapSecurityCode(cfg) != "",
AMapSecurityServiceHost: strings.TrimSpace(cfg.AMapServiceHost),
}))
handler := static.Handler(cfg.StaticDir, api)
handler = withAppConfig(handler, cfg)

View File

@@ -889,7 +889,13 @@ func TestHandlerQualityNotificationPlan(t *testing.T) {
}
func TestHandlerOpsHealthIncludesVehicleServiceRuntime(t *testing.T) {
handler := NewHandler(NewServiceWithRuntime(NewMockStore(), RuntimeInfo{RequestTimeoutMs: 1500}))
handler := NewHandler(NewServiceWithRuntime(NewMockStore(), RuntimeInfo{
RequestTimeoutMs: 1500,
AMapWebJSConfigured: true,
AMapSecurityProxyEnabled: true,
AMapSecurityCodeExposed: false,
AMapSecurityServiceHost: "/_AMapService",
}))
rec := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/api/ops/health", nil)
handler.ServeHTTP(rec, req)
@@ -905,6 +911,15 @@ func TestHandlerOpsHealthIncludesVehicleServiceRuntime(t *testing.T) {
if body.Data.Runtime.RequestTimeoutMs != 1500 {
t.Fatalf("ops health should include request timeout runtime, got %+v body=%s", body.Data.Runtime, rec.Body.String())
}
if !body.Data.Runtime.AMapWebJSConfigured || !body.Data.Runtime.AMapSecurityProxyEnabled {
t.Fatalf("ops health should expose AMap runtime readiness, got %+v body=%s", body.Data.Runtime, rec.Body.String())
}
if body.Data.Runtime.AMapSecurityCodeExposed {
t.Fatalf("ops health should show that AMap security code is not exposed when proxy is enabled: %+v", body.Data.Runtime)
}
if body.Data.Runtime.AMapSecurityServiceHost != "/_AMapService" {
t.Fatalf("ops health should include AMap security service host, got %+v", body.Data.Runtime)
}
}
func TestHandlerVehicleDataAPIsResolveVehicleKeyword(t *testing.T) {

View File

@@ -344,5 +344,9 @@ type OpsHealth struct {
}
type RuntimeInfo struct {
RequestTimeoutMs int `json:"requestTimeoutMs"`
RequestTimeoutMs int `json:"requestTimeoutMs"`
AMapWebJSConfigured bool `json:"amapWebJsConfigured"`
AMapSecurityProxyEnabled bool `json:"amapSecurityProxyEnabled"`
AMapSecurityCodeExposed bool `json:"amapSecurityCodeExposed"`
AMapSecurityServiceHost string `json:"amapSecurityServiceHost"`
}