Skip to content

Migrating MDM files to slog method signatures. - #40263

Merged
getvictor merged 4 commits into
mainfrom
victor/40054-mdm-slog
Feb 23, 2026
Merged

Migrating MDM files to slog method signatures.#40263
getvictor merged 4 commits into
mainfrom
victor/40054-mdm-slog

Conversation

@getvictor

@getvictor getvictor commented Feb 22, 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.

Testing

  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • Refactor
    • Updated internal logging infrastructure across Mobile Device Management (MDM) service modules to improve code consistency and maintainability.

@getvictor

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Feb 22, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai

coderabbitai Bot commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request continues the migration of logging from go-kit/log to slog across MDM service files. It replaces all occurrences of the go-kit/log level API (level.Debug, level.Error, etc.) with context-aware slog logging methods (svc.logger.DebugContext, ErrorContext, WarnContext, InfoContext) in server/service/apple_mdm.go, server/service/mdm.go, and server/service/microsoft_mdm.go. The changes remove the dependency on github.com/go-kit/log/level and update logging statements while preserving existing error handling and control flow.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% 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 clearly describes the main change: migrating MDM files to use slog method signatures, which matches the code changes replacing go-kit/log with slog-based logging.
Description check ✅ Passed The description includes the related issue reference (#40054) and marks relevant checklist items as complete, though it is minimal and does not provide detailed explanation of changes.
Linked Issues check ✅ Passed The PR fulfills the objective of continuing slog migration work as outlined in issue #40054, updating MDM files to use slog method signatures instead of go-kit/log.
Out of Scope Changes check ✅ Passed All changes are in-scope, consisting solely of logging API migrations in MDM-related files and a changelog entry, with no unrelated modifications.

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

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

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/service/microsoft_mdm.go (1)

1081-1084: Consider passing err directly instead of err.Error().

slog accepts error values natively; err.Error() narrows the attribute to a plain string, discarding the error type for structured backends. Other call sites in this file (e.g., line 2635: "err", err) already use the idiomatic form.

♻️ Suggested change
-		svc.logger.DebugContext(ctx, "invalid discover message",
-			"err", err.Error(),
-			"request_xml", string(req.Raw),
-		)
+		svc.logger.DebugContext(ctx, "invalid discover message",
+			"err", err,
+			"request_xml", string(req.Raw),
+		)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/service/microsoft_mdm.go` around lines 1081 - 1084, In
svc.logger.DebugContext(ctx, "invalid discover message", ...) replace the "err",
err.Error() attribute with "err", err so the error is passed as an error value
(preserving type and structured metadata) alongside the existing "request_xml",
string(req.Raw) arguments; update the call site using the
svc.logger.DebugContext method, keeping ctx and req.Raw unchanged.
server/service/mdm.go (2)

813-813: Consider WarnContext for a failed datastore call.

The error from GetVPPAppInstallStatusByCommandUUID is intentionally swallowed (VPP status is best-effort), which is fine, but logging it at Debug makes the failure invisible in production where debug logging is usually disabled. WarnContext would keep the same non-fatal semantics while ensuring the failure surfaces in normal log levels.

♻️ Suggested change
-       svc.logger.DebugContext(ctx, "failed to check if VPP app is installed", "err", err, "command_uuid", commandUUID)
+       svc.logger.WarnContext(ctx, "failed to check if VPP app is installed", "err", err, "command_uuid", commandUUID)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/service/mdm.go` at line 813, The log for the best-effort datastore
call currently uses svc.logger.DebugContext for the error returned by
GetVPPAppInstallStatusByCommandUUID; change that call to use
svc.logger.WarnContext so the swallowed, non-fatal error is visible at normal
log levels (keep the same message keys like "err" and "command_uuid" and the
same context variable commandUUID and function
GetVPPAppInstallStatusByCommandUUID).

1075-1075: Prefer "err" over "details" for error key.

The conventional slog key name for an error value is "err", which tools and log aggregators often recognise specially. "details" works but departs from the pattern used elsewhere in the migrated codebase.

♻️ Suggested change
-       svc.logger.ErrorContext(ctx, "unauthorized to view some team commands", "details", authzErr)
+       svc.logger.ErrorContext(ctx, "unauthorized to view some team commands", "err", authzErr)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/service/mdm.go` at line 1075, Change the log key from "details" to the
conventional "err" in the ErrorContext call so the error is recognized
consistently; update the call to svc.logger.ErrorContext(...) that currently
passes "details", authzErr to instead pass "err", authzErr (look for the
ErrorContext invocation around svc.logger.ErrorContext and the authzErr variable
in mdm.go).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@server/service/mdm.go`:
- Line 813: The log for the best-effort datastore call currently uses
svc.logger.DebugContext for the error returned by
GetVPPAppInstallStatusByCommandUUID; change that call to use
svc.logger.WarnContext so the swallowed, non-fatal error is visible at normal
log levels (keep the same message keys like "err" and "command_uuid" and the
same context variable commandUUID and function
GetVPPAppInstallStatusByCommandUUID).
- Line 1075: Change the log key from "details" to the conventional "err" in the
ErrorContext call so the error is recognized consistently; update the call to
svc.logger.ErrorContext(...) that currently passes "details", authzErr to
instead pass "err", authzErr (look for the ErrorContext invocation around
svc.logger.ErrorContext and the authzErr variable in mdm.go).

In `@server/service/microsoft_mdm.go`:
- Around line 1081-1084: In svc.logger.DebugContext(ctx, "invalid discover
message", ...) replace the "err", err.Error() attribute with "err", err so the
error is passed as an error value (preserving type and structured metadata)
alongside the existing "request_xml", string(req.Raw) arguments; update the call
site using the svc.logger.DebugContext method, keeping ctx and req.Raw
unchanged.

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 continues the ongoing slog migration effort (issue #40054, following #38889) by converting MDM-related service files from go-kit/log to slog. The migration updates all logging calls in the MDM service layer to use the slog-style context-aware logging methods.

Changes:

  • Migrated logging calls from level.Debug/Info/Warn/Error(logger).Log(...) to logger.DebugContext/InfoContext/WarnContext/ErrorContext(ctx, ...)
  • Removed unused go-kit/log/level import from MDM service files
  • Added changelog entry documenting completion of slog migration

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
server/service/microsoft_mdm.go Migrated 7 logging calls to slog pattern; removed level import
server/service/mdm.go Migrated 6 logging calls to slog pattern; removed level import
server/service/apple_mdm.go Migrated 80+ logging calls to slog pattern; removed level import
changes/40054-slog-2 Added user-facing changelog entry for completed migration

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

Comment thread server/service/apple_mdm.go Outdated
@getvictor
getvictor marked this pull request as ready for review February 22, 2026 20:42
@getvictor
getvictor requested a review from a team as a code owner February 22, 2026 20:42
@codecov

codecov Bot commented Feb 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.78261% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.27%. Comparing base (e070072) to head (76abd66).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
server/service/apple_mdm.go 58.25% 43 Missing ⚠️
server/service/mdm.go 14.28% 6 Missing ⚠️
server/service/microsoft_mdm.go 40.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #40263   +/-   ##
=======================================
  Coverage   66.27%   66.27%           
=======================================
  Files        2459     2459           
  Lines      197024   196999   -25     
  Branches     8609     8609           
=======================================
- Hits       130568   130554   -14     
+ Misses      54637    54626   -11     
  Partials    11819    11819           
Flag Coverage Δ
backend 68.13% <54.78%> (+<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.

Comment thread server/service/apple_mdm.go
@getvictor
getvictor merged commit 22a8cd3 into main Feb 23, 2026
47 checks passed
@getvictor
getvictor deleted the victor/40054-mdm-slog branch February 23, 2026 15:27
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