feat: add internal stats flush API

This commit is contained in:
zenfun
2025-12-19 23:26:33 +08:00
parent ac9f0cd0a7
commit 88289015fc
5 changed files with 244 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ type Config struct {
Auth AuthConfig
ModelRegistry ModelRegistryConfig
Quota QuotaConfig
Internal InternalConfig
}
type ServerConfig struct {
@@ -57,6 +58,10 @@ type QuotaConfig struct {
ResetIntervalSeconds int
}
type InternalConfig struct {
StatsToken string
}
func Load() (*Config, error) {
v := viper.New()
@@ -77,6 +82,7 @@ func Load() (*Config, error) {
v.SetDefault("model_registry.cache_dir", "./data/model-registry")
v.SetDefault("model_registry.timeout_seconds", 30)
v.SetDefault("quota.reset_interval_seconds", 300)
v.SetDefault("internal.stats_token", "")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()
@@ -98,6 +104,7 @@ func Load() (*Config, error) {
_ = 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")
_ = v.BindEnv("internal.stats_token", "EZ_INTERNAL_STATS_TOKEN")
if configFile := os.Getenv("EZ_CONFIG_FILE"); configFile != "" {
v.SetConfigFile(configFile)
@@ -146,6 +153,9 @@ func Load() (*Config, error) {
Quota: QuotaConfig{
ResetIntervalSeconds: v.GetInt("quota.reset_interval_seconds"),
},
Internal: InternalConfig{
StatsToken: v.GetString("internal.stats_token"),
},
}
return cfg, nil