Skip to content

Commit

Permalink
Make url configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
magdyksaleh committed Mar 7, 2024
1 parent d3e6055 commit 703a06e
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions router/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,20 +785,30 @@ async fn metrics(prom_handle: Extension<PrometheusHandle>) -> String {
}

async fn request_logger(mut rx: mpsc::Receiver<(i64, String, String)>) {
// TODO: configure whether this is enabled and make it non-blocking if it fails
// TODO: make url configurable
// log the function is getting called
let url = std::env::var("REQUEST_LOGGER_URL").ok();
if Some(&url) == None {
tracing::warn!("REQUEST_LOGGER_URL not set, request logging is disabled");
return;
}

let url_string = url.unwrap();
tracing::info!("Request logging enabled, sending logs to {url_string}");

let retry_policy = ExponentialBackoff::builder().build_with_max_retries(3);
let client = ClientBuilder::new(reqwest::Client::new())
.with(RetryTransientMiddleware::new_with_policy(retry_policy))
.build();
while let Some((tokens, api_token, model_id)) = rx.recv().await {
// Make a request out to localhost:8899 with the tokens, api_token, and model_id
let res = client
.post("http://localhost:8899")
.post(&url_string)
.json(&json!({"tokens": tokens, "api_token": api_token, "model_id": model_id}))
.send()
.await;

if let Err(e) = res {
tracing::error!("Failed to log request: {e}");
}
}
}

Expand Down

0 comments on commit 703a06e

Please sign in to comment.