Skip to content

Commit 6fbe14b

Browse files
lucaspimentelclaude
andcommitted
refactor(stats): take stats_url as a StatsFlusher::new parameter
StatsFlusher derived its intake URL internally via trace_stats_url(&config.site), which hardcodes https://trace.agent.{site}/api/v0.2/stats. Lift the URL to the caller: main.rs now computes trace_stats_url at the call site and passes it in. Mirrors how TraceFlusher already works (URL comes from outside via SendData's embedded Endpoint) and unblocks redirecting StatsFlusher to alternate endpoints such as in-process test harnesses. Retry-loop debug logs now report endpoint.url so they match the URL actually contacted. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9f49e35 commit 6fbe14b

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

bottlecap/src/bin/bottlecap/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ fn start_trace_agent(
11311131
stats_aggregator.clone(),
11321132
Arc::clone(config),
11331133
trace_http_client.clone(),
1134+
libdd_trace_utils::config_utils::trace_stats_url(&config.site),
11341135
));
11351136

11361137
let stats_processor = Arc::new(stats_processor::ServerlessStatsProcessor {});

bottlecap/src/traces/stats_flusher.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ use crate::traces::stats_aggregator::StatsAggregator;
1414
use dogstatsd::api_key::ApiKeyFactory;
1515
use libdd_common::Endpoint;
1616
use libdd_trace_protobuf::pb;
17-
use libdd_trace_utils::{config_utils::trace_stats_url, stats_utils};
17+
use libdd_trace_utils::stats_utils;
1818
use tracing::{debug, error};
1919

2020
pub struct StatsFlusher {
2121
aggregator: Arc<Mutex<StatsAggregator>>,
2222
config: Arc<config::Config>,
2323
api_key_factory: Arc<ApiKeyFactory>,
24+
stats_url: String,
2425
endpoint: OnceCell<Endpoint>,
2526
http_client: HttpClient,
2627
}
@@ -32,11 +33,13 @@ impl StatsFlusher {
3233
aggregator: Arc<Mutex<StatsAggregator>>,
3334
config: Arc<config::Config>,
3435
http_client: HttpClient,
36+
stats_url: String,
3537
) -> Self {
3638
StatsFlusher {
3739
aggregator,
3840
config,
3941
api_key_factory,
42+
stats_url,
4043
endpoint: OnceCell::new(),
4144
http_client,
4245
}
@@ -64,9 +67,8 @@ impl StatsFlusher {
6467
.endpoint
6568
.get_or_init({
6669
move || async move {
67-
let stats_url = trace_stats_url(&self.config.site);
6870
Endpoint {
69-
url: hyper::Uri::from_str(&stats_url)
71+
url: hyper::Uri::from_str(&self.stats_url)
7072
.expect("can't make URI from stats url, exiting"),
7173
api_key: Some(api_key_clone.into()),
7274
timeout_ms: self.config.flush_timeout * S_TO_MS,
@@ -92,8 +94,6 @@ impl StatsFlusher {
9294
}
9395
};
9496

95-
let stats_url = trace_stats_url(&self.config.site);
96-
9797
for attempt in 1..=FLUSH_RETRY_COUNT {
9898
let start = std::time::Instant::now();
9999
let resp = stats_utils::send_stats_payload_with_client(
@@ -108,14 +108,16 @@ impl StatsFlusher {
108108
match resp {
109109
Ok(()) => {
110110
debug!(
111-
"STATS | Successfully flushed stats to {stats_url} in {} ms (attempt {attempt}/{FLUSH_RETRY_COUNT})",
111+
"STATS | Successfully flushed stats to {} in {} ms (attempt {attempt}/{FLUSH_RETRY_COUNT})",
112+
endpoint.url,
112113
elapsed.as_millis()
113114
);
114115
return None;
115116
}
116117
Err(e) => {
117118
debug!(
118-
"STATS | Failed to send stats to {stats_url} in {} ms (attempt {attempt}/{FLUSH_RETRY_COUNT}): {e:?}",
119+
"STATS | Failed to send stats to {} in {} ms (attempt {attempt}/{FLUSH_RETRY_COUNT}): {e:?}",
120+
endpoint.url,
119121
elapsed.as_millis()
120122
);
121123
}

0 commit comments

Comments
 (0)