Skip to content

Commit 1a4450d

Browse files
author
Memfault Inc.
committed
memfaultd 1.21.1 (Build 3112275)
1 parent 997daf7 commit 1a4450d

File tree

10 files changed

+84
-34
lines changed

10 files changed

+84
-34
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to
77
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## [1.21.1] - 2025-05-21
10+
11+
This is a patch release that fixes an overflow issue with the recently added
12+
`diskstats/<disk>/bytes_written` metric.
13+
14+
### Fixed
15+
16+
- Fixed an issue with the `diskstats/<disk>/bytes_written` metric where it would
17+
overflow when the diskstats counter wrapped. This would cause very large
18+
readings to be sent. Whenever there is a potential overflow now the reading
19+
will be discarded.
20+
921
## [1.21.0] - 2025-05-08
1022

1123
This release adds several new metrics for tracking flash wear, as well as a new
@@ -1360,3 +1372,5 @@ package][nginx-pid-report] for a discussion on the topic.
13601372
https://github.com/memfault/memfault-linux-sdk/releases/tag/1.20.0-kirkstone
13611373
[1.21.0]:
13621374
https://github.com/memfault/memfault-linux-sdk/releases/tag/1.21.0-kirkstone
1375+
[1.21.1]:
1376+
https://github.com/memfault/memfault-linux-sdk/releases/tag/1.21.1-kirkstone

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

VERSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
BUILD ID: 3088884
2-
GIT COMMIT: 1b9b610366
3-
VERSION: 1.21.0
1+
BUILD ID: 3112275
2+
GIT COMMIT: eaa113a284
3+
VERSION: 1.21.1

memfault-ssf/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "memfault-ssf"
3-
version = "1.21.0"
3+
version = "1.21.1"
44
edition = "2021"
55
description = "Supporting crate for the Memfault memfaultd embedded Linux agent"
66
homepage = "https://github.com/memfault/memfaultd"

memfault-ssf/VERSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
BUILD ID: 3088884
2-
GIT COMMIT: 1b9b610366
3-
VERSION: 1.21.0
1+
BUILD ID: 3112275
2+
GIT COMMIT: eaa113a284
3+
VERSION: 1.21.1

memfaultc-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "memfaultc-sys"
3-
version = "1.21.0"
3+
version = "1.21.1"
44
edition = "2021"
55
autobins = false
66
description = "Supporting crate for the Memfault memfaultd embedded Linux agent"

memfaultc-sys/VERSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
BUILD ID: 3088884
2-
GIT COMMIT: 1b9b610366
3-
VERSION: 1.21.0
1+
BUILD ID: 3112275
2+
GIT COMMIT: eaa113a284
3+
VERSION: 1.21.1

memfaultd/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "memfaultd"
3-
version = "1.21.0"
3+
version = "1.21.1"
44
edition = "2021"
55
autobins = false
66
rust-version = "1.72"
@@ -28,8 +28,8 @@ name= "mfw"
2828
path= "src/bin/mfw.rs"
2929

3030
[dependencies]
31-
memfaultc-sys = { path= "../memfaultc-sys", version = "1.21.0" }
32-
ssf = { package = "memfault-ssf", path= "../memfault-ssf", version = "1.21.0" }
31+
memfaultc-sys = { path= "../memfaultc-sys", version = "1.21.1" }
32+
ssf = { package = "memfault-ssf", path= "../memfault-ssf", version = "1.21.1" }
3333
argh = "0.1.10"
3434
cfg-if = "1.0.0"
3535
chrono = { version = "0.4.23", features = ["serde"]}

memfaultd/VERSION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
BUILD ID: 3088884
2-
GIT COMMIT: 1b9b610366
3-
VERSION: 1.21.0
1+
BUILD ID: 3112275
2+
GIT COMMIT: eaa113a284
3+
VERSION: 1.21.1

memfaultd/src/metrics/system_metrics/disk.rs

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
};
1010

1111
use eyre::{eyre, Result};
12-
use log::{debug, error};
12+
use log::{debug, error, warn};
1313

1414
use crate::{
1515
metrics::{KeyedMetricReading, MetricStringKey},
@@ -70,19 +70,10 @@ where
7070
.map(|sectors_written| *sectors_written * SECTOR_SIZE);
7171

7272
if let Some(bytes_written) = bytes_written {
73-
if let Some(prev_bytes_written) = prev_bytes_reading.replace(bytes_written) {
74-
let bytes_metric_key = MetricStringKey::from_str(&format!(
75-
"{}/{}/bytes_written",
76-
DISK_METRIC_NAMESPACE, disk_name
77-
))
78-
.map_err(|e| eyre!("Invalid metric key: {}", e))?;
79-
let bytes_since_last_reading = bytes_written - prev_bytes_written;
80-
let bytes_metric = KeyedMetricReading::new_counter(
81-
bytes_metric_key,
82-
bytes_since_last_reading as f64,
83-
);
84-
85-
metrics.push(bytes_metric);
73+
match Self::calc_bytes_written_reading(bytes_written, prev_bytes_reading, disk_name) {
74+
Ok(Some(reading)) => metrics.push(reading),
75+
Ok(None) => {}
76+
Err(e) => debug!("Failed to calculate bytes_written: {}", e),
8677
}
8778
}
8879

@@ -155,6 +146,36 @@ where
155146

156147
Ok(metrics)
157148
}
149+
150+
fn calc_bytes_written_reading(
151+
cur_bytes_written: u64,
152+
prev_bytes_written: &mut Option<u64>,
153+
disk_name: &str,
154+
) -> Result<Option<KeyedMetricReading>> {
155+
if let Some(prev_bytes_written) = prev_bytes_written.replace(cur_bytes_written) {
156+
match cur_bytes_written.checked_sub(prev_bytes_written) {
157+
Some(_) => {
158+
let bytes_metric_key = MetricStringKey::from_str(&format!(
159+
"{}/{}/bytes_written",
160+
DISK_METRIC_NAMESPACE, disk_name
161+
))
162+
.map_err(|e| eyre!("Invalid metric key: {}", e))?;
163+
let bytes_since_last_reading = cur_bytes_written - prev_bytes_written;
164+
let bytes_metric = KeyedMetricReading::new_counter(
165+
bytes_metric_key,
166+
bytes_since_last_reading as f64,
167+
);
168+
Ok(Some(bytes_metric))
169+
}
170+
None => {
171+
warn!("bytes_written metric overflow, discarding reading");
172+
Ok(None)
173+
}
174+
}
175+
} else {
176+
Ok(None)
177+
}
178+
}
158179
}
159180

160181
impl<M> SystemMetricFamilyCollector for DiskMetricsCollector<M>
@@ -323,6 +344,21 @@ mod test {
323344
});
324345
}
325346

347+
#[test]
348+
fn test_calc_bytes_reading_overflow() {
349+
let mut prev_bytes_reading = Some(1000);
350+
let cur_bytes_written = 500;
351+
352+
let result = DiskMetricsCollector::<FakeMmc>::calc_bytes_written_reading(
353+
cur_bytes_written,
354+
&mut prev_bytes_reading,
355+
"mmcblk0",
356+
)
357+
.unwrap();
358+
359+
assert!(result.is_none());
360+
}
361+
326362
#[rstest]
327363
#[case(DiskstatsMetricsConfig::Auto)]
328364
#[case(DiskstatsMetricsConfig::Devices(

0 commit comments

Comments
 (0)