Skip to content

Log plugin RPC operations and connections#71

Open
vyasgun wants to merge 2 commits into
crc-org:masterfrom
vyasgun:pr/operation-logs
Open

Log plugin RPC operations and connections#71
vyasgun wants to merge 2 commits into
crc-org:masterfrom
vyasgun:pr/operation-logs

Conversation

@vyasgun

@vyasgun vyasgun commented Jun 29, 2026

Copy link
Copy Markdown

This PR also fixes linter warnings and deprecations

How to test:

  1. Checkout the PR branch

    git checkout pr/operation-logs
  2. Update machine-driver-libvirt

    cd ../machine-driver-libvirt
    go mod edit -replace=github.com/crc-org/machine=../machine
    go mod vendor
    make clean
    make local
    cp crc-driver-libvirt-local ~/.crc/bin/crc-driver-libvirt-amd64
  3. Update CRC

    cd ../crc
    go mod edit -replace=github.com/crc-org/machine=../machine
    go mod vendor
    make clean
    make
  4. Clean up and start fresh

    crc stop
    crc delete -f
    crc cleanup
  5. Verify RPC logging

    Start CRC and verify that RPC operations and connections are logged in ~/.crc/crc.log:

    grep RPC ~/.crc/crc.log

Logs visible in ~/.crc/crc.log as follows:

grep RPC ~/.crc/crc.log
time="2026-07-07T14:53:51+05:30" level=debug msg="() DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC connection accepted\" remote=\"127.0.0.1:56308\""
time="2026-07-07T14:53:51+05:30" level=debug msg="() DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" machine=default operation=GetVersion"
time="2026-07-07T14:53:51+05:30" level=debug msg="() DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" config_bytes=471 machine=default operation=SetConfigRaw"
time="2026-07-07T14:53:51+05:30" level=debug msg="() DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=GetMachineName"
time="2026-07-07T14:53:51+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=GetMachineName"
time="2026-07-07T14:53:51+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=DriverName"
time="2026-07-07T14:53:51+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=PreCreateCheck"
time="2026-07-07T14:53:51+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" config_bytes=471 machine=crc operation=GetConfigRaw"
time="2026-07-07T14:53:51+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=Create"
time="2026-07-07T14:53:51+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=Close"
time="2026-07-07T14:53:51+05:30" level=debug msg="() DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC connection accepted\" remote=\"127.0.0.1:41556\""
time="2026-07-07T14:53:51+05:30" level=debug msg="() DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" machine=default operation=GetVersion"
time="2026-07-07T14:53:51+05:30" level=debug msg="() DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" config_bytes=769 machine=default operation=SetConfigRaw"
time="2026-07-07T14:53:51+05:30" level=debug msg="() DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=GetMachineName"
time="2026-07-07T14:53:51+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=GetBundleName"
time="2026-07-07T14:53:51+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=GetState"
time="2026-07-07T14:53:51+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" config_bytes=471 machine=crc operation=GetConfigRaw"
time="2026-07-07T14:53:51+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:51+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=Start"
time="2026-07-07T14:53:52+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:52+05:30\" level=info msg=\"RPC server invocation\" config_bytes=471 machine=crc operation=GetConfigRaw"
time="2026-07-07T14:53:52+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:52+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=GetState"
time="2026-07-07T14:53:52+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:53:52+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=GetState"
time="2026-07-07T14:54:06+05:30" level=debug msg="(crc) DBG | time=\"2026-07-07T14:54:06+05:30\" level=info msg=\"RPC server invocation\" machine=crc operation=GetSharedDirs shared_dirs=1"

Note: The PR description previously mentioned ~/.crc/crcd.log, but the correct log file is ~/.crc/crc.log.

Summary by CodeRabbit

  • New Features
    • Added more detailed logging for remote control connections and operations, including connection start/end timing and action-level context.
  • Chores
    • Simplified linter configuration by removing an unused rule.
    • Cleaned up a few unused parameter names in driver interfaces without changing behavior.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

RPC connection handling now logs accept and close events, and RPCServerDriver methods now emit structured logs with operation names and selected metadata. The deadcode linter entry is removed, and two UpdateConfigRaw parameters are marked intentionally unused.

Changes

RPC Logging and Cleanup

Layer / File(s) Summary
Unused parameter names and linter removal
.golangci.yml, drivers/fakedriver/fakedriver.go, libmachine/drivers/base.go
deadcode is removed from the enabled linters list, and both UpdateConfigRaw methods rename their byte parameter to _ while keeping existing return behavior.
Listener and connection logging
libmachine/drivers/plugin/register_driver.go
loggingListener and loggingConn wrap the RPC listener and connection lifecycle; accept and close events are logged with remote address and duration, and http.Serve uses the wrapper.
RPC method logging helper
libmachine/drivers/rpc/server_driver.go
logrus is imported, logRPC is added with panic-safe machine-name lookup, and RPCServerDriver methods log operation names plus config/shared-dir metadata before delegating.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant http.Serve
  participant loggingListener
  participant loggingConn
  participant TCPListener
  http.Serve->>loggingListener: Accept()
  loggingListener->>TCPListener: Accept connection
  loggingListener->>loggingConn: wrap accepted connection
  loggingConn->>loggingConn: Close() logs remote address and duration
Loading
sequenceDiagram
  participant RPCServerDriver
  participant logRPC
  participant ActualDriver
  RPCServerDriver->>logRPC: record method name and machine name
  RPCServerDriver->>ActualDriver: delegate method call
  ActualDriver-->>RPCServerDriver: return result
Loading

Poem

🐇 I hop through logs from start to end,
With listener wraps to greet each friend.
A blank _ tells unused bytes to rest,
And RPC calls now leave their best.
The warren hums with tidy light,
While logrus keeps the trail in sight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 accurately summarizes the main change: added logging for plugin RPC operations and connection events.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Comment thread libmachine/drivers/plugin/register_driver.go Outdated
Comment thread .golangci.yml
- gofmt
- gosec
- gocritic
- deadcode

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is unused enabled by defaut?

For what it’s worth, this golangci-lint config is a v1 config while upstream has moved on to v2. Not sure it’s worth switching to v2 though…

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes, unused is enabled by default.
If we move to a v2 config, there are many linter errors that need to be fixed. Might be worth creating a different PR for it.

Comment thread libmachine/drivers/rpc/server_driver.go Outdated
}

func (r *RPCServerDriver) DriverName(_ *struct{}, reply *string) error {
r.logRPC("DriverName", log.DebugLevel, nil)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How did you decide between the various log levels?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I changed them back to Info for consistency.

vyasgun added 2 commits July 2, 2026 13:21
Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
Signed-off-by: Gunjan Vyas <vyasgun20@gmail.com>
@vyasgun vyasgun force-pushed the pr/operation-logs branch from f4384e8 to 14e8db9 Compare July 2, 2026 07:55
@anjannath

Copy link
Copy Markdown
Member

@vyasgun I replaced the machine module in the crc code base with the branch from this PR and ran crc start, crc stop but didn't get the RPC logs either in stdout or the ~/.crc/crcd.log, could you please write here how to test this?

@vyasgun

vyasgun commented Jul 7, 2026

Copy link
Copy Markdown
Author

@anjannath you'll also need to replace the reference in machine-driver-libvirt and check ~/.crc/crc.log for the logs. (Sorry about the mistake in the original description. I've fixed it and added the testing steps.)

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.

3 participants