Skip to content

Serial device rate limiter#5824

Merged
ShadowCurse merged 6 commits intofirecracker-microvm:mainfrom
kalyazin:console_rate_limiter
Apr 14, 2026
Merged

Serial device rate limiter#5824
ShadowCurse merged 6 commits intofirecracker-microvm:mainfrom
kalyazin:console_rate_limiter

Conversation

@kalyazin
Copy link
Copy Markdown
Contributor

@kalyazin kalyazin commented Apr 8, 2026

Changes

Add optional rate limiter to the serial device

Reason

To be able to limit the amount of console output generated by the guest.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • I have read and understand CONTRIBUTING.md.
  • I have run tools/devtool checkbuild --all to verify that the PR passes
    build checks on all supported architectures.
  • I have run tools/devtool checkstyle to verify that the PR passes the
    automated style checks.
  • I have described what is done in these changes, why they are needed, and
    how they are solving the problem in a clear and encompassing way.
  • I have updated any relevant documentation (both in code and in the docs)
    in the PR.
  • I have mentioned all user-facing changes in CHANGELOG.md.
  • If a specific issue led to this PR, this PR closes the issue.
  • When making API changes, I have followed the
    Runbook for Firecracker API changes.
  • I have tested all new and changed functionalities in unit tests and/or
    integration tests.
  • I have linked an issue to every new TODO.

  • This functionality cannot be added in rust-vmm.

@kalyazin kalyazin force-pushed the console_rate_limiter branch from a98212f to f1a86a9 Compare April 8, 2026 16:55
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 8, 2026

Codecov Report

❌ Patch coverage is 73.97260% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.04%. Comparing base (33bfb59) to head (0143259).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/vmm/src/device_manager/mod.rs 76.47% 8 Missing ⚠️
src/vmm/src/resources.rs 33.33% 6 Missing ⚠️
src/vmm/src/devices/legacy/serial.rs 88.46% 3 Missing ⚠️
src/vmm/src/device_manager/persist.rs 0.00% 1 Missing ⚠️
src/vmm/src/rpc_interface.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5824      +/-   ##
==========================================
- Coverage   83.07%   83.04%   -0.04%     
==========================================
  Files         275      275              
  Lines       29462    29528      +66     
==========================================
+ Hits        24476    24521      +45     
- Misses       4986     5007      +21     
Flag Coverage Δ
5.10-m5n.metal 83.38% <72.30%> (-0.03%) ⬇️
5.10-m6a.metal 82.71% <72.30%> (-0.04%) ⬇️
5.10-m6g.metal 79.96% <63.15%> (-0.03%) ⬇️
5.10-m6i.metal 83.37% <72.30%> (-0.03%) ⬇️
5.10-m7a.metal-48xl 82.70% <72.30%> (-0.03%) ⬇️
5.10-m7g.metal 79.96% <63.15%> (-0.03%) ⬇️
5.10-m7i.metal-24xl 83.34% <72.30%> (-0.04%) ⬇️
5.10-m7i.metal-48xl 83.35% <72.30%> (-0.03%) ⬇️
5.10-m8g.metal-24xl 79.95% <63.15%> (-0.03%) ⬇️
5.10-m8g.metal-48xl 79.96% <63.15%> (-0.03%) ⬇️
5.10-m8i.metal-48xl 83.35% <72.30%> (-0.03%) ⬇️
5.10-m8i.metal-96xl 83.35% <72.30%> (-0.04%) ⬇️
6.1-m5n.metal 83.40% <72.30%> (-0.03%) ⬇️
6.1-m6a.metal 82.73% <72.30%> (-0.04%) ⬇️
6.1-m6g.metal 79.95% <63.15%> (-0.03%) ⬇️
6.1-m6i.metal 83.40% <72.30%> (-0.04%) ⬇️
6.1-m7a.metal-48xl 82.72% <72.30%> (-0.04%) ⬇️
6.1-m7g.metal 79.95% <63.15%> (-0.04%) ⬇️
6.1-m7i.metal-24xl 83.41% <72.30%> (-0.04%) ⬇️
6.1-m7i.metal-48xl 83.41% <72.30%> (-0.03%) ⬇️
6.1-m8g.metal-24xl 79.95% <63.15%> (-0.03%) ⬇️
6.1-m8g.metal-48xl 79.95% <63.15%> (-0.03%) ⬇️
6.1-m8i.metal-48xl 83.41% <72.30%> (-0.04%) ⬇️
6.1-m8i.metal-96xl 83.41% <72.30%> (-0.04%) ⬇️

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.

