Skip to content

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

Closed
arkmish wants to merge 0 commit into
branch-3.6from
armishra/client-side-metrics
Closed

arkmish wants to merge 0 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

@arkmish arkmish closed this Aug 29, 2026
@arkmish
arkmish force-pushed the armishra/client-side-metrics branch from 58ea722 to 1d05536 Compare August 29, 2026 11:39
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