Skip to content

Commit

Permalink
Filter call errors (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci authored Apr 11, 2024
1 parent 6ea24ab commit 354f917
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
17 changes: 9 additions & 8 deletions src/extensions/client/health.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum Event {
SlowResponse,
RequestTimeout,
ConnectionSuccessful,
ConnectionFailed,
ServerError,
StaleChain,
}

Expand All @@ -24,7 +24,7 @@ impl Event {
match self {
Event::ResponseOk => current.saturating_add(2),
Event::SlowResponse => current.saturating_sub(5),
Event::RequestTimeout | Event::ConnectionFailed | Event::StaleChain => 0,
Event::RequestTimeout | Event::ServerError | Event::StaleChain => 0,
Event::ConnectionSuccessful => MAX_SCORE / 5 * 4, // 80% of max score
},
MAX_SCORE,
Expand Down Expand Up @@ -77,17 +77,18 @@ impl Health {
}

pub fn on_error(&self, err: &jsonrpsee::core::Error) {
tracing::warn!("Endpoint {:?} responded with error: {err:?}", self.url);
match err {
jsonrpsee::core::Error::Call(_) => {
// NOT SERVER ERROR
}
jsonrpsee::core::Error::RequestTimeout => {
tracing::warn!("Endpoint {:?} request timeout", self.url);
self.update(Event::RequestTimeout);
}
jsonrpsee::core::Error::Transport(_)
| jsonrpsee::core::Error::RestartNeeded(_)
| jsonrpsee::core::Error::MaxSlotsExceeded => {
self.update(Event::ConnectionFailed);
_ => {
tracing::warn!("Endpoint {:?} responded with error: {err:?}", self.url);
self.update(Event::ServerError);
}
_ => {}
};
}

Expand Down
14 changes: 11 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use futures::FutureExt;
use jsonrpsee::{
core::JsonValue,
server::{RpcModule, ServerHandle},
types::error::INTERNAL_ERROR_CODE,
types::ErrorObjectOwned,
};
use opentelemetry::trace::FutureExt as _;
Expand Down Expand Up @@ -96,16 +97,23 @@ pub async fn build(config: Config) -> anyhow::Result<SubwayServerHandle> {

let result = result_rx
.await
.map_err(|_| errors::map_error(jsonrpsee::core::Error::RequestTimeout))?;
.map_err(|_| errors::map_error(jsonrpsee::core::Error::RequestTimeout));

match result.as_ref() {
Ok(_) => tracer.span_ok(),
Ok(Ok(_)) => tracer.span_ok(),
Ok(Err(err)) => {
if err.code() == INTERNAL_ERROR_CODE {
tracer.span_error(err)
} else {
tracer.span_ok()
}
}
Err(err) => {
tracer.span_error(err);
}
};

result
result?
}
.with_context(tracer.context(method_name))
})?;
Expand Down

0 comments on commit 354f917

Please sign in to comment.