Skip to content

Commit

Permalink
nit: Log time for every request
Browse files Browse the repository at this point in the history
  • Loading branch information
kinkard committed Oct 15, 2024
1 parent 2a7aef7 commit 9e90ce5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, env, num::NonZero};
use std::{collections::HashMap, env, num::NonZero, time::Instant};

use axum::{
extract::{Path, State},
Expand Down Expand Up @@ -129,14 +129,19 @@ async fn forward_request(
State(state): State<AppState>,
Json(request): Json<RequestToForward>,
) -> Result<Json<Value>, (StatusCode, String)> {
info!("Requested /{}", request.endpoint);
let begin = Instant::now();
let response = state
.http_client
.post(format!("{}/{}", state.valhalla_url, request.endpoint))
.json(&request.payload)
.send()
.await
.map_err(|err| (StatusCode::BAD_REQUEST, err.to_string()))?;
info!(
"Fetched /{} in {}ms",
request.endpoint,
begin.elapsed().as_millis()
);

response
.json()
Expand All @@ -163,6 +168,7 @@ async fn traffic(
));
};

let begin = Instant::now();
let edges = [GraphLevel::Highway, GraphLevel::Arterial, GraphLevel::Local]
.into_iter()
.map(|level| reader.tiles_in_bbox(bbox.0, bbox.1, level))
Expand All @@ -182,6 +188,11 @@ async fn traffic(
})
.map(|edge| (edge.shape, 10 - (edge.jam_factor * 10.0).round() as i32))
.collect::<HashMap<_, _>>();
info!(
"Fetched {} traffic edges in {}ms",
edges.len(),
begin.elapsed().as_millis()
);
Ok(Json(serde_json::to_value(edges).unwrap()))
}

Expand Down

0 comments on commit 9e90ce5

Please sign in to comment.