feat(go): add platform principles and health probes
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/eventbus"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/gateway"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/health"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/identity"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/observability"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/protocol/gb32960"
|
||||
@@ -39,6 +40,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
defer closeResolver()
|
||||
health.Start(ctx, logger, health.NewServer(env("HEALTH_ADDR", ""), "vehicle-gateway", nil))
|
||||
|
||||
protocols := []gateway.TCPProtocol{
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
_ "github.com/taosdata/driver-go/v3/taosWS"
|
||||
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/health"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/history"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/observability"
|
||||
)
|
||||
@@ -34,6 +35,9 @@ func main() {
|
||||
logger.Error("tdengine ping failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
health.Start(ctx, logger, health.NewServer(env("HEALTH_ADDR", ""), "vehicle-history-writer", []health.Check{
|
||||
{Name: "tdengine", Check: db.PingContext},
|
||||
}))
|
||||
|
||||
writer := history.NewWriter(db)
|
||||
if cfg.EnsureSchema {
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"github.com/segmentio/kafka-go"
|
||||
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/health"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/observability"
|
||||
)
|
||||
|
||||
@@ -32,6 +33,14 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
defer conn.Close()
|
||||
health.Start(ctx, logger, health.NewServer(env("HEALTH_ADDR", ""), "nats-kafka-bridge", []health.Check{
|
||||
{Name: "nats", Check: func(context.Context) error {
|
||||
if conn.Status() != nats.CONNECTED {
|
||||
return fmt.Errorf("nats status is %s", conn.Status().String())
|
||||
}
|
||||
return nil
|
||||
}},
|
||||
}))
|
||||
js, err := conn.JetStream()
|
||||
if err != nil {
|
||||
logger.Error("nats jetstream init failed", "error", err)
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
_ "github.com/taosdata/driver-go/v3/taosWS"
|
||||
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/health"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/history"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/observability"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/realtime"
|
||||
@@ -46,6 +47,9 @@ func main() {
|
||||
})
|
||||
|
||||
mux := http.NewServeMux()
|
||||
healthChecks := []health.Check{
|
||||
{Name: "redis", Check: func(ctx context.Context) error { return client.Ping(ctx).Err() }},
|
||||
}
|
||||
mux.Handle("/openapi.json", realtime.NewOpenAPIHandler())
|
||||
mux.Handle("/swagger-ui/", realtime.NewSwaggerUIHandler())
|
||||
mux.Handle("/api/realtime/vehicles/", realtime.NewHandler(repository))
|
||||
@@ -62,6 +66,7 @@ func main() {
|
||||
logger.Error("stats mysql ping failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
healthChecks = append(healthChecks, health.Check{Name: "mysql", Check: db.PingContext})
|
||||
closeStats = func() { _ = db.Close() }
|
||||
bindingTable := env("VEHICLE_IDENTITY_TABLE", "vehicle_identity_binding")
|
||||
snapshotWriter := realtime.NewSnapshotWriterWithPlateResolver(db, realtime.NewBindingPlateResolver(db, bindingTable))
|
||||
@@ -108,6 +113,7 @@ func main() {
|
||||
logger.Error("history tdengine ping failed", "driver", driver, "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
healthChecks = append(healthChecks, health.Check{Name: "tdengine", Check: db.PingContext})
|
||||
closeHistory = func() { _ = db.Close() }
|
||||
database := env("TDENGINE_DATABASE", history.DefaultDatabase)
|
||||
mux.Handle("/api/history/raw-frames", history.NewRawFrameHandler(history.NewRawFrameRepository(db, database)))
|
||||
@@ -126,6 +132,9 @@ func main() {
|
||||
logger.Warn("TDENGINE_DSN is empty; history query api disabled")
|
||||
}
|
||||
defer closeHistory()
|
||||
healthHandler := health.NewHandler("vehicle-realtime-api", healthChecks)
|
||||
mux.Handle("/healthz", healthHandler)
|
||||
mux.Handle("/readyz", healthHandler)
|
||||
|
||||
server := &http.Server{
|
||||
Addr: env("HTTP_ADDR", ":20210"),
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"github.com/segmentio/kafka-go"
|
||||
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/health"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/observability"
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/stats"
|
||||
)
|
||||
@@ -34,6 +35,9 @@ func main() {
|
||||
logger.Error("mysql ping failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
health.Start(ctx, logger, health.NewServer(env("HEALTH_ADDR", ""), "vehicle-stat-writer", []health.Check{
|
||||
{Name: "mysql", Check: db.PingContext},
|
||||
}))
|
||||
|
||||
writer := stats.NewWriter(db, cfg.Location)
|
||||
if cfg.EnsureSchema {
|
||||
|
||||
Reference in New Issue
Block a user