Skip to content

Add client-side metrics to the ZooKeeper Java client#148

Draft
arkmish wants to merge 1 commit into
branch-3.6from
armishra/client-side-metrics
Draft

Add client-side metrics to the ZooKeeper Java client#148
arkmish wants to merge 1 commit into
branch-3.6from
armishra/client-side-metrics

Conversation

@arkmish

@arkmish arkmish commented Jul 13, 2026

Copy link
Copy Markdown

Description

Adds client-side metrics to the ZooKeeper Java client, built on the existing pluggable MetricsProvider framework (which was always intended for client use, per ZOOKEEPER-3103). Until now only the server emitted metrics via ServerMetrics; the Java client emitted none.

  • What: a new ClientMetrics singleton (mirroring ServerMetrics) plus instrumentation in ClientCnxn. It records per-operation request latency and count, unsuccessful-request counts labelled by KeeperException.Code, ping round-trip time, connect latency, and connection established/loss/reconnect and session-expired counters.
  • Why: give operators visibility into client-observed behavior (op traffic, latency, errors, connection/session churn) — aligning with the open upstream requests ZOOKEEPER-4983 / ZOOKEEPER-4863 / ZOOKEEPER-4841.
  • How: metrics are emitted from a single request funnel (queuePacket/finishPacket) and the SendThread lifecycle. The feature is opt-in: the default provider is NullMetricsProvider (zero overhead), enabled via new zookeeper.clientMetricsProvider.className / zookeeper.clientMetricsProvider.* client properties on ZKClientConfig. The provider is a per-JVM singleton shared by all ZooKeeper instances so a real provider is not booted twice (e.g. Prometheus port binding).

Tests

  • Local code review completed

The following tests are written for this issue:

  • ClientMetricsTest (unit — singleton, per-op latency/count, error-by-code, lifecycle counters/summaries)
  • ZKClientConfigMetricsTest (unit — provider class-name default/override and metricsProvider.* passthrough)
  • ClientMetricsIntegrationTest (integration — real client↔server; asserts create/getData counts, NONODE error count, and connection-established are emitted)

The following is the result of the "mvn test" command on the appropriate module (zookeeper-server):

mvn -pl zookeeper-server -am test -Dtest='ClientMetricsTest,ZKClientConfigMetricsTest,ClientMetricsIntegrationTest'
Tests run: 9, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

Existing ZKClientConfigTest (6) still passes. (Note: JMX-harness integration tests are broken in this local environment under Java 25/RMI, unrelated to this change; the metrics integration test is self-contained and avoids that harness.)

Changes that Break Backward Compatibility (Optional)

None. The feature is purely additive and opt-in: with no configuration the client uses NullMetricsProvider, so existing behavior and overhead are unchanged.

Documentation (Optional)

Adds a "Client Metrics" section to zookeeper-docs/.../zookeeperMonitor.md documenting how to enable the provider, the per-JVM semantics, and the emitted metrics.

🤖 Generated with GitHub Copilot CLI

Introduce ClientMetrics (mirroring ServerMetrics) and wire the existing
pluggable MetricsProvider framework into the Java client. Client metrics
are opt-in: the default provider is NullMetricsProvider, so there is no
overhead unless explicitly enabled via the new
zookeeper.clientMetricsProvider.className / .* client properties.

ClientCnxn now emits, from a single request funnel and the SendThread
lifecycle:
- per-operation request latency and count
- unsuccessful request counts labelled by KeeperException.Code
- ping round-trip time and connect latency
- connection established / loss / reconnect and session-expired counters

The provider is a per-JVM singleton shared by all ZooKeeper instances so
that, e.g., a Prometheus provider does not bind the same port twice.

Adds unit and integration tests and a Client Metrics section to the
monitor guide.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant