@@ -50,6 +50,20 @@ type ModelRegistry struct {
5050 categoryCache map [core.ModelCategory ][]ModelWithProvider
5151}
5252
53+ type metadataEnrichmentStats struct {
54+ Enriched int
55+ Total int
56+ Providers int
57+ }
58+
59+ func (s metadataEnrichmentStats ) slogAttrs () []any {
60+ return []any {
61+ "metadata_enriched" , s .Enriched ,
62+ "metadata_total" , s .Total ,
63+ "metadata_providers" , s .Providers ,
64+ }
65+ }
66+
5367// NewModelRegistry creates a new model registry
5468func NewModelRegistry () * ModelRegistry {
5569 return & ModelRegistry {
@@ -190,8 +204,9 @@ func (r *ModelRegistry) Initialize(ctx context.Context) error {
190204 r .mu .RLock ()
191205 list := r .modelList
192206 r .mu .RUnlock ()
207+ metadataStats := metadataEnrichmentStats {}
193208 if list != nil {
194- enrichProviderModelMaps (list , providerTypes , newModelsByProvider , nil )
209+ metadataStats = enrichProviderModelMaps (list , providerTypes , newModelsByProvider , nil )
195210 }
196211
197212 // Atomically swap the models map and invalidate sorted caches
@@ -206,11 +221,13 @@ func (r *ModelRegistry) Initialize(ctx context.Context) error {
206221 r .initialized = true
207222 r .initMu .Unlock ()
208223
209- slog . Info ( "model registry initialized" ,
224+ attrs := [] any {
210225 "total_models" , totalModels ,
211226 "providers" , len (providers ),
212227 "failed_providers" , failedProviders ,
213- )
228+ }
229+ attrs = append (attrs , metadataStats .slogAttrs ()... )
230+ slog .Info ("model registry initialized" , attrs ... )
214231
215232 return nil
216233}
@@ -297,8 +314,9 @@ func (r *ModelRegistry) LoadFromCache(ctx context.Context) (int, error) {
297314 }
298315
299316 // Enrich cached models with model list metadata
317+ metadataStats := metadataEnrichmentStats {}
300318 if list != nil {
301- enrichProviderModelMaps (list , r .snapshotProviderTypes (), newModelsByProvider , nil )
319+ metadataStats = enrichProviderModelMaps (list , r .snapshotProviderTypes (), newModelsByProvider , nil )
302320 }
303321
304322 r .mu .Lock ()
@@ -311,10 +329,12 @@ func (r *ModelRegistry) LoadFromCache(ctx context.Context) (int, error) {
311329 }
312330 r .mu .Unlock ()
313331
314- slog . Info ( "loaded models from cache" ,
332+ attrs := [] any {
315333 "models" , len (newModels ),
316334 "cache_updated_at" , modelCache .UpdatedAt ,
317- )
335+ }
336+ attrs = append (attrs , metadataStats .slogAttrs ()... )
337+ slog .Info ("loaded models from cache" , attrs ... )
318338
319339 return len (newModels ), nil
320340}
@@ -902,24 +922,29 @@ func (r *ModelRegistry) SetModelList(list *modeldata.ModelList, raw json.RawMess
902922// entries instead of mutating them in place so concurrent readers can safely keep
903923// using older snapshots after unlocking.
904924func (r * ModelRegistry ) EnrichModels () {
925+ _ = r .enrichModels ()
926+ }
927+
928+ func (r * ModelRegistry ) enrichModels () metadataEnrichmentStats {
905929 r .mu .Lock ()
906930 defer r .mu .Unlock ()
907931
908932 if r .modelList == nil || len (r .models ) == 0 {
909- return
933+ return metadataEnrichmentStats {}
910934 }
911935
912936 providerTypes := make (map [core.Provider ]string , len (r .providerTypes ))
913937 maps .Copy (providerTypes , r .providerTypes )
914938
915939 replacements := make (map [* ModelInfo ]* ModelInfo , len (r .models ))
916- enrichProviderModelMaps (r .modelList , providerTypes , r .modelsByProvider , replacements )
940+ stats := enrichProviderModelMaps (r .modelList , providerTypes , r .modelsByProvider , replacements )
917941 for modelID , info := range r .models {
918942 if replacement , ok := replacements [info ]; ok {
919943 r .models [modelID ] = replacement
920944 }
921945 }
922946 r .invalidateSortedCaches ()
947+ return stats
923948}
924949
925950// ResolveMetadata resolves metadata for a model directly via the stored model list,
@@ -976,21 +1001,26 @@ func enrichProviderModelMaps(
9761001 providerTypes map [core.Provider ]string ,
9771002 modelsByProvider map [string ]map [string ]* ModelInfo ,
9781003 replacements map [* ModelInfo ]* ModelInfo ,
979- ) {
1004+ ) metadataEnrichmentStats {
9801005 if list == nil {
981- return
1006+ return metadataEnrichmentStats {}
9821007 }
1008+ stats := metadataEnrichmentStats {}
9831009 for _ , providerModels := range modelsByProvider {
9841010 if len (providerModels ) == 0 {
9851011 continue
9861012 }
1013+ stats .Providers ++
9871014 accessor := & registryAccessor {
9881015 models : providerModels ,
9891016 providerTypes : providerTypes ,
9901017 replacements : replacements ,
9911018 }
992- modeldata .Enrich (accessor , list )
1019+ enrichStats := modeldata .Enrich (accessor , list )
1020+ stats .Enriched += enrichStats .Enriched
1021+ stats .Total += enrichStats .Total
9931022 }
1023+ return stats
9941024}
9951025
9961026// registryAccessor implements modeldata.ModelInfoAccessor.
@@ -1104,14 +1134,16 @@ func (r *ModelRegistry) refreshModelList(ctx context.Context, url string) {
11041134 }
11051135
11061136 r .SetModelList (list , raw )
1107- r . EnrichModels ()
1137+ metadataStats := r . enrichModels ()
11081138
11091139 if err := r .SaveToCache (fetchCtx ); err != nil {
11101140 if ! isBenignBackgroundRefreshError (ctx , err ) {
11111141 slog .Warn ("failed to save cache after model list refresh" , "error" , err )
11121142 }
11131143 }
1114- slog .Debug ("model list refreshed" , "models" , len (list .Models ))
1144+ attrs := []any {"models" , len (list .Models )}
1145+ attrs = append (attrs , metadataStats .slogAttrs ()... )
1146+ slog .Debug ("model list refreshed" , attrs ... )
11151147}
11161148
11171149func isBenignBackgroundRefreshError (parent context.Context , err error ) bool {
0 commit comments