From be3012cabc373cfb4351635782850397e1db68af Mon Sep 17 00:00:00 2001 From: Brian Martin Date: Tue, 3 Sep 2019 11:15:30 -0700 Subject: [PATCH] config: use atomics for sampler enabled Use atomics for the sampler enabled status. Fixes `softnet` to be disabled by default to match other samplers --- CHANGELOG.md | 1 + Cargo.lock | 1 + Cargo.toml | 1 + src/config/cpu.rs | 3 ++- src/config/disk.rs | 3 ++- src/config/ebpf.rs | 3 ++- src/config/general.rs | 3 ++- src/config/network.rs | 13 +++++++------ src/config/perf.rs | 12 +++++++----- src/config/softnet.rs | 12 +++++++----- 10 files changed, 32 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 068bcc14..7d27dbe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Fixed - Allows memcache sampler to reconnect to the cache instance which helps to make the sampler more resilient to transient errors +- Softnet sampler now disabled by default to be consistent with other samplers # [1.0.1] - 2019-08-22 ## Fixed diff --git a/Cargo.lock b/Cargo.lock index 55e84978..e6ec082e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -652,6 +652,7 @@ dependencies = [ name = "rezolus" version = "1.0.2-alpha.0" dependencies = [ + "atomics 0.2.0 (git+https://github.com/twitter/rpc-perf)", "bcc 0.0.10 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 04d0f582..e2057a08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ publish = false edition = '2018' [dependencies] +atomics = { git = "https://github.com/twitter/rpc-perf", branch = "master" } bcc = { version = "0.0.10", optional = true } clap = "2.33.0" failure = "0.1.5" diff --git a/src/config/cpu.rs b/src/config/cpu.rs index 0bac62c2..c376746f 100644 --- a/src/config/cpu.rs +++ b/src/config/cpu.rs @@ -4,7 +4,8 @@ use crate::config::*; use crate::samplers::cpu::CpuStatistic; -use core::sync::atomic::{AtomicBool, Ordering}; + +use atomics::*; #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] diff --git a/src/config/disk.rs b/src/config/disk.rs index 5bac9f6f..dedc0838 100644 --- a/src/config/disk.rs +++ b/src/config/disk.rs @@ -3,7 +3,8 @@ // http://www.apache.org/licenses/LICENSE-2.0 use crate::config::*; -use core::sync::atomic::{AtomicBool, Ordering}; + +use atomics::*; #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] diff --git a/src/config/ebpf.rs b/src/config/ebpf.rs index fbf694df..6a51a919 100644 --- a/src/config/ebpf.rs +++ b/src/config/ebpf.rs @@ -3,7 +3,8 @@ // http://www.apache.org/licenses/LICENSE-2.0 use crate::config::*; -use core::sync::atomic::{AtomicBool, Ordering}; + +use atomics::*; #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] diff --git a/src/config/general.rs b/src/config/general.rs index c0366476..29425bf9 100644 --- a/src/config/general.rs +++ b/src/config/general.rs @@ -3,7 +3,8 @@ // http://www.apache.org/licenses/LICENSE-2.0 use crate::config::*; -use core::sync::atomic::{AtomicUsize, Ordering}; + +use atomics::*; #[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] diff --git a/src/config/network.rs b/src/config/network.rs index a48e3ed6..57554c42 100644 --- a/src/config/network.rs +++ b/src/config/network.rs @@ -3,15 +3,16 @@ // http://www.apache.org/licenses/LICENSE-2.0 use crate::config::*; - use crate::samplers::network::interface::InterfaceStatistic; use crate::samplers::network::protocol::ProtocolStatistic; -#[derive(Clone, Debug, Deserialize)] +use atomics::*; + +#[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] pub struct Network { #[serde(default = "default_enabled")] - enabled: bool, + enabled: AtomicBool, #[serde(default = "default_interface_statistics")] interface_statistics: Vec, #[serde(default = "default_protocol_statistics")] @@ -28,8 +29,8 @@ impl Default for Network { } } -fn default_enabled() -> bool { - false +fn default_enabled() -> AtomicBool { + AtomicBool::new(false) } fn default_interface_statistics() -> Vec { @@ -65,7 +66,7 @@ fn default_protocol_statistics() -> Vec { impl Network { pub fn enabled(&self) -> bool { - self.enabled + self.enabled.load(Ordering::Relaxed) } pub fn interface_statistics(&self) -> &[InterfaceStatistic] { diff --git a/src/config/perf.rs b/src/config/perf.rs index f394c7b4..f4ac9cd8 100644 --- a/src/config/perf.rs +++ b/src/config/perf.rs @@ -5,11 +5,13 @@ use crate::config::*; use crate::samplers::perf::PerfStatistic; -#[derive(Clone, Debug, Deserialize)] +use atomics::*; + +#[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] pub struct Perf { #[serde(default = "default_enabled")] - enabled: bool, + enabled: AtomicBool, #[serde(default = "default_statistics")] statistics: Vec, } @@ -23,8 +25,8 @@ impl Default for Perf { } } -fn default_enabled() -> bool { - false +fn default_enabled() -> AtomicBool { + AtomicBool::new(false) } fn default_statistics() -> Vec { @@ -54,7 +56,7 @@ fn default_statistics() -> Vec { impl Perf { pub fn enabled(&self) -> bool { - self.enabled + self.enabled.load(Ordering::Relaxed) } pub fn statistics(&self) -> &[PerfStatistic] { diff --git a/src/config/softnet.rs b/src/config/softnet.rs index 48dd7c16..4bd2afe3 100644 --- a/src/config/softnet.rs +++ b/src/config/softnet.rs @@ -4,11 +4,13 @@ use crate::config::*; -#[derive(Clone, Debug, Deserialize)] +use atomics::*; + +#[derive(Debug, Deserialize)] #[serde(deny_unknown_fields)] pub struct Softnet { #[serde(default = "default_enabled")] - enabled: bool, + enabled: AtomicBool, } impl Default for Softnet { @@ -19,12 +21,12 @@ impl Default for Softnet { } } -fn default_enabled() -> bool { - true +fn default_enabled() -> AtomicBool { + AtomicBool::new(false) } impl Softnet { pub fn enabled(&self) -> bool { - self.enabled + self.enabled.load(Ordering::Relaxed) } }