Skip to content

Commit

Permalink
small fix for TOTAL_REQUESTS_COUNTER metrics (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobayurii committed Jun 7, 2024
1 parent b8f87be commit 39bbc3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
9 changes: 6 additions & 3 deletions rpc-server/src/modules/blocks/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub async fn block(
// Proxy if the optimistic updating is not working
let block_view = data
.near_rpc_client
.call(block_request, Some("optimistic"))
.call(block_request, Some("block"))
.await?;
return Ok(near_jsonrpc::primitives::types::blocks::RpcBlockResponse { block_view });
}
Expand Down Expand Up @@ -80,7 +80,7 @@ pub async fn changes_in_block_by_type(
// Proxy if the optimistic updating is not working
return Ok(data
.near_rpc_client
.call(changes_in_block_request, Some("optimistic"))
.call(changes_in_block_request, Some("EXPERIMENTAL_changes"))
.await?);
}
};
Expand Down Expand Up @@ -109,7 +109,10 @@ pub async fn changes_in_block(
// Proxy if the optimistic updating is not working
return Ok(data
.near_rpc_client
.call(changes_in_block_request, Some("optimistic"))
.call(
changes_in_block_request,
Some("EXPERIMENTAL_changes_in_block"),
)
.await?);
}
};
Expand Down
38 changes: 20 additions & 18 deletions rpc-server/src/modules/queries/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ pub async fn query(
) -> Result<near_jsonrpc::primitives::types::query::RpcQueryResponse, RPCError> {
let query_request = near_jsonrpc::primitives::types::query::RpcQueryRequest::parse(params)?;

// When the data check fails, we want to emit the log message and increment the
// corresponding metric. Despite the metrics have "proxies" in their names, we
// are not proxying the requests anymore and respond with the error to the client.
// Since we already have the dashboard using these metric names, we don't want to
// change them and reuse them for the observability of the shadow data consistency checks.
let method_name = match &query_request.request {
near_primitives::views::QueryRequest::ViewAccount { .. } => "query_view_account",
near_primitives::views::QueryRequest::ViewCode { .. } => "query_view_code",
near_primitives::views::QueryRequest::ViewAccessKey { .. } => "query_view_access_key",
near_primitives::views::QueryRequest::ViewState { .. } => "query_view_state",
near_primitives::views::QueryRequest::CallFunction { .. } => "query_call_function",
near_primitives::views::QueryRequest::ViewAccessKeyList { .. } => {
"query_view_access_key_list"
}
};

if let near_primitives::types::BlockReference::Finality(
near_primitives::types::Finality::None,
) = &query_request.block_reference
Expand All @@ -29,15 +45,15 @@ pub async fn query(
// Proxy if the optimistic updating is not working
Ok(data
.near_rpc_client
.call(query_request, Some("optimistic"))
.call(query_request, Some(method_name))
.await?)
} else {
// query_call with optimistic block
query_call(&data, query_request, true).await
query_call(&data, query_request, method_name, true).await
};
};

query_call(&data, query_request, false).await
query_call(&data, query_request, method_name, false).await
}

/// fetch query result from read-rpc
Expand All @@ -46,24 +62,10 @@ pub async fn query(
async fn query_call(
data: &Data<ServerContext>,
mut query_request: near_jsonrpc::primitives::types::query::RpcQueryRequest,
method_name: &str,
is_optimistic: bool,
) -> Result<near_jsonrpc::primitives::types::query::RpcQueryResponse, RPCError> {
tracing::debug!("`query` call. Params: {:?}", query_request,);
// When the data check fails, we want to emit the log message and increment the
// corresponding metric. Despite the metrics have "proxies" in their names, we
// are not proxying the requests anymore and respond with the error to the client.
// Since we already have the dashboard using these metric names, we don't want to
// change them and reuse them for the observability of the shadow data consistency checks.
let method_name = match &query_request.request {
near_primitives::views::QueryRequest::ViewAccount { .. } => "query_view_account",
near_primitives::views::QueryRequest::ViewCode { .. } => "query_view_code",
near_primitives::views::QueryRequest::ViewAccessKey { .. } => "query_view_access_key",
near_primitives::views::QueryRequest::ViewState { .. } => "query_view_state",
near_primitives::views::QueryRequest::CallFunction { .. } => "query_call_function",
near_primitives::views::QueryRequest::ViewAccessKeyList { .. } => {
"query_view_access_key_list"
}
};
let block = fetch_block_from_cache_or_get(data, &query_request.block_reference, method_name)
.await
.map_err(near_jsonrpc::primitives::errors::RpcError::from)?;
Expand Down

0 comments on commit 39bbc3c

Please sign in to comment.