rpc server: add prometheus label `is_rate_limited` (#3504)
After some discussion with @kogeler after the we added the rate-limit middleware it may slow down the rpc call timings metrics significantly because it works as follows: 1. The rate limit guard is checked when the call comes and if a slot is available -> process the call 2. If no free spot is available then the call will be sleeping `jitter_delay + min_time_rate_guard` then woken up and checked at most ten times 3. If no spot is available after 10 iterations -> the call is rejected (this may take tens of seconds) Thus, this PR adds a label "is_rate_limited" to filter those out on the metrics "substrate_rpc_calls_time" and "substrate_rpc_calls_finished". I had to merge two middleware layers Metrics and RateLimit to avoid shared state in a hacky way. --------- Co-authored-by:James Wilson <james@jsdw.me>
parent
0eda0b3f
Showing
- Cargo.lock 0 additions, 1 deletionCargo.lock
- prdoc/pr_3504.prdoc 13 additions, 0 deletionsprdoc/pr_3504.prdoc
- substrate/client/rpc-servers/Cargo.toml 0 additions, 1 deletionsubstrate/client/rpc-servers/Cargo.toml
- substrate/client/rpc-servers/src/lib.rs 17 additions, 8 deletionssubstrate/client/rpc-servers/src/lib.rs
- substrate/client/rpc-servers/src/middleware/metrics.rs 71 additions, 125 deletionssubstrate/client/rpc-servers/src/middleware/metrics.rs
- substrate/client/rpc-servers/src/middleware/mod.rs 125 additions, 4 deletionssubstrate/client/rpc-servers/src/middleware/mod.rs
- substrate/client/rpc-servers/src/middleware/rate_limit.rs 13 additions, 73 deletionssubstrate/client/rpc-servers/src/middleware/rate_limit.rs
Please register or sign in to comment