From 39bbc3c27a81cc2da1d62e1f447b1724ce6f5969 Mon Sep 17 00:00:00 2001 From: Yurii Koba Date: Fri, 7 Jun 2024 18:56:24 +0300 Subject: [PATCH] small fix for TOTAL_REQUESTS_COUNTER metrics (#276) --- rpc-server/src/modules/blocks/methods.rs | 9 ++++-- rpc-server/src/modules/queries/methods.rs | 38 ++++++++++++----------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/rpc-server/src/modules/blocks/methods.rs b/rpc-server/src/modules/blocks/methods.rs index bf09a05a..4972e8ac 100644 --- a/rpc-server/src/modules/blocks/methods.rs +++ b/rpc-server/src/modules/blocks/methods.rs @@ -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 }); } @@ -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?); } }; @@ -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?); } }; diff --git a/rpc-server/src/modules/queries/methods.rs b/rpc-server/src/modules/queries/methods.rs index 484bb784..a8832190 100644 --- a/rpc-server/src/modules/queries/methods.rs +++ b/rpc-server/src/modules/queries/methods.rs @@ -21,6 +21,22 @@ pub async fn query( ) -> Result { 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 @@ -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 @@ -46,24 +62,10 @@ pub async fn query( async fn query_call( data: &Data, mut query_request: near_jsonrpc::primitives::types::query::RpcQueryRequest, + method_name: &str, is_optimistic: bool, ) -> Result { 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)?;