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

feat(rpc): record call metrics per method #5338

Merged
merged 7 commits into from
Nov 7, 2023

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented Nov 7, 2023

Currently, we don't have RPC metrics per method, but it can be extremely useful for debugging of long-running requests. This PR fixes it, and also changes the layout of RPC server metrics to make use of labels.

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could precompute all labels for known methods during build and put them into a map

let metrics = RpcServerMetrics::default();

so we need to find a way to pass the TransportRpcModuleConfig
here

async fn build(

@@ -2148,7 +2148,17 @@ impl<TX: DbTxMut + DbTx> BlockWriter for DatabaseProvider<TX> {

let start = Instant::now();
self.tx.put::<tables::Transactions>(next_tx_num, transaction.into())?;
transactions_elapsed += start.elapsed();
let elapsed = start.elapsed();
if elapsed > Duration::from_millis(100) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be too short and could potentially spam output?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, increased to 1s

crates/rpc/rpc-builder/src/metrics.rs Outdated Show resolved Hide resolved
Comment on lines 15 to 19
/// Connection metrics per transport type
connection_metrics: ConnectionMetrics,

/// Call metrics per RPC method
call_metrics: HashMap<&'static str, RpcServerCallMetrics>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we Arc the internals?
because atleast for the ipc server this is cloned.

and I believe this is also the case for HTTP and ws

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connection_metrics should be fine, as it already has all metrics as Arc under the hood. Agree for call_metrics to avoid the cloning of hashmap, fixed.

@shekhirin shekhirin force-pushed the alexey/rpc-metrics-per-method branch from 9703b58 to f546950 Compare November 7, 2023 14:55
@shekhirin shekhirin added C-enhancement New feature or request A-rpc Related to the RPC implementation A-observability Related to tracing, metrics, logs and other observability tools labels Nov 7, 2023
@shekhirin shekhirin marked this pull request as ready for review November 7, 2023 14:56
@shekhirin shekhirin requested a review from mattsse November 7, 2023 15:54
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pedantic nit re Arc wrapper type :)

@@ -1452,15 +1470,20 @@ impl RpcServerConfig {
/// This consumes the builder and returns a server.
///
/// Note: The server ist not started and does nothing unless polled, See also [RpcServer::start]
pub async fn build(mut self) -> Result<RpcServer, RpcError> {
pub async fn build(mut self, modules: &TransportRpcModules) -> Result<RpcServer, RpcError> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit awkward now, but I'm okay with this because this should only be called when an instance of TransportRpcModules exists.

Comment on lines 15 to 18
/// Connection metrics per transport type
connection_metrics: ConnectionMetrics,
/// Call metrics per RPC method
call_metrics: Arc<HashMap<&'static str, RpcServerCallMetrics>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we group both in an inner type that we arc in a single field here? so a clone here is a single Arc::clone?

@mattsse mattsse added this pull request to the merge queue Nov 7, 2023
Merged via the queue into main with commit 47669c5 Nov 7, 2023
@mattsse mattsse deleted the alexey/rpc-metrics-per-method branch November 7, 2023 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-observability Related to tracing, metrics, logs and other observability tools A-rpc Related to the RPC implementation C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants