Skip to content

Migrating vulnerabilities pkgs to slog. - #40106

Merged
getvictor merged 2 commits into
mainfrom
victor/40054-slog-vulns
Feb 20, 2026
Merged

Migrating vulnerabilities pkgs to slog.#40106
getvictor merged 2 commits into
mainfrom
victor/40054-slog-vulns

Conversation

@getvictor

@getvictor getvictor commented Feb 19, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #40054

Checklist for submitter

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    • Included in previous PR

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • Refactor
    • Migrated logging infrastructure from external framework to standard library structured logging, enabling improved context-aware operations and error tracking across vulnerability detection and synchronization workflows.

@getvictor

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Feb 19, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai

coderabbitai Bot commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request implements a systematic migration of the vulnerability scanning codebase from go-kit logging to Go's standard library slog. The changes include replacing all kitlog.Logger parameters with *slog.Logger, adding context.Context parameters to enable context-aware logging, and updating all logging calls from level-based methods (e.g., level.Error, level.Debug) to context-aware slog methods (e.g., ErrorContext, DebugContext). The migration spans the NVD, MSRC, GOVAL Dictionary, custom CVE, and CPE vulnerability analysis modules, along with their synchronization and utility functions. Function signatures are updated consistently to thread context and the new logger type through the call chain, while control flow and error handling logic remain unchanged.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 26.42% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title "Migrating vulnerabilities pkgs to slog" clearly and concisely summarizes the primary change: replacing go-kit logging with Go's standard slog library across vulnerabilities packages.
Description check ✅ Passed The PR description includes the required template with a related issue reference (#40054) and contains substantive content showing the submitter engaged with the checklist format.
Linked Issues check ✅ Passed The PR successfully addresses the objectives from #40054 by migrating vulnerabilities packages from go-kit logging to slog, implementing context propagation, and updating function signatures across multiple files.
Out of Scope Changes check ✅ Passed All code changes are directly related to the slog migration objective: replacing go-kit/log with slog, adding context parameters, and updating logging calls throughout the vulnerabilities packages.

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

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch victor/40054-slog-vulns

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

@coderabbitai coderabbitai Bot left a comment

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 comments (3)
server/vulnerabilities/nvd/sync/cve_syncer_test.go (1)

60-61: Minor: hoist the discard logger out of the loop.

slog.New(slog.DiscardHandler) is allocated on every iteration. Since the logger is stateless, it can be created once before the loop.

♻️ Suggested change

Add before the loop (e.g., around line 55):

discardLogger := slog.New(slog.DiscardHandler)

Then on line 61:

-			convertedLegacyVuln := convertAPI20CVEToLegacy(t.Context(), api20Vuln.CVE, slog.New(slog.DiscardHandler))
+			convertedLegacyVuln := convertAPI20CVEToLegacy(t.Context(), api20Vuln.CVE, discardLogger)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/vulnerabilities/nvd/sync/cve_syncer_test.go` around lines 60 - 61,
Hoist the stateless discard logger out of the loop so you don't allocate it on
every iteration: create a single discardLogger using
slog.New(slog.DiscardHandler) before iterating over api20CVEs, then pass that
discardLogger into convertAPI20CVEToLegacy inside the loop instead of calling
slog.New(slog.DiscardHandler) each time.
tools/nvd/nvdvuln/nvdvuln.go (1)

296-306: Optional: simplify vulnDBSync body.

The error-forwarding dance (if err != nil { return err }; return nil) can be reduced to a direct return; the function is already a thin wrapper.

♻️ Proposed simplification
 func vulnDBSync(ctx context.Context, vulnDBDir string, debug bool, logger *slog.Logger) error {
 	opts := nvd.SyncOptions{
 		VulnPath: vulnDBDir,
 		Debug:    debug,
 	}
-	err := nvd.Sync(ctx, opts, logger)
-	if err != nil {
-		return err
-	}
-	return nil
+	return nvd.Sync(ctx, opts, logger)
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/nvd/nvdvuln/nvdvuln.go` around lines 296 - 306, The vulnDBSync function
body contains an unnecessary error check; replace the current pattern in
vulnDBSync that assigns err := nvd.Sync(...), checks if err != nil then returns
err, and finally returns nil, with a direct return of the call to nvd.Sync(ctx,
opts, logger). Keep construction of opts (nvd.SyncOptions with VulnPath and
Debug) as-is and then simply return nvd.Sync(ctx, opts, logger) to simplify the
wrapper.
cmd/fleet/cron.go (1)

455-473: Consider: repeated logger.SlogLogger() calls could be hoisted.

Both goval_dictionary.Refresh (Line 458) and goval_dictionary.Analyze (Line 473) call logger.SlogLogger() separately. You could hoist a single slogLogger := logger.SlogLogger() at the top of checkGovalDictionaryVulnerabilities and reuse it. Same applies to checkNVDVulnerabilities which has four such calls. This is purely a readability nit — no functional concern.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/fleet/cron.go` around lines 455 - 473, Multiple repeated calls to
logger.SlogLogger() reduce readability; hoist a single slogLogger :=
logger.SlogLogger() at the top of checkGovalDictionaryVulnerabilities and
replace the calls to goval_dictionary.Refresh(..., logger.SlogLogger()) and
goval_dictionary.Analyze(..., logger.SlogLogger()) to use slogLogger instead,
and do the same in checkNVDVulnerabilities (replace its four logger.SlogLogger()
calls with the single slogLogger variable) so the same slog instance is reused
throughout each function.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmd/fleet/cron.go`:
- Around line 455-473: Multiple repeated calls to logger.SlogLogger() reduce
readability; hoist a single slogLogger := logger.SlogLogger() at the top of
checkGovalDictionaryVulnerabilities and replace the calls to
goval_dictionary.Refresh(..., logger.SlogLogger()) and
goval_dictionary.Analyze(..., logger.SlogLogger()) to use slogLogger instead,
and do the same in checkNVDVulnerabilities (replace its four logger.SlogLogger()
calls with the single slogLogger variable) so the same slog instance is reused
throughout each function.

In `@server/vulnerabilities/nvd/sync/cve_syncer_test.go`:
- Around line 60-61: Hoist the stateless discard logger out of the loop so you
don't allocate it on every iteration: create a single discardLogger using
slog.New(slog.DiscardHandler) before iterating over api20CVEs, then pass that
discardLogger into convertAPI20CVEToLegacy inside the loop instead of calling
slog.New(slog.DiscardHandler) each time.

In `@tools/nvd/nvdvuln/nvdvuln.go`:
- Around line 296-306: The vulnDBSync function body contains an unnecessary
error check; replace the current pattern in vulnDBSync that assigns err :=
nvd.Sync(...), checks if err != nil then returns err, and finally returns nil,
with a direct return of the call to nvd.Sync(ctx, opts, logger). Keep
construction of opts (nvd.SyncOptions with VulnPath and Debug) as-is and then
simply return nvd.Sync(ctx, opts, logger) to simplify the wrapper.

Copilot AI left a comment

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.

Pull request overview

This PR migrates the vulnerabilities packages (nvd, msrc, goval_dictionary, customcve) from go-kit/log to the standard library's log/slog as part of the ongoing slog migration effort tracked in issue #40054.

Changes:

  • Migrated all vulnerability processing packages from go-kit/log to *slog.Logger
  • Added context.Context parameters to functions that use logging for proper context-aware logging
  • Updated test files to use slog.New(slog.DiscardHandler) and t.Context()
  • Updated integration points (cron jobs, CLI tools) to work with new logger signatures

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/nvd/nvdvuln/nvdvuln.go Migrated CLI tool to create slog logger directly, added context to vulnDBSync
server/vulnerabilities/nvd/sync_test.go Updated tests to use slog.DiscardHandler
server/vulnerabilities/nvd/sync/cve_syncer_test.go Updated tests to use t.Context() and slog.DiscardHandler
server/vulnerabilities/nvd/sync/cve_syncer.go Migrated CVE syncer to *slog.Logger, added context to functions, updated logging calls
server/vulnerabilities/nvd/sync.go Migrated sync functions to *slog.Logger with context
server/vulnerabilities/nvd/db.go Updated sqliteDBReadOnly to use *slog.Logger
server/vulnerabilities/nvd/cve_test.go Updated tests to use slog.DiscardHandler
server/vulnerabilities/nvd/cve.go Migrated CVE processing functions to *slog.Logger with context
server/vulnerabilities/nvd/cpe_test.go Updated tests to use t.Context() and slog.DiscardHandler
server/vulnerabilities/nvd/cpe.go Migrated CPE processing to *slog.Logger with context, updated software transformers
server/vulnerabilities/msrc/analyzer_test.go Updated tests to use t.Context() and slog.DiscardHandler
server/vulnerabilities/msrc/analyzer.go Migrated Windows vulnerability analyzer to *slog.Logger with context
server/vulnerabilities/goval_dictionary/sync.go Migrated sync function to *slog.Logger with context
server/vulnerabilities/goval_dictionary/database_test.go Updated tests to use t.Context() and slog.DiscardHandler
server/vulnerabilities/goval_dictionary/database.go Migrated database evaluation to *slog.Logger with context
server/vulnerabilities/goval_dictionary/analyzer.go Updated analyzer function to use *slog.Logger
server/vulnerabilities/customcve/matching_rules_test.go Updated tests to use slog.DiscardHandler
server/vulnerabilities/customcve/matching_rules.go Migrated custom CVE matching to *slog.Logger
cmd/fleet/cron.go Updated cron jobs to call logger.SlogLogger() when passing to vulnerability functions
cmd/cve/validate/main.go Migrated validation CLI tool to create slog logger directly, added context

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/vulnerabilities/nvd/cve.go
Comment thread server/vulnerabilities/nvd/cve.go
@codecov

codecov Bot commented Feb 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.80851% with 75 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.30%. Comparing base (357c42c) to head (842c219).
⚠️ Report is 71 commits behind head on main.

Files with missing lines Patch % Lines
server/vulnerabilities/nvd/sync/cve_syncer.go 33.33% 21 Missing and 1 partial ⚠️
server/vulnerabilities/nvd/cpe.go 68.42% 12 Missing ⚠️
cmd/cve/generate.go 0.00% 11 Missing ⚠️
server/vulnerabilities/nvd/cve.go 50.00% 8 Missing ⚠️
server/vulnerabilities/nvd/sync.go 62.50% 6 Missing ⚠️
cmd/cve/validate/main.go 0.00% 5 Missing ⚠️
cmd/fleet/cron.go 62.50% 2 Missing and 1 partial ⚠️
server/vulnerabilities/customcve/matching_rules.go 25.00% 3 Missing ⚠️
...erver/vulnerabilities/goval_dictionary/database.go 33.33% 2 Missing ⚠️
...erver/vulnerabilities/goval_dictionary/analyzer.go 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #40106      +/-   ##
==========================================
+ Coverage   66.28%   66.30%   +0.01%     
==========================================
  Files        2445     2446       +1     
  Lines      195899   196001     +102     
  Branches     8676     8676              
==========================================
+ Hits       129847   129949     +102     
  Misses      54291    54291              
  Partials    11761    11761              
Flag Coverage Δ
backend 68.10% <46.80%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@getvictor
getvictor marked this pull request as ready for review February 19, 2026 17:29
@getvictor
getvictor requested a review from a team as a code owner February 19, 2026 17:29

@mostlikelee mostlikelee left a comment

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.

LGTM, agree with the warning levels on many of the retryable failures

@getvictor
getvictor merged commit ae4ccdf into main Feb 20, 2026
50 checks passed
@getvictor
getvictor deleted the victor/40054-slog-vulns branch February 20, 2026 21:36
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.

slog migration (2)

3 participants