Skip to content

Commit

Permalink
cleaner error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hcaumeil committed Aug 3, 2023
1 parent c0d2e55 commit 295c2b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
25 changes: 12 additions & 13 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,26 +448,25 @@ impl L7ListenerHandler for HttpListener {
*/
let host = unsafe { from_utf8_unchecked(hostname) };

let res = self
let route = self
.fronts
.lookup(host.as_bytes(), uri.as_bytes(), method)
.ok_or(FrontendFromRequestError::NoClusterFound);
.ok_or_else(|| {
incr!("http.failed_backend_matching");
FrontendFromRequestError::NoClusterFound
})?;

let now = Instant::now();

if let Ok(r) = res.as_ref() {
if let Route::ClusterId(c) = r {
time!(
"frontend_matching_time",
&c,
(now - start).whole_milliseconds()
);
}
} else {
incr!("http.failed_backend_matching")
if let Route::ClusterId(cluster) = &route {
time!(
"frontend_matching_time",
cluster,
(now - start).whole_milliseconds()
);
}

res
Ok(route)
}
}

Expand Down
25 changes: 12 additions & 13 deletions lib/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,26 +585,25 @@ impl L7ListenerHandler for HttpsListener {
// chars in there
let host = unsafe { from_utf8_unchecked(hostname) };

let res = self
let route = self
.fronts
.lookup(host.as_bytes(), uri.as_bytes(), method)
.ok_or(FrontendFromRequestError::NoClusterFound);
.ok_or_else(|| {
incr!("http.failed_backend_matching");
FrontendFromRequestError::NoClusterFound
})?;

let now = Instant::now();

if let Ok(r) = res.as_ref() {
if let Route::ClusterId(c) = r {
time!(
"frontend_matching_time",
&c,
(now - start).whole_milliseconds()
);
}
} else {
incr!("http.failed_backend_matching")
if let Route::ClusterId(cluster) = &route {
time!(
"frontend_matching_time",
cluster,
(now - start).whole_milliseconds()
);
}

res
Ok(route)
}
}

Expand Down

0 comments on commit 295c2b6

Please sign in to comment.