Skip to content

Commit 6de9b50

Browse files
authored
Merge branch 'main' into dependabot/cargo/firecracker-a55a2eb063
2 parents 19a0a4a + 31748a3 commit 6de9b50

File tree

7 files changed

+98
-41
lines changed

7 files changed

+98
-41
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ and this project adheres to
1616

1717
### Removed
1818

19+
- [#5439](https://github.com/firecracker-microvm/firecracker/pull/5439): Removed
20+
the `rx_partial_writes`, `tx_partial_reads`, `sync_response_fails`,
21+
`sync_vmm_send_timeout_count`, `deprecated_cmd_line_api_calls`, `log_fails`
22+
and `device_events` metrics, as they were never incremented.
23+
1924
### Fixed
2025

2126
- [#5418](https://github.com/firecracker-microvm/firecracker/pull/5418): Fixed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ pub struct NetDeviceMetrics {
161161
pub rx_queue_event_count: SharedIncMetric,
162162
/// Number of events associated with the rate limiter installed on the receiving path.
163163
pub rx_event_rate_limiter_count: SharedIncMetric,
164-
/// Number of RX partial writes to guest.
165-
pub rx_partial_writes: SharedIncMetric,
166164
/// Number of RX rate limiter throttling events.
167165
pub rx_rate_limiter_throttled: SharedIncMetric,
168166
/// Number of events received on the associated tap.
@@ -191,8 +189,6 @@ pub struct NetDeviceMetrics {
191189
pub tx_count: SharedIncMetric,
192190
/// Number of transmitted packets.
193191
pub tx_packets_count: SharedIncMetric,
194-
/// Number of TX partial reads from guest.
195-
pub tx_partial_reads: SharedIncMetric,
196192
/// Number of events associated with the transmitting queue.
197193
pub tx_queue_event_count: SharedIncMetric,
198194
/// Number of events associated with the rate limiter installed on the transmitting path.
@@ -233,8 +229,6 @@ impl NetDeviceMetrics {
233229
.add(other.rx_queue_event_count.fetch_diff());
234230
self.rx_event_rate_limiter_count
235231
.add(other.rx_event_rate_limiter_count.fetch_diff());
236-
self.rx_partial_writes
237-
.add(other.rx_partial_writes.fetch_diff());
238232
self.rx_rate_limiter_throttled
239233
.add(other.rx_rate_limiter_throttled.fetch_diff());
240234
self.rx_tap_event_count
@@ -256,8 +250,6 @@ impl NetDeviceMetrics {
256250
self.tx_count.add(other.tx_count.fetch_diff());
257251
self.tx_packets_count
258252
.add(other.tx_packets_count.fetch_diff());
259-
self.tx_partial_reads
260-
.add(other.tx_partial_reads.fetch_diff());
261253
self.tx_queue_event_count
262254
.add(other.tx_queue_event_count.fetch_diff());
263255
self.tx_rate_limiter_event_count

src/vmm/src/logger/metrics.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,13 @@ pub struct ApiServerMetrics {
337337
pub process_startup_time_us: SharedStoreMetric,
338338
/// Measures the cpu's startup time in microseconds.
339339
pub process_startup_time_cpu_us: SharedStoreMetric,
340-
/// Number of failures on API requests triggered by internal errors.
341-
pub sync_response_fails: SharedIncMetric,
342-
/// Number of timeouts during communication with the VMM.
343-
pub sync_vmm_send_timeout_count: SharedIncMetric,
344340
}
345341
impl ApiServerMetrics {
346342
/// Const default construction.
347343
pub const fn new() -> Self {
348344
Self {
349345
process_startup_time_us: SharedStoreMetric::new(),
350346
process_startup_time_cpu_us: SharedStoreMetric::new(),
351-
sync_response_fails: SharedIncMetric::new(),
352-
sync_vmm_send_timeout_count: SharedIncMetric::new(),
353347
}
354348
}
355349
}
@@ -497,15 +491,12 @@ impl PatchRequestsMetrics {
497491
pub struct DeprecatedApiMetrics {
498492
/// Total number of calls to deprecated HTTP endpoints.
499493
pub deprecated_http_api_calls: SharedIncMetric,
500-
/// Total number of calls to deprecated CMD line parameters.
501-
pub deprecated_cmd_line_api_calls: SharedIncMetric,
502494
}
503495
impl DeprecatedApiMetrics {
504496
/// Const default construction.
505497
pub const fn new() -> Self {
506498
Self {
507499
deprecated_http_api_calls: SharedIncMetric::new(),
508-
deprecated_cmd_line_api_calls: SharedIncMetric::new(),
509500
}
510501
}
511502
}
@@ -519,8 +510,6 @@ pub struct LoggerSystemMetrics {
519510
pub metrics_fails: SharedIncMetric,
520511
/// Number of misses on logging human readable content.
521512
pub missed_log_count: SharedIncMetric,
522-
/// Number of errors while trying to log human readable content.
523-
pub log_fails: SharedIncMetric,
524513
}
525514
impl LoggerSystemMetrics {
526515
/// Const default construction.
@@ -529,7 +518,6 @@ impl LoggerSystemMetrics {
529518
missed_metrics_count: SharedIncMetric::new(),
530519
metrics_fails: SharedIncMetric::new(),
531520
missed_log_count: SharedIncMetric::new(),
532-
log_fails: SharedIncMetric::new(),
533521
}
534522
}
535523
}
@@ -806,16 +794,13 @@ impl VcpuMetrics {
806794
/// Metrics specific to the machine manager as a whole.
807795
#[derive(Debug, Default, Serialize)]
808796
pub struct VmmMetrics {
809-
/// Number of device related events received for a VM.
810-
pub device_events: SharedIncMetric,
811797
/// Metric for signaling a panic has occurred.
812798
pub panic_count: SharedStoreMetric,
813799
}
814800
impl VmmMetrics {
815801
/// Const default construction.
816802
pub const fn new() -> Self {
817803
Self {
818-
device_events: SharedIncMetric::new(),
819804
panic_count: SharedStoreMetric::new(),
820805
}
821806
}

tests/host_tools/fcmetrics.py

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import jsonschema
1919
import pytest
2020

21+
from framework import utils
2122
from framework.properties import global_props
23+
from framework.utils_repo import git_repo_files
2224
from host_tools.metrics import get_metrics_logger
2325

2426

@@ -105,7 +107,6 @@ def validate_fc_metrics(metrics):
105107
"event_fails",
106108
"rx_queue_event_count",
107109
"rx_event_rate_limiter_count",
108-
"rx_partial_writes",
109110
"rx_rate_limiter_throttled",
110111
"rx_tap_event_count",
111112
"rx_bytes_count",
@@ -119,7 +120,6 @@ def validate_fc_metrics(metrics):
119120
"tx_fails",
120121
"tx_count",
121122
"tx_packets_count",
122-
"tx_partial_reads",
123123
"tx_queue_event_count",
124124
"tx_rate_limiter_event_count",
125125
"tx_rate_limiter_throttled",
@@ -132,8 +132,6 @@ def validate_fc_metrics(metrics):
132132
"api_server": [
133133
"process_startup_time_us",
134134
"process_startup_time_cpu_us",
135-
"sync_response_fails",
136-
"sync_vmm_send_timeout_count",
137135
],
138136
"balloon": [
139137
"activate_fails",
@@ -146,7 +144,6 @@ def validate_fc_metrics(metrics):
146144
"block": block_metrics,
147145
"deprecated_api": [
148146
"deprecated_http_api_calls",
149-
"deprecated_cmd_line_api_calls",
150147
],
151148
"get_api_requests": [
152149
"instance_info_count",
@@ -178,7 +175,6 @@ def validate_fc_metrics(metrics):
178175
"missed_metrics_count",
179176
"metrics_fails",
180177
"missed_log_count",
181-
"log_fails",
182178
],
183179
"mmds": [
184180
"rx_accepted",
@@ -246,7 +242,6 @@ def validate_fc_metrics(metrics):
246242
{"exit_mmio_write_agg": latency_agg_metrics_fields},
247243
],
248244
"vmm": [
249-
"device_events",
250245
"panic_count",
251246
],
252247
"uart": [
@@ -570,3 +565,61 @@ def run(self):
570565
time.sleep(1)
571566
if self.running is False:
572567
break
568+
569+
570+
def find_metrics_files():
571+
"""Gets a list of all Firecracker sources files ending with 'metrics.rs'"""
572+
return list(git_repo_files(root="..", glob="*metrics.rs"))
573+
574+
575+
def extract_fields(file_path):
576+
"""Gets a list of all metrics defined in the given file, in the form tuples (name, type)"""
577+
fields = utils.run_cmd(
578+
rf'grep -Po "(?<=pub )(\w+): (Shared(?:Inc|Store)Metric|LatencyAggregateMetrics)" {file_path}'
579+
).stdout.strip()
580+
581+
return [field.split(": ", maxsplit=1) for field in fields.splitlines()]
582+
583+
584+
def is_file_production(filepath):
585+
"""Returns True iff accesses to metric fields in the given file should cause the metric be considered 'used in production code'. Excludes, for example, files in which the metrics are defined, where accesses happen as part of copy constructors, etc."""
586+
path = filepath.lower()
587+
return (
588+
"/test/" in path
589+
or "/tests/" in path
590+
or path.endswith("_test.rs")
591+
or "test_" in path
592+
or "tests.rs" in path
593+
or ("metrics.rs" in path and "vmm" in path)
594+
)
595+
596+
597+
KNOWN_FALSE_POSITIVES = [
598+
"min_us",
599+
"max_us",
600+
"sum_us",
601+
"process_startup_time_us",
602+
"process_startup_time_cpu_us",
603+
]
604+
605+
606+
def is_metric_used(field, field_type):
607+
"""Returns True iff the given metric has a production use in the firecracker codebase"""
608+
if field in KNOWN_FALSE_POSITIVES:
609+
return True
610+
611+
if field_type in ("SharedIncMetric", "SharedStoreMetric"):
612+
pattern = rf"{field}\s*\.\s*store|{field}\s*\.\s*inc|{field}\s*\.\s*add|{field}\s*\.\s*fetch|METRICS.*{field}"
613+
elif field_type == "LatencyAggregateMetrics":
614+
pattern = rf"{field}\s*\.\s*record_latency_metrics"
615+
else:
616+
raise RuntimeError(f"Unknown metric type: {field_type}")
617+
618+
result = utils.run_cmd(f'grep -RPzo "{pattern}" ../src')
619+
620+
for line in result.stdout.strip().split("\0"):
621+
if not line:
622+
continue
623+
if not is_file_production(line.split(":", maxsplit=1)[0]):
624+
return True
625+
return False

tests/integration_tests/functional/test_pause_resume.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def verify_net_emulation_paused(metrics):
1313
"""Verify net emulation is paused based on provided metrics."""
1414
net_metrics = metrics["net"]
1515
assert net_metrics["rx_queue_event_count"] == 0
16-
assert net_metrics["rx_partial_writes"] == 0
1716
assert net_metrics["rx_tap_event_count"] == 0
1817
assert net_metrics["rx_bytes_count"] == 0
1918
assert net_metrics["rx_packets_count"] == 0

tests/integration_tests/security/test_vulnerabilities.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ def download_spectre_meltdown_checker(tmp_path_factory):
110110
global_props.buildkite_pr,
111111
reason="Test depends solely on factors external to GitHub repository",
112112
)
113-
# Temporary suppression for Ubuntu 6.14 kernel
114-
@pytest.mark.skipif(
115-
"Ubuntu" in global_props.os and global_props.host_linux_version == "6.14",
116-
reason="Ubuntu does not enable CONFIG_MITIGATION_GDS on 6.14 kernel",
117-
)
118113
def test_spectre_meltdown_checker_on_host(spectre_meltdown_checker):
119114
"""Test with the spectre / meltdown checker on host."""
120115
report = spectre_meltdown_checker.get_report_for_host()
@@ -126,11 +121,6 @@ def test_spectre_meltdown_checker_on_host(spectre_meltdown_checker):
126121
global_props.buildkite_pr,
127122
reason="Test depends solely on factors external to GitHub repository",
128123
)
129-
# Temporary suppression for Ubuntu 6.14 kernel
130-
@pytest.mark.skipif(
131-
"Ubuntu" in global_props.os and global_props.host_linux_version == "6.14",
132-
reason="Ubuntu does not enable CONFIG_MITIGATION_GDS on 6.14 kernel",
133-
)
134124
def test_vulnerabilities_on_host():
135125
"""Test vulnerability files on host."""
136126
res = utils.run_cmd(f"grep -r Vulnerable {VULN_DIR}")

tests/integration_tests/style/test_rust.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
"""Tests ensuring codebase style compliance for Rust."""
4+
from collections import defaultdict
45

56
from framework import utils
7+
from host_tools.fcmetrics import extract_fields, find_metrics_files, is_metric_used
68

79

810
def test_rust_order():
@@ -24,3 +26,34 @@ def test_rust_style():
2426

2527
# rustfmt prepends `"Diff in"` to the reported output.
2628
assert "Diff in" not in stdout
29+
30+
31+
def test_unused_metrics():
32+
"""Tests that all metrics defined in Firecracker's metrics.rs files actually have code
33+
paths that increment them."""
34+
metrics_files = find_metrics_files()
35+
unused = defaultdict(list)
36+
37+
assert metrics_files
38+
39+
for file_path in metrics_files:
40+
fields = extract_fields(file_path)
41+
if not fields:
42+
continue
43+
44+
for field, ty in fields:
45+
if not is_metric_used(field, ty):
46+
unused[file_path].append((field, ty))
47+
48+
# Grouped output
49+
for file_path, fields in unused.items():
50+
print(f"📄 Defined in: {file_path}")
51+
print("Possibly Unused: \n")
52+
for field, field_type in fields:
53+
print(f" ❌ {field} ({field_type})")
54+
55+
print()
56+
57+
assert (
58+
not unused
59+
), "Unused metrics founds, see stdout. Please either hook them up, or remove them"

0 commit comments

Comments
 (0)