Skip to content

Commit 7c8a9a4

Browse files
committed
feat(balloon): add logging for malformed balloon-stats tag
Added warn logging to the decode of BalloonStats if unknown tag is introduced. Additionally, updated integration test of BalloonStats to fail if this warn occurs. The Result type from the update method is removed and corresponding update metrics have been removed as it is no longer tracked. Signed-off-by: Aaron Lo <aaronlo0929@gmail.com>
1 parent d130c7d commit 7c8a9a4

File tree

4 files changed

+26
-33
lines changed

4 files changed

+26
-33
lines changed

src/vmm/src/devices/virtio/balloon/device.rs

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ops::Deref;
55
use std::sync::Arc;
66
use std::time::Duration;
77

8-
use log::{error, info, warn};
8+
use log::{debug, error, info, warn};
99
use serde::{Deserialize, Serialize};
1010
use utils::time::TimerFd;
1111
use vmm_sys_util::eventfd::EventFd;
@@ -207,7 +207,7 @@ pub struct BalloonStats {
207207
}
208208

209209
impl BalloonStats {
210-
fn update_with_stat(&mut self, stat: &BalloonStat) -> Result<(), BalloonError> {
210+
fn update_with_stat(&mut self, stat: &BalloonStat) {
211211
let val = Some(stat.val);
212212
match stat.tag {
213213
VIRTIO_BALLOON_S_SWAP_IN => self.swap_in = val,
@@ -226,12 +226,8 @@ impl BalloonStats {
226226
VIRTIO_BALLOON_S_DIRECT_SCAN => self.direct_scan = val,
227227
VIRTIO_BALLOON_S_ASYNC_RECLAIM => self.async_reclaim = val,
228228
VIRTIO_BALLOON_S_DIRECT_RECLAIM => self.direct_reclaim = val,
229-
_ => {
230-
return Err(BalloonError::MalformedPayload);
231-
}
229+
tag => debug!("balloon: unknown stats update tag: {tag}"),
232230
}
233-
234-
Ok(())
235231
}
236232
}
237233

@@ -503,10 +499,7 @@ impl Balloon {
503499
let stat = mem
504500
.read_obj::<BalloonStat>(addr)
505501
.map_err(|_| BalloonError::MalformedDescriptor)?;
506-
self.latest_stats.update_with_stat(&stat).map_err(|_| {
507-
METRICS.stats_update_fails.inc();
508-
BalloonError::MalformedPayload
509-
})?;
502+
self.latest_stats.update_with_stat(&stat);
510503
}
511504

512505
self.stats_desc_index = Some(head.index);
@@ -1067,52 +1060,52 @@ pub(crate) mod tests {
10671060
val: 1,
10681061
};
10691062

1070-
stats.update_with_stat(&stat).unwrap();
1063+
stats.update_with_stat(&stat);
10711064
assert_eq!(stats.swap_in, Some(1));
10721065
stat.tag = VIRTIO_BALLOON_S_SWAP_OUT;
1073-
stats.update_with_stat(&stat).unwrap();
1066+
stats.update_with_stat(&stat);
10741067
assert_eq!(stats.swap_out, Some(1));
10751068
stat.tag = VIRTIO_BALLOON_S_MAJFLT;
1076-
stats.update_with_stat(&stat).unwrap();
1069+
stats.update_with_stat(&stat);
10771070
assert_eq!(stats.major_faults, Some(1));
10781071
stat.tag = VIRTIO_BALLOON_S_MINFLT;
1079-
stats.update_with_stat(&stat).unwrap();
1072+
stats.update_with_stat(&stat);
10801073
assert_eq!(stats.minor_faults, Some(1));
10811074
stat.tag = VIRTIO_BALLOON_S_MEMFREE;
1082-
stats.update_with_stat(&stat).unwrap();
1075+
stats.update_with_stat(&stat);
10831076
assert_eq!(stats.free_memory, Some(1));
10841077
stat.tag = VIRTIO_BALLOON_S_MEMTOT;
1085-
stats.update_with_stat(&stat).unwrap();
1078+
stats.update_with_stat(&stat);
10861079
assert_eq!(stats.total_memory, Some(1));
10871080
stat.tag = VIRTIO_BALLOON_S_AVAIL;
1088-
stats.update_with_stat(&stat).unwrap();
1081+
stats.update_with_stat(&stat);
10891082
assert_eq!(stats.available_memory, Some(1));
10901083
stat.tag = VIRTIO_BALLOON_S_CACHES;
1091-
stats.update_with_stat(&stat).unwrap();
1084+
stats.update_with_stat(&stat);
10921085
assert_eq!(stats.disk_caches, Some(1));
10931086
stat.tag = VIRTIO_BALLOON_S_HTLB_PGALLOC;
1094-
stats.update_with_stat(&stat).unwrap();
1087+
stats.update_with_stat(&stat);
10951088
assert_eq!(stats.hugetlb_allocations, Some(1));
10961089
stat.tag = VIRTIO_BALLOON_S_HTLB_PGFAIL;
1097-
stats.update_with_stat(&stat).unwrap();
1090+
stats.update_with_stat(&stat);
10981091
assert_eq!(stats.hugetlb_failures, Some(1));
10991092
stat.tag = VIRTIO_BALLOON_S_OOM_KILL;
1100-
stats.update_with_stat(&stat).unwrap();
1093+
stats.update_with_stat(&stat);
11011094
assert_eq!(stats.oom_kill, Some(1));
11021095
stat.tag = VIRTIO_BALLOON_S_ALLOC_STALL;
1103-
stats.update_with_stat(&stat).unwrap();
1096+
stats.update_with_stat(&stat);
11041097
assert_eq!(stats.alloc_stall, Some(1));
11051098
stat.tag = VIRTIO_BALLOON_S_ASYNC_SCAN;
1106-
stats.update_with_stat(&stat).unwrap();
1099+
stats.update_with_stat(&stat);
11071100
assert_eq!(stats.async_scan, Some(1));
11081101
stat.tag = VIRTIO_BALLOON_S_DIRECT_SCAN;
1109-
stats.update_with_stat(&stat).unwrap();
1102+
stats.update_with_stat(&stat);
11101103
assert_eq!(stats.direct_scan, Some(1));
11111104
stat.tag = VIRTIO_BALLOON_S_ASYNC_RECLAIM;
1112-
stats.update_with_stat(&stat).unwrap();
1105+
stats.update_with_stat(&stat);
11131106
assert_eq!(stats.async_reclaim, Some(1));
11141107
stat.tag = VIRTIO_BALLOON_S_DIRECT_RECLAIM;
1115-
stats.update_with_stat(&stat).unwrap();
1108+
stats.update_with_stat(&stat);
11161109
assert_eq!(stats.direct_reclaim, Some(1));
11171110
}
11181111

src/vmm/src/devices/virtio/balloon/metrics.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ pub(super) struct BalloonDeviceMetrics {
5757
pub inflate_count: SharedIncMetric,
5858
// Number of balloon statistics updates from the driver.
5959
pub stats_updates_count: SharedIncMetric,
60-
// Number of balloon statistics update failures.
61-
pub stats_update_fails: SharedIncMetric,
6260
/// Number of balloon device deflations.
6361
pub deflate_count: SharedIncMetric,
6462
/// Number of times when handling events on a balloon device failed.
@@ -83,7 +81,6 @@ impl BalloonDeviceMetrics {
8381
activate_fails: SharedIncMetric::new(),
8482
inflate_count: SharedIncMetric::new(),
8583
stats_updates_count: SharedIncMetric::new(),
86-
stats_update_fails: SharedIncMetric::new(),
8784
deflate_count: SharedIncMetric::new(),
8885
event_fails: SharedIncMetric::new(),
8986
free_page_report_count: SharedIncMetric::new(),

src/vmm/src/devices/virtio/block/virtio/metrics.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ pub struct BlockDeviceMetrics {
163163
pub rate_limiter_event_count: SharedIncMetric,
164164
/// Number of update operation triggered on this block device.
165165
pub update_count: SharedIncMetric,
166-
/// Number of failures while doing update on this block device.
167-
pub update_fails: SharedIncMetric,
168166
/// Number of bytes read by this block device.
169167
pub read_bytes: SharedIncMetric,
170168
/// Number of bytes written by this block device.
@@ -215,7 +213,6 @@ impl BlockDeviceMetrics {
215213
self.rate_limiter_event_count
216214
.add(other.rate_limiter_event_count.fetch_diff());
217215
self.update_count.add(other.update_count.fetch_diff());
218-
self.update_fails.add(other.update_fails.fetch_diff());
219216
self.read_bytes.add(other.read_bytes.fetch_diff());
220217
self.write_bytes.add(other.write_bytes.fetch_diff());
221218
self.read_count.add(other.read_count.fetch_diff());

tests/integration_tests/functional/test_balloon.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ def test_stats(uvm_plain_any):
320320
# Get another reading of the stats after the polling interval has passed.
321321
deflated_stats = test_microvm.api.balloon_stats.get().json()
322322

323+
# Ensure that stats don't have unknown balloon stats fields
324+
assert "balloon: unknown stats update tag:" not in test_microvm.log_data
325+
323326
# Ensure the stats reflect deflating the balloon.
324327
assert inflated_stats["free_memory"] < deflated_stats["free_memory"]
325328
assert inflated_stats["available_memory"] < deflated_stats["available_memory"]
@@ -372,6 +375,9 @@ def test_stats_update(uvm_plain_any):
372375
final_stats = test_microvm.api.balloon_stats.get().json()
373376
assert next_stats["available_memory"] != final_stats["available_memory"]
374377

378+
# Ensure that stats don't have unknown balloon stats fields
379+
assert "balloon: unknown stats update tag:" not in test_microvm.log_data
380+
375381

376382
def test_balloon_snapshot(uvm_plain_any, microvm_factory):
377383
"""

0 commit comments

Comments
 (0)