feat(stats): add usage stats and quota reset

This commit is contained in:
zenfun
2025-12-19 21:50:28 +08:00
parent 524f8c5a4e
commit ac9f0cd0a7
9 changed files with 713 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ type Config struct {
Log LogConfig
Auth AuthConfig
ModelRegistry ModelRegistryConfig
Quota QuotaConfig
}
type ServerConfig struct {
@@ -52,6 +53,10 @@ type ModelRegistryConfig struct {
TimeoutSeconds int
}
type QuotaConfig struct {
ResetIntervalSeconds int
}
func Load() (*Config, error) {
v := viper.New()
@@ -71,6 +76,7 @@ func Load() (*Config, error) {
v.SetDefault("model_registry.models_dev_ref", "dev")
v.SetDefault("model_registry.cache_dir", "./data/model-registry")
v.SetDefault("model_registry.timeout_seconds", 30)
v.SetDefault("quota.reset_interval_seconds", 300)
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()
@@ -91,6 +97,7 @@ func Load() (*Config, error) {
_ = v.BindEnv("model_registry.models_dev_ref", "EZ_MODEL_REGISTRY_MODELS_DEV_REF")
_ = v.BindEnv("model_registry.cache_dir", "EZ_MODEL_REGISTRY_CACHE_DIR")
_ = v.BindEnv("model_registry.timeout_seconds", "EZ_MODEL_REGISTRY_TIMEOUT_SECONDS")
_ = v.BindEnv("quota.reset_interval_seconds", "EZ_QUOTA_RESET_INTERVAL_SECONDS")
if configFile := os.Getenv("EZ_CONFIG_FILE"); configFile != "" {
v.SetConfigFile(configFile)
@@ -136,6 +143,9 @@ func Load() (*Config, error) {
CacheDir: v.GetString("model_registry.cache_dir"),
TimeoutSeconds: v.GetInt("model_registry.timeout_seconds"),
},
Quota: QuotaConfig{
ResetIntervalSeconds: v.GetInt("quota.reset_interval_seconds"),
},
}
return cfg, nil