Skip to content

Commit e842466

Browse files
committed
chore(config): drop the Default impl from the histogram component config
A component config struct should take its values from the typed configuration model, not restate defaults. Remove impl Default for HistogramConfiguration and build the representative configuration explicitly in the tests that need one.
1 parent 9d1afae commit e842466

2 files changed

Lines changed: 26 additions & 32 deletions

File tree

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,25 +150,6 @@ impl HistogramConfiguration {
150150
}
151151
}
152152

153-
impl Default for HistogramConfiguration {
154-
fn default() -> Self {
155-
Self {
156-
statistics: vec![
157-
HistogramStatistic::Maximum,
158-
HistogramStatistic::Median,
159-
HistogramStatistic::Average,
160-
HistogramStatistic::Count,
161-
HistogramStatistic::Percentile {
162-
q: 0.95,
163-
suffix: "95percentile".into(),
164-
},
165-
],
166-
copy_to_distribution: false,
167-
copy_to_distribution_prefix: "".into(),
168-
}
169-
}
170-
}
171-
172153
#[cfg(test)]
173154
mod tests {
174155
use super::*;

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,25 @@ mod tests {
871871
use super::config::HistogramStatistic;
872872
use super::*;
873873

874+
/// The histogram statistics the Datadog Agent computes by default, for aggregation-state tests
875+
/// that need a representative configuration.
876+
fn default_hist_config() -> HistogramConfiguration {
877+
HistogramConfiguration::from_statistics(
878+
&[
879+
HistogramStatistic::Maximum,
880+
HistogramStatistic::Median,
881+
HistogramStatistic::Average,
882+
HistogramStatistic::Count,
883+
HistogramStatistic::Percentile {
884+
q: 0.95,
885+
suffix: "95percentile".into(),
886+
},
887+
],
888+
false,
889+
String::new(),
890+
)
891+
}
892+
874893
const BUCKET_WIDTH_SECS: NonZeroU64 = NonZeroU64::new(10).expect("not zero");
875894
const BUCKET_WIDTH: Duration = Duration::from_secs(BUCKET_WIDTH_SECS.get());
876895
const COUNTER_EXPIRE_SECS: u64 = 20;
@@ -1070,7 +1089,7 @@ mod tests {
10701089
BUCKET_WIDTH_SECS,
10711090
2,
10721091
COUNTER_EXPIRE,
1073-
HistogramConfiguration::default(),
1092+
default_hist_config(),
10741093
Telemetry::noop(),
10751094
);
10761095

@@ -1120,7 +1139,7 @@ mod tests {
11201139
BUCKET_WIDTH_SECS,
11211140
2,
11221141
COUNTER_EXPIRE,
1123-
HistogramConfiguration::default(),
1142+
default_hist_config(),
11241143
Telemetry::noop(),
11251144
);
11261145

@@ -1175,7 +1194,7 @@ mod tests {
11751194
BUCKET_WIDTH_SECS,
11761195
10,
11771196
COUNTER_EXPIRE,
1178-
HistogramConfiguration::default(),
1197+
default_hist_config(),
11791198
Telemetry::noop(),
11801199
);
11811200

@@ -1224,7 +1243,7 @@ mod tests {
12241243
BUCKET_WIDTH_SECS,
12251244
10,
12261245
COUNTER_EXPIRE,
1227-
HistogramConfiguration::default(),
1246+
default_hist_config(),
12281247
Telemetry::noop(),
12291248
);
12301249

@@ -1338,7 +1357,7 @@ mod tests {
13381357
BUCKET_WIDTH_SECS,
13391358
10,
13401359
COUNTER_EXPIRE,
1341-
HistogramConfiguration::default(),
1360+
default_hist_config(),
13421361
Telemetry::noop(),
13431362
);
13441363

@@ -1405,7 +1424,7 @@ mod tests {
14051424
BUCKET_WIDTH_SECS,
14061425
10,
14071426
COUNTER_EXPIRE,
1408-
HistogramConfiguration::default(),
1427+
default_hist_config(),
14091428
Telemetry::noop(),
14101429
);
14111430

@@ -1462,13 +1481,7 @@ mod tests {
14621481
let builder = MetricsBuilder::default();
14631482
let telemetry = Telemetry::new(&builder);
14641483

1465-
let mut state = AggregationState::new(
1466-
BUCKET_WIDTH_SECS,
1467-
2,
1468-
COUNTER_EXPIRE,
1469-
HistogramConfiguration::default(),
1470-
telemetry,
1471-
);
1484+
let mut state = AggregationState::new(BUCKET_WIDTH_SECS, 2, COUNTER_EXPIRE, default_hist_config(), telemetry);
14721485

14731486
// Make sure our telemetry is registered at default values.
14741487
assert_eq!(recorder.gauge("aggregate_active_contexts"), Some(0.0));

0 commit comments

Comments
 (0)