From 8739ed4419f4d38dfd62116d8fbc40177637e31d Mon Sep 17 00:00:00 2001 From: Nils Andreas Svee Date: Tue, 14 Apr 2026 02:14:35 +0700 Subject: [PATCH] fix(metrics): use AtomicU32 for drop counter to support MIPS targets Also bumps version to 0.4.1. --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 4 ++-- src/metrics.rs | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ba4afc..7b70f93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -392,7 +392,7 @@ dependencies = [ [[package]] name = "sqm-autorate-rust" -version = "0.4.0" +version = "0.4.1" dependencies = [ "anyhow", "fastrand", diff --git a/Cargo.toml b/Cargo.toml index fdc6714..d17e2a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sqm-autorate-rust" -version = "0.4.0" +version = "0.4.1" edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index 3d31d04..92fa1f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,7 @@ use ::log::{debug, info}; use std::collections::HashMap; use std::net::IpAddr; use std::str::FromStr; -use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; +use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; use std::sync::mpsc::{channel, sync_channel, RecvTimeoutError}; use std::sync::{Arc, Mutex, RwLock}; use std::thread::sleep; @@ -95,7 +95,7 @@ fn main() -> anyhow::Result<()> { let (error_tx, error_rx) = channel::(); let (reselect_tx, reselect_rx) = channel(); - let dropped = Arc::new(AtomicU64::new(0)); + let dropped = Arc::new(AtomicU32::new(0)); let (metrics_tx, metrics_thread_handle) = if config.observability_enabled { let (tx, rx) = sync_channel(1000); diff --git a/src/metrics.rs b/src/metrics.rs index a615e55..18ecd4b 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -5,7 +5,7 @@ use log::{error, info, warn}; use rustix::time::ClockId; use std::fmt::Write; use std::net::{IpAddr, TcpStream, UdpSocket}; -use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::mpsc::{Receiver, RecvTimeoutError, SyncSender}; use std::sync::Arc; use std::time::Duration; @@ -116,18 +116,18 @@ pub enum Metric { tags: &'static [(&'static str, &'static str)], }, Dropped { - count: u64, + count: u32, }, } #[derive(Clone)] pub struct MetricsSender { tx: Option>, - dropped: Arc, + dropped: Arc, } impl MetricsSender { - pub fn new(tx: SyncSender<(Metric, u64)>, dropped: Arc) -> Self { + pub fn new(tx: SyncSender<(Metric, u64)>, dropped: Arc) -> Self { Self { tx: Some(tx), dropped, @@ -137,7 +137,7 @@ impl MetricsSender { pub fn disabled() -> Self { Self { tx: None, - dropped: Arc::new(AtomicU64::new(0)), + dropped: Arc::new(AtomicU32::new(0)), } } @@ -153,7 +153,7 @@ impl MetricsSender { pub struct Metrics { pub config: Config, - pub metrics_dropped: Arc, + pub metrics_dropped: Arc, pub metrics_rx: Receiver<(Metric, u64)>, }