🔧 Update Go version in go.mod and enhance build process with versioning information. Modify Makefile and Taskfile to inject build metadata (version, commit, build time) into the binary. Improve README with instructions for custom version builds and document new build info features. Add benchmarks for message parsing and processing to improve performance testing capabilities.

This commit is contained in:
windyboy
2025-11-18 14:15:58 +08:00
parent 7f44b5389d
commit 06fc9cb9e0
27 changed files with 3009 additions and 55 deletions
+13 -4
View File
@@ -1,6 +1,7 @@
package main
import (
"caatsm/internal/infra/buildinfo"
"caatsm/internal/infra/config"
"caatsm/pkg/di"
"context"
@@ -158,14 +159,18 @@ func runListen(parentCtx context.Context, cfg *config.Config) error {
ctx, stop := signal.NotifyContext(parentCtx, os.Interrupt, syscall.SIGTERM)
defer stop()
shutdownTelemetry := func(context.Context) error { return nil }
var shutdownTelemetry func(context.Context) error
if cfg.Telemetry.Enabled {
var telErr error
shutdownTelemetry, telErr = initTelemetry(ctx, cfg)
if telErr != nil {
return fmt.Errorf("failed to initialize telemetry: %w", telErr)
}
defer shutdownTelemetry(context.Background())
defer func() {
if err := shutdownTelemetry(context.Background()); err != nil {
zap.L().Error("Failed to shutdown telemetry", zap.Error(err))
}
}()
}
// Initialize dependencies using Wire
@@ -178,7 +183,11 @@ func runListen(parentCtx context.Context, cfg *config.Config) error {
if err := monitorServer.Start(ctx); err != nil {
return fmt.Errorf("failed to start monitoring server: %w", err)
}
defer monitorServer.Shutdown(context.Background())
defer func() {
if err := monitorServer.Shutdown(context.Background()); err != nil {
zap.L().Error("Failed to shutdown monitoring server", zap.Error(err))
}
}()
}
// Start consumer in a goroutine
@@ -385,7 +394,7 @@ func initTelemetry(ctx context.Context, cfg *config.Config) (func(context.Contex
resource.WithContainer(),
resource.WithAttributes(
semconv.ServiceName("caatsm"),
semconv.ServiceVersion("dev"), // TODO: Use build info
semconv.ServiceVersion(buildinfo.Version),
semconv.ServiceNamespace("airport"),
attribute.String("service.component", "receiver"),
attribute.String("deployment.environment", env),
+7 -6
View File
@@ -62,7 +62,7 @@ func main() {
duration := flag.Duration("duration", 0, "Total duration for interval/mixed modes (0 = rely on --count only)")
flag.Parse()
rand.Seed(time.Now().UnixNano())
// rand.Seed deprecated in Go 1.20+, using default source
var nc *nats.Conn
var js nats.JetStreamContext
@@ -73,7 +73,11 @@ func main() {
if err != nil {
log.Fatalf("connect nats: %v", err)
}
defer nc.Drain()
defer func() {
if err := nc.Drain(); err != nil {
log.Printf("failed to drain NATS connection: %v", err)
}
}()
if *useJetStream {
opts := []nats.JSOpt{}
@@ -191,10 +195,7 @@ func runIntervalMode(cfg SeedConfig, categories []string, statuses []string, pub
start := time.Now()
sent := 0
for {
if cfg.Count > 0 && sent >= cfg.Count {
break
}
for cfg.Count <= 0 || sent < cfg.Count {
if cfg.Duration > 0 && time.Since(start) >= cfg.Duration {
break
}