Skip to content

Commit

Permalink
fix: app is a reserved label, so use client instead (#1065)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw authored Jun 11, 2024
1 parent 3bda843 commit 1231bb8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
11 changes: 7 additions & 4 deletions src/eth/rpc/rpc_http_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ where

/// Extracts the client application name from the `app` query parameter.
fn parse_client_app(uri: &Uri) -> RpcClientApp {
// parse query params
let Some(query_params_str) = uri.query() else { return RpcClientApp::Unknown };

let query_params: HashMap<String, String> = match serde_urlencoded::from_str(query_params_str) {
Ok(url) => url,
Err(e) => {
Expand All @@ -51,8 +51,11 @@ fn parse_client_app(uri: &Uri) -> RpcClientApp {
}
};

match query_params.get("app") {
Some(app) => RpcClientApp::Identified(app.to_owned()),
None => RpcClientApp::Unknown,
// try to extract client from query params
for param in ["app", "client"] {
if let Some(client_app) = query_params.get(param) {
return RpcClientApp::Identified(client_app.to_owned());
}
}
RpcClientApp::Unknown
}
18 changes: 9 additions & 9 deletions src/eth/rpc/rpc_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'a> RpcServiceT<'a> for RpcMiddleware {

fn call(&self, request: jsonrpsee::types::Request<'a>) -> Self::Future {
// extract request data
let app = extract_client_app(&request);
let client = extract_client_app(&request);
let method = request.method_name();
let function = match method {
"eth_call" | "eth_estimateGas" => extract_call_function(request.params()),
Expand All @@ -59,7 +59,7 @@ impl<'a> RpcServiceT<'a> for RpcMiddleware {

// trace request
tracing::info!(
%app,
%client,
id = %request.id,
%method,
function = %function.clone().unwrap_or_default(),
Expand All @@ -71,12 +71,12 @@ impl<'a> RpcServiceT<'a> for RpcMiddleware {
#[cfg(feature = "metrics")]
{
let active = ACTIVE_REQUESTS.fetch_add(1, Ordering::Relaxed) + 1;
metrics::set_rpc_requests_active(active, &app, method, function.clone());
metrics::inc_rpc_requests_started(&app, method, function.clone());
metrics::set_rpc_requests_active(active, &client, method, function.clone());
metrics::inc_rpc_requests_started(&client, method, function.clone());
}

RpcResponse {
app,
client,
id: request.id.to_string(),
method: method.to_string(),
function,
Expand All @@ -96,7 +96,7 @@ pub struct RpcResponse<'a> {
#[pin]
future_response: ResponseFuture<BoxFuture<'a, MethodResponse>>,

app: RpcClientApp,
client: RpcClientApp,
id: String,
method: String,
function: Option<SoliditySignature>,
Expand All @@ -119,7 +119,7 @@ impl<'a> Future for RpcResponse<'a> {
let response_success = response.is_success();
let response_result = response.as_result();
tracing::info!(
app = %proj.app,
client = %proj.client,
id = %proj.id,
method = %proj.method,
function = %proj.function.clone().unwrap_or_default(),
Expand All @@ -133,7 +133,7 @@ impl<'a> Future for RpcResponse<'a> {
#[cfg(feature = "metrics")]
{
let active = ACTIVE_REQUESTS.fetch_sub(1, Ordering::Relaxed) - 1;
metrics::set_rpc_requests_active(active, &*proj.app, proj.method.clone(), proj.function.clone());
metrics::set_rpc_requests_active(active, &*proj.client, proj.method.clone(), proj.function.clone());

let mut rpc_result = "error";
if response_success {
Expand All @@ -142,7 +142,7 @@ impl<'a> Future for RpcResponse<'a> {

metrics::inc_rpc_requests_finished(
elapsed,
&*proj.app,
&*proj.client,
proj.method.clone(),
proj.function.clone(),
rpc_result,
Expand Down
8 changes: 4 additions & 4 deletions src/infra/metrics/metrics_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ metrics! {
group: json_rpc,

"Number of JSON-RPC requests active right now."
gauge rpc_requests_active{app, method, function} [],
gauge rpc_requests_active{client, method, function} [],

"Number of JSON-RPC requests that started."
counter rpc_requests_started{app, method, function} [],
counter rpc_requests_started{client, method, function} [],

"Number of JSON-RPC requests that finished."
histogram_duration rpc_requests_finished{app, method, function, result, success} [],
histogram_duration rpc_requests_finished{client, method, function, result, success} [],

"Number of JSON-RPC subscriptions active right now."
gauge rpc_subscriptions_active{subscription} []
gauge rpc_subscriptions_active{subscription} []
}

// Storage reads.
Expand Down

0 comments on commit 1231bb8

Please sign in to comment.