Add cluster metrics listener for observability (node count, connections)#18
Merged
Merged
Conversation
Expose cluster/node statistics (node count, per-node pooled connection and failure counts) via an optional, dependency-free metrics listener. Register any object responding to `report(cluster_stats)` through the new `ClientPolicy#metrics_listener` option. Its `#report` is invoked from the tend thread once per tend interval with a fresh `ClusterStats` snapshot -- including on unchanged cycles -- so downstream gauges (e.g. Datadog) stay alive. Listener exceptions are caught and logged so a broken reporter cannot disrupt tending. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
zuchmanski
marked this pull request as ready for review
July 2, 2026 12:08
madejejej
approved these changes
Jul 2, 2026
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.
What
Adds an optional, dependency-free metrics hook to the client so applications can export cluster/node statistics (node count, per-node pooled connections, failures) to Datadog/StatsD/Prometheus/etc.
The client emits a fresh snapshot once per tend interval (default 1s) — including on cycles where the node set did not change — so downstream gauges stay alive between changes. No more scraping
"Tend finished. N nodes have joined the cluster"log lines.How to integrate
report(cluster_stats)::metrics_listenerclient policy option:That's it.
#reportwill be called every tend interval with aClusterStatssnapshot.Snapshot API
ClusterStats:node_count→ Integernode_names→ Arrayopen_connections→ Integer (sum of idle pooled connections across nodes)nodes→ Array<NodeStats>to_h→ Hash (handy for JSON logging)NodeStats:name,available_connections,failures,active?Notes / tradeoffs
dogstatsd. This is the conventional way client libs expose observability.available_connections= idle pooled connections per node (node.connections.length). The pool doesn't track in-use count, so this is the closest signal without deeper changes.#reportruns inline on the tend thread — keep it fast/non-blocking (a StatsD UDP send is fine). If heavy work is needed, push it to your own queue/thread inside the reporter."Exception in metrics listener: ..."); a broken reporter cannot disrupt cluster tending.Aerospike::MetricsListeneris optional and only documents the contract.Changes
lib/aerospike/cluster_stats.rb— newClusterStats/NodeStatsvalue objectslib/aerospike/metrics_listener.rb— new listener contract (docs)lib/aerospike/policy/client_policy.rb— newmetrics_listeneroptionlib/aerospike/cluster.rb—#report_metrics/#cluster_stats, invoked each tend cyclelib/aerospike.rb— require the new filesspec/aerospike/cluster_stats_spec.rb+#report_metricscoverage incluster_spec.rbTesting
bundle exec rspec spec/aerospike/cluster_stats_spec.rb spec/aerospike/cluster_spec.rb→ 30 examples, 0 failures. (The suite-levelafter(:suite)error requires a running Aerospike server and is unrelated to this change.)🤖 Generated with Claude Code