Repository navigation
Conversation
Requests received over a client WebSocket connection are counted in erpc_network_request_received_total like HTTP ones, with no way to tell the two apart. Record the ingress transport on NormalizedRequest (defaulting to "http") and expose it as a transport label (http|ws), set by the WebSocket handler for regular calls and eth_(un)subscribe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- erpc_websocket_connections_active gains a network label. The label is
now set once at upgrade (the network alias if configured, else its id),
so connections without subscriptions are attributed too.
- erpc_websocket_connections_closed_total{project,network,close_code,
initiator}: closed client connections, by who ended them. Codes outside
the RFC 6455 range (1000-1015) are reported as "other" so a client cannot
create series by picking arbitrary close codes.
- erpc_websocket_requests_total{project,network,category,user,agent_name,
outcome}: every JSON-RPC request received on a client connection, batch
items individually, including those rejected before they reach the
network and so absent from network_request_received_total (invalid,
invalid_batch, method_not_allowed, unauthorized, rate_limited,
network_unavailable). category stays "n/a" until the request is
authenticated so unauthenticated clients cannot create series with
arbitrary method names. A panicking request is counted as "error".
The network label is read from the project config (the value
Network.Label() returns): resolving it via GetNetwork would block the
upgrade until a cold network is bootstrapped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
erpc_websocket_notifications_sent_total and erpc_websocket_subscription_notifications_dropped_total gain user and agent_name, and become labeled counters so those labels can be dropped through metrics customizations like on every other per-client counter. The labels are captured once at eth_subscribe time and carried on the subscription (wsclient.SubscriptionLabels), so recording a notification needs no lookup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a Metrics section to the WebSocket page and list the new families in the metrics reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Client-side WebSocket traffic is only partly visible in metrics: calls that reach the network are counted in
erpc_network_request_received_totalindistinguishably from HTTP, and calls rejected before the network (invalid JSON, disallowed method, auth failure, consumer rate limit, network unavailable) are not counted at all. The subscription pressure metrics from erpc#1255 cover connections, subscriptions and notifications per network, but not per client, and not why connections close.This builds on erpc#1255 instead of adding parallel metrics:
transportlabel (http|ws) onerpc_network_request_received_total, recorded onNormalizedRequest(defaults tohttp).erpc_websocket_connections_activegains anetworklabel. The connection's network label is now set once at upgrade instead of on the first subscription, so connections without subscriptions are attributed too.erpc_websocket_connections_closed_total{project,network,close_code,initiator}.close_codeis bounded to the RFC 6455 range (1000-1015, elseother).erpc_websocket_requests_total{project,network,category,user,agent_name,outcome}: every JSON-RPC request on a client connection (batch items individually), including pre-network rejections. Outcomes:ok,error,rate_limited,invalid,invalid_batch,method_not_allowed,unauthorized,network_unavailable.categorystaysn/auntil the request is authenticated, so unauthenticated clients cannot create series with arbitrary method names.userandagent_nameonerpc_websocket_notifications_sent_totalanderpc_websocket_subscription_notifications_dropped_total, which become labeled counters. The labels are captured ateth_subscribetime and carried on the subscription (wsclient.SubscriptionLabels).Notes for review:
user/agent_namewith the existingmetrics.customizationslabel rules. Gauges carry nouserlabel.networklabel is read from the project config (the valueNetwork.Label()returns). Resolving it withGetNetworkwould block the upgrade until a cold network is bootstrapped.getOrCreateConnno longer setsnetworkLabel; it is written once before the connection is shared, so reads need no lock.erpc_network_request_duration_seconds{user}.operation/websocket, rows inreference/metrics, and thetransportlabel wherevernetwork_request_received_totallabels are listed.Verification
Based on
erpc/erpcmain @ 094b912.go build ./...,go vet ./...andgofmt -lon touched files are clean.make test-fast(what CI runs): passes, exit 0, no failing test.TestWebSocket_RequestAccounting: ok, method_not_allowed, invalid and invalid_batch outcomes;transport="ws"on received; connection gauge up and back down; client-initiated close counted with code 1000.TestWebSocket_RequestAccountingAuthRateLimited: therate_limitedoutcome.TestWebSocket_CloseCodeLabelIsBounded.TestWebSocket_LogsSubscribeOnAllUpstreamsAndDedupe: the sent counter now asserts theuser/agent_namelabels.TestNormalizedRequest_TransportDefaultsToHttp.AI assistance
🤖 Generated with Claude Code