Skip to content

rpc-client: per-provider/method request metrics (counted by batch element)#493

Closed
elina-chertova wants to merge 1 commit into
open-betafrom
metrics/rpc-per-provider-method
Closed

rpc-client: per-provider/method request metrics (counted by batch element)#493
elina-chertova wants to merge 1 commit into
open-betafrom
metrics/rpc-per-provider-method

Conversation

@elina-chertova

Copy link
Copy Markdown
Contributor

Summary

Add per-upstream request metrics at the RpcClient level, so every SDK ingest path (dump, processor, data-service) can see how many requests we send to each provider — broken down by network, method and outcome — from our own metrics.

Why

Today we can't reconcile our request volume against a provider's dashboard:

  • sqd_chain_rpc_requests_served_total{url} is emitted only by the dump CLI → archive-only; the live / data-service path has no per-provider counter.
  • the only label is the full keyed URL (high cardinality + leaks the API key).

So we can't answer "how many requests / which methods did we send to provider X on chain Y", nor catch over-usage spikes from our side. Instrumenting at RpcClient — the transport all paths share — closes the blind spot in one place.

What changed (util/rpc-client/src/client.ts)

  • RpcClientOptions gains provider? and chain? — the canonical identity, set by the caller from its deployment/infra config. Deliberately not derived from the URL host (a provider can use several hosts, e.g. direct.drpc.org and lb.drpc.live).
  • per-method tally counted by batch element (a JSON-RPC batch is one HTTP call but N billable items), split into success/failure, keyed by method.
  • exposed via getMetrics() (RpcMetrics.methods, plus provider / chain).

Design decisions

  • Exposed through getMetrics(), not a prom-client Counter inside rpc-client — keeps this low-level lib dependency-free and avoids duplicating the per-CLI exporters that already read getMetrics(). An exporter then emits sqd_rpc_upstream_requests_total{provider, chain, method, outcome}.
  • Counts batch elements, so the number matches what providers bill (batching is real — see sqd_rpc_batch_size_*).

Not in this PR (follow-ups)

  • exporter side: PrometheusServers (dump-cli, processor-tools) + data-service emit the labeled counter from getMetrics().methods.
  • wire callers (ingesters) to pass provider / chain from config.

Compatibility

requestsServed (HTTP-call count) unchanged; methods{} is purely additive.

Testing

Couldn't run tsc in the authoring environment (rush deps not installed) — please confirm with rush build --to @subsquid/rpc-client.

@elina-chertova elina-chertova requested a review from tmcgroul June 12, 2026 10:50
…ment)

Instrument at the RpcClient level so EVERY SDK path (dump, processor, data-service) gets
per-upstream visibility from one place. Provider/chain identity come from constructor options
(set by the caller from its infra/deployment config — the canonical 'name', NOT derived from the
URL host, which can vary per provider). Calls are tallied by BATCH ELEMENT (a JSON-RPC batch is
one HTTP call but N billable items) and split by outcome, keyed by method — so a Prometheus
exporter can emit {provider, chain, method, outcome} and reconcile against provider CU bills.

Exposed via getMetrics() (RpcMetrics.methods) rather than a prom-client Counter inside rpc-client:
keeps this low-level lib dependency-free and avoids duplicating the per-CLI exporters that already
read getMetrics(). The exporter side (PrometheusServer label emission) is a follow-up.

requestsServed (HTTP-call count) is unchanged for back-compat; methods{} is additive.
@elina-chertova elina-chertova force-pushed the metrics/rpc-per-provider-method branch from 2f5bcbe to f52dcc6 Compare June 12, 2026 11:05
@tmcgroul

Copy link
Copy Markdown
Contributor

this pr targets open-beta branch which is not maintained anymore. closing in favour of #511

@tmcgroul tmcgroul closed this Jun 26, 2026
@tmcgroul tmcgroul deleted the metrics/rpc-per-provider-method branch June 26, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants