RPC_process: Add metrics for external RPC calls
What
Why
When a node is started with --external-rpc-addr option, the RPC calls that are made through the external RPC port are not taken into account by the RPC metrics. We can currently see that in the following way:
- start sandbox node
$ ./src/bin_node/octez-sandboxed-node.sh 1 --connections 0 --rpc-addr localhost:18731 --metrics-addr localhost:12345 --external-rpc-addr localhost:18732
$ eval `./src/bin_client/octez-init-sandboxed-client.sh 1`
$ octez-activate-alpha
- check metrics for
baking_rights(example)
$ curl -s 'localhost:12345/metrics' | grep baking_rights
<nothing>
- do an RPC call (which is not external)
$ curl -s 'localhost:18731/chains/main/blocks/head/helpers/baking_rights'
- check metrics for
baking_rights
$ curl -s 'localhost:12345/metrics' | grep baking_rights
octez_rpc_calls_sum{endpoint="/chains/<chain_id>/blocks/<block_id>/helpers/baking_rights", method="GET"} 0.000847
octez_rpc_calls_count{endpoint="/chains/<chain_id>/blocks/<block_id>/helpers/baking_rights", method="GET"} 1.000000
- do an external RPC call
$ curl -s 'localhost:18732/chains/main/blocks/head/helpers/baking_rights'
- check metrics for
baking_rights
$ curl -s 'localhost:12345/metrics' | grep baking_rights
octez_rpc_calls_sum{endpoint="/chains/<chain_id>/blocks/<block_id>/helpers/baking_rights", method="GET"} 0.000847
octez_rpc_calls_count{endpoint="/chains/<chain_id>/blocks/<block_id>/helpers/baking_rights", method="GET"} 1.000000
(still just 1 call)
As we can see, the second curl was not taken into account by the metrics.
How
To solve this, we add a Metrics_server in lib_rpc_process/main.ml, which would mean that we can query the /metrics endpoint on the external RPC port.
Manually testing the MR
- start sandbox node
$ ./src/bin_node/octez-sandboxed-node.sh 1 --connections 0 --rpc-addr localhost:18731 --metrics-addr localhost:12345 --external-rpc-addr localhost:18732
$ eval `./src/bin_client/octez-init-sandboxed-client.sh 1`
$ octez-activate-alpha
- make external RPC call
$ curl -s 'localhost:18732/chains/main/blocks/head/helpers/baking_rights'
- observe the new
external_rpc_callsmetrics
$ curl -s 'localhost:18732/metrics' | grep baking_rights
octez_external_rpc_calls_sum{endpoint="/chains/<chain_id>/blocks/<block_id>/helpers/baking_rights", method="GET"} 0.001346
octez_external_rpc_calls_count{endpoint="/chains/<chain_id>/blocks/<block_id>/helpers/baking_rights", method="GET"} 1.000000
- and that this not counted for the normal
metrics
$ curl -s 'localhost:12345/metrics' | grep baking_rights
<nothing>
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rstfor the protocol and the environment,CHANGES.rstat the root of the repository for everything else). -
Select suitable reviewers using the Reviewersfield below. -
Select as Assigneethe next person who should take action on that MR