feat(arch): add log partitioning and provider delete sync

This commit is contained in:
zenfun
2025-12-21 20:45:16 +08:00
parent f819f89ba2
commit 816ea93339
23 changed files with 582 additions and 69 deletions

View File

@@ -45,6 +45,7 @@ type LogConfig struct {
RetentionDays int
MaxRecords int
DSN string
Partitioning string
}
type ModelRegistryConfig struct {
@@ -79,6 +80,7 @@ func Load() (*Config, error) {
v.SetDefault("log.retention_days", 30)
v.SetDefault("log.max_records", 1000000)
v.SetDefault("log.dsn", "")
v.SetDefault("log.partitioning", "off")
v.SetDefault("auth.jwt_secret", "change_me_in_production")
v.SetDefault("model_registry.enabled", false)
v.SetDefault("model_registry.refresh_seconds", 1800)
@@ -104,6 +106,7 @@ func Load() (*Config, error) {
_ = v.BindEnv("log.retention_days", "EZ_LOG_RETENTION_DAYS")
_ = v.BindEnv("log.max_records", "EZ_LOG_MAX_RECORDS")
_ = v.BindEnv("log.dsn", "EZ_LOG_PG_DSN")
_ = v.BindEnv("log.partitioning", "EZ_LOG_PARTITIONING")
_ = v.BindEnv("auth.jwt_secret", "EZ_JWT_SECRET")
_ = v.BindEnv("model_registry.enabled", "EZ_MODEL_REGISTRY_ENABLED")
_ = v.BindEnv("model_registry.refresh_seconds", "EZ_MODEL_REGISTRY_REFRESH_SECONDS")
@@ -149,6 +152,7 @@ func Load() (*Config, error) {
RetentionDays: v.GetInt("log.retention_days"),
MaxRecords: v.GetInt("log.max_records"),
DSN: strings.TrimSpace(v.GetString("log.dsn")),
Partitioning: strings.TrimSpace(v.GetString("log.partitioning")),
},
Auth: AuthConfig{
JWTSecret: v.GetString("auth.jwt_secret"),

View File

@@ -4,6 +4,7 @@ import "testing"
func TestLoad_LogDSNOverride(t *testing.T) {
t.Setenv("EZ_LOG_PG_DSN", "host=log-db user=postgres dbname=logs")
t.Setenv("EZ_LOG_PARTITIONING", "monthly")
cfg, err := Load()
if err != nil {
t.Fatalf("load config: %v", err)
@@ -11,4 +12,7 @@ func TestLoad_LogDSNOverride(t *testing.T) {
if cfg.Log.DSN != "host=log-db user=postgres dbname=logs" {
t.Fatalf("expected log dsn to be set, got %q", cfg.Log.DSN)
}
if cfg.Log.Partitioning != "monthly" {
t.Fatalf("expected log partitioning to be set, got %q", cfg.Log.Partitioning)
}
}