Skip to content

Commit f4420b3

Browse files
committed
chore(antithesis): Migrate Antithesis SDK to saluki-antithesis
We've found the bare SDK use to be untidy. This commit attempts to tidy up the use of the Antithesis SDK by hiding behind a macro which * takes care of the cfg flagging on/off * does not expose the need for serde_json * remains no-op
1 parent da59d73 commit f4420b3

30 files changed

Lines changed: 440 additions & 180 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ members = [
1818
"lib/protos/datadog",
1919
"lib/protos/otlp",
2020
"lib/resource-accounting",
21+
"lib/saluki-antithesis",
2122
"lib/saluki-api",
2223
"lib/saluki-app",
2324
"lib/saluki-common",
@@ -54,6 +55,7 @@ ddsketch = { path = "lib/ddsketch" }
5455
resource-accounting = { path = "lib/resource-accounting" }
5556
process-memory = { path = "lib/process-memory" }
5657
prometheus-exposition = { path = "lib/prometheus-exposition" }
58+
saluki-antithesis = { path = "lib/saluki-antithesis" }
5759
saluki-api = { path = "lib/saluki-api" }
5860
saluki-app = { path = "lib/saluki-app" }
5961
saluki-common = { path = "lib/saluki-common" }

bin/agent-data-plane/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ workspace = true
1111
[features]
1212
default = []
1313
fips = ["saluki-app/tls-fips", "saluki-components/fips"]
14-
antithesis = ["dep:antithesis_sdk", "antithesis_sdk/full", "dep:antithesis-instrumentation", "saluki-components/antithesis"]
14+
antithesis = ["saluki-antithesis/antithesis", "dep:antithesis-instrumentation"]
1515

1616
[dependencies]
1717
antithesis-instrumentation = { workspace = true, optional = true }
18-
antithesis_sdk = { workspace = true, optional = true }
1918
argh = { workspace = true, features = ["help"] }
2019
async-trait = { workspace = true }
2120
bytesize = { workspace = true }
@@ -36,6 +35,7 @@ ottl = { workspace = true }
3635
prost = { workspace = true }
3736
prost-types = { workspace = true }
3837
resource-accounting = { workspace = true }
38+
saluki-antithesis = { workspace = true }
3939
saluki-api = { workspace = true }
4040
saluki-app = { workspace = true }
4141
saluki-common = { workspace = true }

bin/agent-data-plane/src/main.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ async fn main() -> Result<(), GenericError> {
8888

8989
// Bootstrap-integration probe: proves the Antithesis SDK is linked, cataloging works, and the
9090
// instrumentation path is wired.
91-
#[cfg(feature = "antithesis")]
92-
antithesis_sdk::assert_reachable!("agent-data-plane completed bootstrap", &serde_json::json!({}));
91+
saluki_antithesis::reachable!("agent-data-plane completed bootstrap");
9392

9493
// Run the given subcommand. The bootstrap supervisor is forwarded by value; only the long-lived `run`
9594
// subcommand actually drives it (it is added as a child of the internal supervisor inside
@@ -118,7 +117,7 @@ async fn main() -> Result<(), GenericError> {
118117
/// ideally before any panics are possible.
119118
#[cfg(feature = "antithesis")]
120119
fn initialize_antithesis() {
121-
antithesis_sdk::antithesis_init();
120+
saluki_antithesis::init();
122121

123122
let default_hook = std::panic::take_hook();
124123
std::panic::set_hook(Box::new(move |info| {
@@ -129,9 +128,9 @@ fn initialize_antithesis() {
129128
.map(|s| (*s).to_string())
130129
.or_else(|| payload.downcast_ref::<String>().cloned())
131130
.unwrap_or_else(|| "<non-string panic payload>".to_string());
132-
antithesis_sdk::assert_unreachable!(
131+
saluki_antithesis::unreachable!(
133132
"agent-data-plane panicked",
134-
&serde_json::json!({ "message": message, "location": location })
133+
{ "message": message, "location": location }
135134
);
136135
default_hook(info);
137136
}));
@@ -151,11 +150,10 @@ fn load_bootstrap_config(bootstrap_config_path: &Path) -> Result<ConfigurationLo
151150
.error_context("Environment variable prefix should not be empty.")
152151
});
153152
// A graceful config rejection exits 1 rather than crashing; classify that against a clean boot.
154-
#[cfg(feature = "antithesis")]
155-
antithesis_sdk::assert_always_or_unreachable!(
153+
saluki_antithesis::always_or_unreachable!(
156154
loaded.is_ok(),
157155
"agent-data-plane boots under sampled config",
158-
&serde_json::json!({ "phase": "config_load", "error": loaded.as_ref().err().map(|e| format!("{e:?}")) })
156+
{ "phase": "config_load", "error": loaded.as_ref().err().map(|e| format!("{e:?}")) }
159157
);
160158
loaded
161159
}
@@ -196,11 +194,10 @@ async fn run_inner(
196194
Err(e) => {
197195
error!("{:?}", e);
198196
// Same boot property as the config-load gate, distinguished by `phase` in the details.
199-
#[cfg(feature = "antithesis")]
200-
antithesis_sdk::assert_always_or_unreachable!(
197+
saluki_antithesis::always_or_unreachable!(
201198
false,
202199
"agent-data-plane boots under sampled config",
203-
&serde_json::json!({ "phase": "run_setup", "error": format!("{e:?}") })
200+
{ "phase": "run_setup", "error": format!("{e:?}") }
204201
);
205202
Some(1)
206203
}

lib/ddsketch/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ repository = { workspace = true }
99
workspace = true
1010

1111
[features]
12-
antithesis = ["dep:antithesis_sdk", "antithesis_sdk/full"]
1312
ddsketch_extended = []
1413
serde = ["dep:serde", "smallvec/serde"]
1514

1615
[dependencies]
17-
antithesis_sdk = { workspace = true, optional = true }
1816
datadog-protos = { workspace = true }
1917
float-cmp = { workspace = true, features = ["ratio"] }
2018
ordered-float = { workspace = true }
2119
protobuf = { workspace = true }
20+
saluki-antithesis = { workspace = true }
2221
serde = { workspace = true, optional = true }
2322
smallvec = { workspace = true, features = ["union"] }
2423

lib/ddsketch/src/agent/sketch.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ impl DDSketch {
188188
fn adjust_basic_stats(&mut self, v: f64, n: u64) {
189189
// Every insert path funnels through here, so this is where we guard that the incoming sample is finite. If
190190
// this is not true something has gone wrong with the DogStatsD codec.
191-
#[cfg(feature = "antithesis")]
192-
antithesis_sdk::assert_always!(v.is_finite(), "DDSketch sample is finite at insert");
191+
saluki_antithesis::always!(v.is_finite(), "DDSketch sample is finite at insert");
193192

194193
if v < self.min {
195194
self.min = v;
@@ -722,15 +721,8 @@ fn trim_left(bins: &mut SmallVec<[Bin; 4]>, bin_limit: u16) {
722721

723722
// This is the one place every mutating method routes through, so asserting here guards the bin-count bound for
724723
// all of them.
725-
#[cfg(feature = "antithesis")]
726-
{
727-
antithesis_sdk::assert_reachable!("DDSketch bin collapse reached");
728-
antithesis_sdk::assert_always_less_than_or_equal_to!(
729-
bins.len(),
730-
bin_limit,
731-
"DDSketch bin count within bin_limit"
732-
);
733-
}
724+
saluki_antithesis::reachable!("DDSketch bin collapse reached");
725+
saluki_antithesis::always_le!(bins.len(), bin_limit, "DDSketch bin count within bin_limit");
734726
}
735727

736728
#[allow(clippy::cast_possible_truncation)]

lib/saluki-antithesis/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "saluki-antithesis"
3+
version = "0.1.0"
4+
edition = { workspace = true }
5+
license = { workspace = true }
6+
repository = { workspace = true }
7+
8+
[lints]
9+
workspace = true
10+
11+
[features]
12+
antithesis = ["dep:antithesis_sdk", "antithesis_sdk/full", "dep:serde_json"]
13+
14+
[dependencies]
15+
antithesis_sdk = { workspace = true, optional = true }
16+
serde_json = { workspace = true, optional = true }

0 commit comments

Comments
 (0)