@kalyazin kalyazin force-pushed the console_rate_limiter branch from f1a86a9 to e57c5ff Compare April 8, 2026 17:06
@JamesC1305 JamesC1305 linked an issue Apr 8, 2026 that may be closed by this pull request
3 tasks
@kalyazin kalyazin force-pushed the console_rate_limiter branch from e57c5ff to 7dcf338 Compare April 9, 2026 09:45
@kalyazin kalyazin marked this pull request as ready for review April 9, 2026 12:07
@kalyazin kalyazin requested review from Manciukic and pb8o as code owners April 9, 2026 12:07
@kalyazin kalyazin force-pushed the console_rate_limiter branch from 7dcf338 to 4468f30 Compare April 9, 2026 12:07
@kalyazin kalyazin self-assigned this Apr 9, 2026
@kalyazin kalyazin added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Apr 9, 2026
Comment thread src/vmm/src/devices/legacy/serial.rs Outdated
Comment thread src/vmm/src/devices/legacy/serial.rs Outdated
@kalyazin kalyazin force-pushed the console_rate_limiter branch 2 times, most recently from d673b55 to 9438dca Compare April 13, 2026 10:27
@kalyazin kalyazin requested a review from micz010 as a code owner April 13, 2026 10:27
@kalyazin kalyazin force-pushed the console_rate_limiter branch 2 times, most recently from 3afef5e to b529745 Compare April 13, 2026 11:29
@kalyazin kalyazin changed the title Serial device rate limiter and sanitisation Serial device rate limiter Apr 13, 2026
Comment thread src/vmm/src/devices/legacy/serial.rs Outdated
Restructure SerialOut from an enum to a struct wrapping
SerialOutInner + TokenBucket.  The Write impl rate-limits guest
output via a token bucket, dropping excess bytes when the budget
is empty.

Signed-off-by: Nikita Kalyazin <kalyazin@amazon.com>
Add an optional rate_limiter field (TokenBucket) to the SerialConfig
definition in the Firecracker swagger spec.  When present, guest
writes to the serial port that exceed the configured rate are silently
dropped and counted in the uart.rate_limiter_dropped_bytes metric.

Signed-off-by: Nikita Kalyazin <kalyazin@amazon.com>
Add the serial endpoint to the API Endpoints table, the SerialConfig
schema with serial_out_path and rate_limiter fields to the Input
Schema table, and update the TokenBucket footnote to include serial.

Signed-off-by: Nikita Kalyazin <kalyazin@amazon.com>
@kalyazin kalyazin force-pushed the console_rate_limiter branch from b529745 to f1d2789 Compare April 13, 2026 15:10
ShadowCurse
ShadowCurse previously approved these changes Apr 13, 2026
Copy link
Copy Markdown
Contributor

@Manciukic Manciukic left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, just one nit. Also, we should update the `docs/prod-host-setup.md as well:

Firecracker does
not offer users the option to limit serial data transfer, nor does it impose any
restrictions on stdout handling.

Comment thread src/vmm/src/rpc_interface.rs
Advertise the rate limiter as a recommended measure for serial device in
prod host setup.

Signed-off-by: Nikita Kalyazin <kalyazin@amazon.com>
Add test_serial_rate_limiting to test_serial_io.py. The test configures
a rate limiter via the PUT /serial API before boot.

Update fcmetrics.py schema with the new uart metric field:
rate_limiter_dropped_bytes.

Signed-off-by: Nikita Kalyazin <kalyazin@amazon.com>
Add an entry under [Unreleased] > Added describing the new serial
console output optional rate limiting feature.

Signed-off-by: Nikita Kalyazin <kalyazin@amazon.com>
@kalyazin kalyazin force-pushed the console_rate_limiter branch from f1d2789 to 0143259 Compare April 13, 2026 16:41
@kalyazin
Copy link
Copy Markdown
Contributor Author

Mostly LGTM, just one nit. Also, we should update the `docs/prod-host-setup.md as well:

Firecracker does
not offer users the option to limit serial data transfer, nor does it impose any
restrictions on stdout handling.

Thanks, updated.

@ShadowCurse ShadowCurse merged commit 8ddea25 into firecracker-microvm:main Apr 14, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Awaiting review Indicates that a pull request is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants