Skip to content

Commit 61a047c

Browse files
committed
test(integration): add e2e test for log rate limiting
Add integration tests that verify the rate-limited logging infrastructure works end-to-end: - rate_limited_log_count metric exists in the metrics output and is zero under normal (non-error) operation - Normal balloon inflate/deflate does not trigger spurious suppression summary messages in the log output Signed-off-by: Nikita Kalyazin <kalyazin@amazon.com>
1 parent 6416d3b commit 61a047c

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
"""Tests for per-callsite log rate limiting.
4+
5+
Validates that the rate-limited logging infrastructure is wired up correctly
6+
end-to-end: the rate_limited_log_count metric exists in the metrics output,
7+
and normal balloon operations (which use error_rate_limited! at some callsites)
8+
do not produce spurious suppression summaries under non-error conditions.
9+
"""
10+
11+
12+
def test_rate_limited_metric_exists(uvm_plain):
13+
"""
14+
Verify that the rate_limited_log_count metric is present in the
15+
metrics output and is zero under normal (non-error) operation.
16+
"""
17+
microvm = uvm_plain
18+
microvm.spawn()
19+
microvm.basic_config()
20+
microvm.start()
21+
22+
metrics = microvm.flush_metrics()
23+
24+
# The logger metrics should contain the new rate_limited_log_count field.
25+
assert "logger" in metrics
26+
assert "rate_limited_log_count" in metrics["logger"]
27+
# Under normal operation no messages should be rate-limited.
28+
assert metrics["logger"]["rate_limited_log_count"] == 0
29+
30+
31+
def test_no_spurious_suppression_in_logs(uvm_plain):
32+
"""
33+
Verify that normal balloon inflate/deflate does not trigger rate
34+
limiting suppression messages in the log output.
35+
"""
36+
microvm = uvm_plain
37+
microvm.spawn(log_show_level=True)
38+
microvm.basic_config()
39+
microvm.add_net_iface()
40+
41+
# Add a balloon device.
42+
microvm.api.balloon.put(
43+
amount_mib=0, deflate_on_oom=True, stats_polling_interval_s=0
44+
)
45+
microvm.start()
46+
47+
# Inflate and deflate — this exercises the balloon code paths that
48+
# now use error_rate_limited!, but under normal operation none of
49+
# the error paths should fire.
50+
microvm.api.balloon.patch(amount_mib=64)
51+
microvm.api.balloon.patch(amount_mib=0)
52+
53+
log_data = microvm.log_data
54+
# No suppression summary should appear in normal operation.
55+
assert "messages were suppressed at" not in log_data
56+
57+
# Verify metric is still zero.
58+
metrics = microvm.flush_metrics()
59+
assert metrics["logger"]["rate_limited_log_count"] == 0

0 commit comments

Comments
 (0)