Skip to content

*: add drpc client and server metrics#33

Open
suj-krishnan wants to merge 1 commit intocockroachdb:mainfrom
suj-krishnan:add_drpc_metrics
Open

*: add drpc client and server metrics#33
suj-krishnan wants to merge 1 commit intocockroachdb:mainfrom
suj-krishnan:add_drpc_metrics

Conversation

@suj-krishnan
Copy link
Copy Markdown

@suj-krishnan suj-krishnan commented Mar 2, 2026

Add metrics collection for drpc client connections, server connections, and connection pools.

  • Introduce Counter, Observer, and Gauge metric interfaces in the drpc package, allowing us to plug in the metrics implementation from cockroach
  • Client metrics: bytes sent/received
  • Server metrics: bytes sent/received, TLS handshake errors, inactivity timeouts, and per-RPC stream lifecycle metrics (total, duration) with labels for service/method/type/code
  • Pool metrics: pool size, connection hits/misses, connection age

@suj-krishnan suj-krishnan force-pushed the add_drpc_metrics branch 6 times, most recently from 66f4653 to af14586 Compare March 10, 2026 15:11
@suj-krishnan suj-krishnan marked this pull request as ready for review March 10, 2026 15:11
@suj-krishnan suj-krishnan changed the title add drpc metrics *: add drpc client and server metrics Mar 10, 2026
@suj-krishnan suj-krishnan marked this pull request as draft March 11, 2026 06:14
Add metrics collection for drpc client connections, server connections,
and stream pool.
- Introduce Counter, Observer, and Gauge metric interfaces in the drpc package,
allowing us to plug in the metrics implementation from cockroach
- Client metrics: bytes sent/received
- Server metrics: bytes sent/received, TLS handshake errors, inactivity
timeouts, and per-RPC stream lifecycle metrics (total, active, duration,
errors) with labels for service/method/type
- Pool metrics: pool size, connection hits/misses, connection age
@suj-krishnan suj-krishnan marked this pull request as ready for review March 11, 2026 06:32
@suj-krishnan suj-krishnan requested a review from Nukitt March 12, 2026 04:42
BytesSent: opts.Metrics.BytesSent,
BytesRecv: opts.Metrics.BytesRecv,
}
c.tr = tr
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can save one line if you move this above c declaration :)

@shubhamdhama shubhamdhama self-requested a review March 12, 2026 06:03
Copy link
Copy Markdown

@shubhamdhama shubhamdhama left a comment

Choose a reason for hiding this comment

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

  1. drpcstats is now superseded by the new drpc.Counter/drpc.Observer interfaces. Since we don't use the drpcstats package, I think we can safely remove it. Also, please move the metrics.go to a new package, drpcmetrics which would provide this transport.
  2. RPCTyper and rpcLabels feel like they belong in drpcmux, the mux already knows whether an RPC is unary and can split the path. The current design requires drpcserver to do a type assertion against its own handler to get this information.

if p.opts.Metrics.ConnectionHitsTotal != nil {
p.opts.Metrics.ConnectionHitsTotal.Add(nil, 1)
}
if p.opts.Metrics.ConnectionAgeSeconds != nil {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This != nil is kinda spilled all over the place. Not a blocker for merging this PR, only suggesting if we can do better here.
One suggestion would be to default to noop implementation to these interfaces,

  type noopCounter struct{}
  func (noopCounter) Add(map[string]string, float64) {}

  type noopGauge = noopCounter

  type noopObserver struct{}
  func (noopObserver) Observe(map[string]string, float64) {}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks - yes, will fix this one (bothers me too).

@suj-krishnan
Copy link
Copy Markdown
Author

  1. drpcstats is now superseded by the new drpc.Counter/drpc.Observer interfaces. Since we don't use the drpcstats package, I think we can safely remove it. Also, please move the metrics.go to a new package, drpcmetrics which would provide this transport.
  2. RPCTyper and rpcLabels feel like they belong in drpcmux, the mux already knows whether an RPC is unary and can split the path. The current design requires drpcserver to do a type assertion against its own handler to get this information.

1 is in my todo list. Will check if 2 would work. TFTF!

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