Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small fix for TOTAL_REQUESTS_COUNTER metrics #276

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading