Skip to content

fix(providers): reduce metadata enrichment log noise#187

Merged
SantiagoDePolonia merged 1 commit intomainfrom
fix/excessive-logs
Mar 29, 2026
Merged

fix(providers): reduce metadata enrichment log noise#187
SantiagoDePolonia merged 1 commit intomainfrom
fix/excessive-logs

Conversation

@SantiagoDePolonia
Copy link
Copy Markdown
Contributor

@SantiagoDePolonia SantiagoDePolonia commented Mar 29, 2026

Summary

  • move metadata enrichment logging to cycle-level summaries instead of per-provider INFO logs
  • include metadata enrichment counts on cache/init/model-list summary logs
  • add a regression test covering the single-summary logging behavior

Test Plan

  • go test ./...

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced model registry initialization logging to include metadata enrichment statistics, showing the count of models enriched and total models processed for better visibility into the enrichment process.
  • Tests

    • Added test coverage for metadata enrichment statistics logging during model registry initialization.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

📝 Walkthrough

Walkthrough

The changes refactor metadata enrichment tracking by introducing an EnrichStats struct to capture enrichment counts, removing redundant logging from the enricher, and updating the registry to aggregate and log these statistics at initialization and refresh points instead.

Changes

Cohort / File(s) Summary
Enrichment Stats Struct
internal/modeldata/enricher.go
Added EnrichStats struct with Enriched and Total fields. Modified Enrich function to return EnrichStats instead of void, and removed structured logging call.
Stats Aggregation
internal/providers/registry.go
Introduced metadataEnrichmentStats type with slogAttrs() method. Refactored enrichProviderModelMaps to return stats, Initialize and LoadFromCache to capture and log stats, and refreshModelList to include enrichment counters in debug logging.
Stats Capture & Logging
internal/providers/init.go
Updated background goroutine to capture metadataStats from enrichModels() call and append stats attributes to slog.Info logging via dynamic attribute slice.
Enrichment Logging Test
internal/providers/registry_test.go
Added TestInitialize_LogsSingleMetadataSummaryPerCycle test that verifies metadata enrichment stats are included in initialization logs with expected counts, and validates no duplicate enrichment logging occurs.

Sequence Diagram

sequenceDiagram
    participant Init as Init Process
    participant Registry as Model Registry
    participant Enricher as Enricher
    participant Logger as Structured Logger

    Init->>Registry: Initialize()
    Registry->>Enricher: enrichProviderModelMaps()
    Enricher->>Enricher: iterate models & resolve metadata
    Enricher-->>Registry: return metadataEnrichmentStats{Enriched, Total, Providers}
    Registry->>Logger: slog.Info("model registry initialized", ..., metadata_enriched, metadata_total, metadata_providers)
    Logger-->>Registry: log entry emitted
    Registry-->>Init: initialization complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 Stats now flow where silence dwelt,
No logs repeat—once aggregated felt,
Rich metadata counts, from provider to core,
One message sings what enrichment's for! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(providers): reduce metadata enrichment log noise' directly and accurately describes the main change: consolidating verbose per-operation metadata enrichment logs into single cycle-level summaries to reduce noise.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/excessive-logs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/providers/registry_test.go`:
- Around line 671-676: This test replaces the global logger via
slog.SetDefault(slog.New(...)) and restores it in t.Cleanup, which is not safe
if the test is made parallel; update the test around the
slog.Default/Slog.SetDefault usage to add a clear inline comment documenting
that the test must not be run in parallel (do not call t.Parallel()) because it
mutates global state, and consider (optionally) guarding the global mutation
with a note referencing the cleanup that restores the original logger.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 28363309-0a57-4ed6-a450-195067c13ff0

📥 Commits

Reviewing files that changed from the base of the PR and between 3740a6c and 2baf32a.

📒 Files selected for processing (4)
  • internal/modeldata/enricher.go
  • internal/providers/init.go
  • internal/providers/registry.go
  • internal/providers/registry_test.go

Comment on lines +671 to +676
var buf bytes.Buffer
original := slog.Default()
slog.SetDefault(slog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelInfo})))
t.Cleanup(func() {
slog.SetDefault(original)
})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider test isolation for parallel safety.

The test modifies slog.Default(), which is a global state. While t.Cleanup properly restores it and this test doesn't call t.Parallel(), future maintainers might inadvertently add parallelism.

Consider adding a comment to document this constraint:

 	var buf bytes.Buffer
 	original := slog.Default()
+	// NOTE: This test modifies slog.Default() and must not run in parallel with other tests.
 	slog.SetDefault(slog.New(slog.NewJSONHandler(&buf, &slog.HandlerOptions{Level: slog.LevelInfo})))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/providers/registry_test.go` around lines 671 - 676, This test
replaces the global logger via slog.SetDefault(slog.New(...)) and restores it in
t.Cleanup, which is not safe if the test is made parallel; update the test
around the slog.Default/Slog.SetDefault usage to add a clear inline comment
documenting that the test must not be run in parallel (do not call t.Parallel())
because it mutates global state, and consider (optionally) guarding the global
mutation with a note referencing the cleanup that restores the original logger.

@SantiagoDePolonia SantiagoDePolonia merged commit ade4738 into main Mar 29, 2026
16 checks passed
@SantiagoDePolonia SantiagoDePolonia deleted the fix/excessive-logs branch April 4, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant