Skip to content

Commit a43f81d

Browse files
authored
fix: append ingest path correctly (#100)
1 parent 986f498 commit a43f81d

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/session.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{
1313
pyroscope::{PyroscopeConfig, Compression},
1414
utils::{get_time_range, merge_tags_with_app_name},
1515
Result,
16+
PyroscopeError,
1617
encode::{folded, pprof},
1718
};
1819
use crate::backend::EncodedReport;
@@ -194,38 +195,29 @@ impl Session {
194195

195196

196197
fn upload(&self, report: EncodedReport) -> Result<()> {
197-
log::info!(
198-
target: LOG_TAG,
199-
"Sending Session: {} - {}",
200-
self.from,
201-
self.until
202-
);
198+
log::info!(target: LOG_TAG, "Sending Session: {} - {}", self.from, self.until);
203199

204200
if report.data.is_empty() {
205201
return Ok(());
206202
}
207203

208-
// Create a new client
204+
//todo do not create a new client for every request
209205
let client = reqwest::blocking::Client::new();
210206

211-
// Clone URL
212-
let url = self.config.url.clone();
213-
214-
// Merge application name with Tags
215207
let application_name = merge_tags_with_app_name(
216208
self.config.application_name.clone(),
217209
report.metadata.tags.clone().into_iter().collect(),
218210
)?;
219211

220-
// Parse URL
221-
let joined = Url::parse(&url)?.join("ingest")?;
212+
let mut url = Url::parse(&self.config.url)?;
213+
url.path_segments_mut()
214+
.map_err(|_e| PyroscopeError::new("url construction failure - cannot_be_a_base"))?
215+
.push("ingest");
222216

223-
// Create Reqwest builder
224217
let mut req_builder = client
225-
.post(joined.as_str())
218+
.post(url.as_str())
226219
.header("Content-Type", report.content_type.as_str());
227220

228-
// Set authentication token
229221
if let Some(auth_token) = &self.config.auth_token {
230222
req_builder = req_builder.bearer_auth(auth_token);
231223
}
@@ -239,8 +231,7 @@ impl Session {
239231
req_builder = req_builder.header(k, v);
240232
};
241233

242-
// Send the request
243-
req_builder
234+
let response = req_builder
244235
.query(&[
245236
("name", application_name.as_str()),
246237
("from", &format!("{}", self.from)),
@@ -252,6 +243,10 @@ impl Session {
252243
.body(report.data)
253244
.timeout(Duration::from_secs(10))
254245
.send()?;
246+
247+
if !response.status().is_success() {
248+
log::error!(target: LOG_TAG, "Sending Session failed {}", response.status().as_u16());
249+
}
255250
Ok(())
256251
}
257252
}

0 commit comments

Comments
 (0)