Skip to content

Commit 19505d6

Browse files
committed
chore(antithesis): Expand cheap-win antithesis SDK assertions
This commit is a child to #1928. It's meant to demonstrate how the new saluki-antithesis works in a bulk change and also, incidentally, flag things to Antithesis that demonstrate bugs we've previously found. See for instance PR #1923.
1 parent f4420b3 commit 19505d6

7 files changed

Lines changed: 46 additions & 6 deletions

File tree

lib/ddsketch/src/agent/sketch.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ impl DDSketch {
198198
self.max = v;
199199
}
200200

201+
saluki_antithesis::always_le!(self.min, self.max, "DDSketch min does not exceed max after insert");
202+
201203
self.count += n;
202204
// It's possible that self.sum will be INF after this multiplication, even though we've demonstrated that `v`
203205
// is finite. The Datadog Agent sketch sum behaves the same way, so we do not assert that self.sum is itself

lib/saluki-components/src/encoders/datadog/metrics/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,9 @@ fn encode_series_v2_metric(
977977
.map(|interval| value / interval.as_secs_f64())
978978
.unwrap_or(value);
979979

980-
if !emittable(value) {
980+
let dropped = !emittable(value);
981+
saluki_antithesis::sometimes!(dropped, "non-finite series point dropped before wire");
982+
if dropped {
981983
continue;
982984
}
983985

@@ -1016,7 +1018,9 @@ fn encode_series_v1_metric(
10161018
.map(|interval| value / interval.as_secs_f64())
10171019
.unwrap_or(value);
10181020

1019-
if !emittable(value) {
1021+
let dropped = !emittable(value);
1022+
saluki_antithesis::sometimes!(dropped, "non-finite series point dropped before wire");
1023+
if dropped {
10201024
continue;
10211025
}
10221026

lib/saluki-components/src/sources/dogstatsd/mod.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,18 @@ impl DogStatsDConfiguration {
670670
fn effective_context_string_interner_bytes(&self) -> ByteSize {
671671
match self.context_string_interner_size_bytes {
672672
Some(explicit_bytes) => explicit_bytes,
673-
None => ByteSize::b(self.context_string_interner_entry_count * INTERNER_BASELINE_BYTES_PER_ENTRY),
673+
None => {
674+
saluki_antithesis::always_le!(
675+
self.context_string_interner_entry_count,
676+
u64::MAX / INTERNER_BASELINE_BYTES_PER_ENTRY,
677+
"dogstatsd interner byte-size multiply does not overflow",
678+
{ "entry_count": self.context_string_interner_entry_count }
679+
);
680+
ByteSize::b(
681+
self.context_string_interner_entry_count
682+
.saturating_mul(INTERNER_BASELINE_BYTES_PER_ENTRY),
683+
)
684+
}
674685
}
675686
}
676687

@@ -1133,6 +1144,12 @@ async fn process_io_buffer_pool_shrinker(
11331144
fn build_io_buffer_pool(
11341145
min_buffers: usize, max_buffers: usize, buffer_size: usize,
11351146
) -> (ElasticObjectPool<BytesBuffer>, impl Future<Output = ()> + Send) {
1147+
saluki_antithesis::always_le!(
1148+
buffer_size,
1149+
usize::MAX - 4,
1150+
"dogstatsd buffer size add does not overflow",
1151+
{ "buffer_size": buffer_size }
1152+
);
11361153
let adjusted_buffer_size = get_adjusted_buffer_size(buffer_size);
11371154
ElasticObjectPool::with_builder("dsd_packet_bufs", min_buffers, max_buffers, move || {
11381155
FixedSizeVec::with_capacity(adjusted_buffer_size)

lib/saluki-components/src/transforms/aggregate/config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ impl HistogramStatistic {
6464
HistogramStatistic::Maximum => summary.max().unwrap_or(0.0),
6565
HistogramStatistic::Average => summary.avg(),
6666
HistogramStatistic::Median => summary.median().unwrap_or(0.0),
67-
HistogramStatistic::Percentile { q, .. } => summary.quantile(*q).unwrap_or(0.0),
67+
HistogramStatistic::Percentile { q, .. } => {
68+
saluki_antithesis::always_ge!(*q, 0.0, "histogram percentile quantile at or above zero");
69+
saluki_antithesis::always_le!(*q, 1.0, "histogram percentile quantile at or below one");
70+
summary.quantile(*q).unwrap_or(0.0)
71+
}
6872
}
6973
}
7074
}

lib/saluki-components/src/transforms/aggregate/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,13 @@ impl AggregationState {
700700
// This is useful for sparsely-updated counters.
701701
let should_expire_if_empty = match &am.values {
702702
MetricValues::Counter(..) => {
703-
counter_expire_secs != 0 && am.last_seen + counter_expire_secs < current_time
703+
saluki_antithesis::always_le!(
704+
am.last_seen,
705+
u64::MAX - counter_expire_secs,
706+
"aggregate counter expiry add does not overflow",
707+
{ "last_seen": am.last_seen, "counter_expire_secs": counter_expire_secs }
708+
);
709+
counter_expire_secs != 0 && am.last_seen.saturating_add(counter_expire_secs) < current_time
704710
}
705711
_ => true,
706712
};
@@ -711,7 +717,7 @@ impl AggregationState {
711717
// This is also safe to do even when there are real values in those buckets since adding zero to anything is
712718
// a no-op from the perspective of what we end up flushing, and it doesn't mess with the "last seen" time.
713719
if let MetricValues::Counter(..) = &mut am.values {
714-
let expires_at = am.last_seen + counter_expire_secs;
720+
let expires_at = am.last_seen.saturating_add(counter_expire_secs);
715721
for (zv_bucket_start, zero_value) in &zero_value_buckets {
716722
if expires_at > *zv_bucket_start {
717723
am.values.merge(zero_value.clone());

lib/saluki-core/src/topology/interconnect/dispatcher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ where
102102
let item_count = item.item_count();
103103

104104
// Send the item to all senders except the last one by cloning the item.
105+
saluki_antithesis::always_gt!(self.senders.len(), 0, "dispatcher fanout has at least one sender");
105106
let cloned_sends = self.senders.len() - 1;
106107
for sender in &self.senders[0..cloned_sends] {
107108
sender

lib/saluki-io/src/buf/vec.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl Buf for BytesBuffer {
9393

9494
fn advance(&mut self, cnt: usize) {
9595
let data = self.data_mut();
96+
saluki_antithesis::always_le!(data.read_idx + cnt, data.data.len(), "buffer advance within bounds");
9697
assert!(data.read_idx + cnt <= data.data.len());
9798
data.read_idx += cnt;
9899
}
@@ -193,6 +194,11 @@ impl Buf for FrozenBytesBuffer {
193194
}
194195

195196
fn advance(&mut self, cnt: usize) {
197+
saluki_antithesis::always_le!(
198+
self.data.read_idx + cnt,
199+
self.data.data.len(),
200+
"buffer advance within bounds"
201+
);
196202
assert!(self.data.read_idx + cnt <= self.data.data.len());
197203
self.data.read_idx += cnt;
198204
}

0 commit comments

Comments
 (0)