Skip to content

Commit a7b0ce9

Browse files
committed
Fix rebase conflicts
1 parent ead3f33 commit a7b0ce9

File tree

2 files changed

+41
-42
lines changed

2 files changed

+41
-42
lines changed

bottlecap/src/logs/flusher.rs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::config;
22
use crate::http::get_client;
33
use crate::logs::aggregator::Aggregator;
44
use crate::FLUSH_RETRY_COUNT;
5-
use futures::future::join_all;
65
use dogstatsd::api_key::ApiKeyFactory;
6+
use futures::future::join_all;
77
use reqwest::header::HeaderMap;
88
use std::error::Error;
99
use std::time::Instant;
@@ -95,7 +95,6 @@ impl Flusher {
9595

9696
async fn create_request(&self, data: Vec<u8>) -> reqwest::RequestBuilder {
9797
let url = format!("{}/api/v2/logs", self.endpoint);
98-
let body = self.compress(data);
9998
let headers = self.get_headers().await;
10099
self.client
101100
.post(&url)
@@ -146,6 +145,35 @@ impl Flusher {
146145
}
147146
}
148147
}
148+
149+
async fn get_headers(&self) -> &HeaderMap {
150+
self.headers
151+
.get_or_init(move || async move {
152+
let api_key = self.api_key_factory.get_api_key().await;
153+
let mut headers = HeaderMap::new();
154+
headers.insert(
155+
"DD-API-KEY",
156+
api_key.parse().expect("failed to parse header"),
157+
);
158+
headers.insert(
159+
"DD-PROTOCOL",
160+
"agent-json".parse().expect("failed to parse header"),
161+
);
162+
headers.insert(
163+
"Content-Type",
164+
"application/json".parse().expect("failed to parse header"),
165+
);
166+
167+
if self.config.logs_config_use_compression {
168+
headers.insert(
169+
"Content-Encoding",
170+
"zstd".parse().expect("failed to parse header"),
171+
);
172+
}
173+
headers
174+
})
175+
.await
176+
}
149177
}
150178

151179
#[allow(clippy::module_name_repetitions)]
@@ -157,15 +185,15 @@ pub struct LogsFlusher {
157185

158186
impl LogsFlusher {
159187
pub fn new(
160-
api_key: String,
188+
api_key_factory: Arc<ApiKeyFactory>,
161189
aggregator: Arc<Mutex<Aggregator>>,
162190
config: Arc<config::Config>,
163191
) -> Self {
164192
let mut flushers = Vec::new();
165193

166194
// Create primary flusher
167195
flushers.push(Flusher::new(
168-
api_key.clone(),
196+
Arc::clone(&api_key_factory),
169197
config.logs_config_logs_dd_url.clone(),
170198
aggregator.clone(),
171199
config.clone(),
@@ -175,7 +203,7 @@ impl LogsFlusher {
175203
for endpoint in &config.logs_config_additional_endpoints {
176204
let endpoint_url = format!("https://{}:{}", endpoint.host, endpoint.port);
177205
flushers.push(Flusher::new(
178-
endpoint.api_key.clone(),
206+
Arc::clone(&api_key_factory),
179207
endpoint_url,
180208
aggregator.clone(),
181209
config.clone(),
@@ -252,33 +280,4 @@ impl LogsFlusher {
252280
encoder.write_all(data)?;
253281
encoder.finish().map_err(|e| Box::new(e) as Box<dyn Error>)
254282
}
255-
256-
async fn get_headers(&self) -> &HeaderMap {
257-
self.headers
258-
.get_or_init(move || async move {
259-
let api_key = self.api_key_factory.get_api_key().await;
260-
let mut headers = HeaderMap::new();
261-
headers.insert(
262-
"DD-API-KEY",
263-
api_key.parse().expect("failed to parse header"),
264-
);
265-
headers.insert(
266-
"DD-PROTOCOL",
267-
"agent-json".parse().expect("failed to parse header"),
268-
);
269-
headers.insert(
270-
"Content-Type",
271-
"application/json".parse().expect("failed to parse header"),
272-
);
273-
274-
if self.config.logs_config_use_compression {
275-
headers.insert(
276-
"Content-Encoding",
277-
"zstd".parse().expect("failed to parse header"),
278-
);
279-
}
280-
headers
281-
})
282-
.await
283-
}
284283
}

bottlecap/src/traces/trace_agent.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub struct ProxyState {
7676
pub config: Arc<config::Config>,
7777
pub tags_provider: Arc<provider::Provider>,
7878
pub http_client: reqwest::Client,
79-
pub api_key: String,
79+
pub api_key_factory: Arc<ApiKeyFactory>,
8080
}
8181

8282
pub struct TraceAgent {
@@ -197,7 +197,7 @@ impl TraceAgent {
197197
config: Arc::clone(&self.config),
198198
tags_provider: Arc::clone(&self.tags_provider),
199199
http_client: self.http_client.clone(),
200-
api_key: self.api_key.clone(),
200+
api_key_factory: Arc::clone(&self.api_key_factory),
201201
};
202202

203203
let trace_router = Router::new()
@@ -289,7 +289,7 @@ impl TraceAgent {
289289
Self::handle_proxy(
290290
state.config,
291291
state.http_client,
292-
state.api_key,
292+
state.api_key_factory,
293293
state.tags_provider,
294294
request,
295295
"trace.agent",
@@ -303,7 +303,7 @@ impl TraceAgent {
303303
Self::handle_proxy(
304304
state.config,
305305
state.http_client,
306-
state.api_key,
306+
state.api_key_factory,
307307
state.tags_provider,
308308
request,
309309
"intake.profile",
@@ -320,7 +320,7 @@ impl TraceAgent {
320320
Self::handle_proxy(
321321
state.config,
322322
state.http_client,
323-
state.api_key,
323+
state.api_key_factory,
324324
state.tags_provider,
325325
request,
326326
"api",
@@ -337,7 +337,7 @@ impl TraceAgent {
337337
Self::handle_proxy(
338338
state.config,
339339
state.http_client,
340-
state.api_key,
340+
state.api_key_factory,
341341
state.tags_provider,
342342
request,
343343
"api",
@@ -351,7 +351,7 @@ impl TraceAgent {
351351
Self::handle_proxy(
352352
state.config,
353353
state.http_client,
354-
state.api_key,
354+
state.api_key_factory,
355355
state.tags_provider,
356356
request,
357357
"llmobs-intake",
@@ -365,7 +365,7 @@ impl TraceAgent {
365365
Self::handle_proxy(
366366
state.config,
367367
state.http_client,
368-
state.api_key,
368+
state.api_key_factory,
369369
state.tags_provider,
370370
request,
371371
"http-intake.logs",

0 commit comments

Comments
 (0)