[WIP]Add OpenTelemetry metrics support for load balancer state sensor #1129
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.
This PR adds OpenTelemetry (OTel) metrics instrumentation to the LoadBalancerState sensor.
Changes New Interface: Added LoadBalancerStateOtelMetricsProvider interface for collecting LoadBalancerState metrics via OpenTelemetry
recordClusterCount(String clientName, int regularClusterCount, long symlinkClusterCount)
recordServiceCount(String clientName, int serviceCount)
Purpose: library-side abstraction so host apps can plug an OTel implementation.
No-op Implementation: Added NoOpLoadBalancerStateOtelMetricsProvider as default when metrics are disabled.
JMX bean changes
SimpleLoadBalancerStateJmx now accepts a LoadBalancerStateOtelMetricsProvider and exposes setClientName/getClientName.
The bean calls provider.recordClusterCount(...) from both getClusterCount() and getSymlinkClusterCount(), and provider.recordServiceCount(...) from getServiceCount().
Integration
D2ClientConfig: added field to carry LoadBalancerStateOtelMetricsProvider (defaults to NoOp).
D2ClientBuilder: added setLoadBalancerStateOtelMetricsProvider(...) to inject a provider.
D2ClientJmxManager: accepts the provider, constructs provider-backed SimpleLoadBalancerStateJmx, sets client name before registration, and registers the bean.
Updated load-balancer factory call sites to forward the provider into D2ClientJmxManager.
Metrics Tracked
Gauges:
regular cluster count (recordClusterCount)
symlink cluster count (recordClusterCount)
service count (recordServiceCount)
All callbacks include clientName for attribution.
Testing
Added TestSimpleLoadBalancerStateJmx to verify:
default no-op provider is safe,
mock provider received expected callbacks,
client name propagation works.
Updated test fixtures to match API types (Set for clusters).
Backward compatibility
Fully backward compatible: defaults to NoOp provider when not configured; existing behavior unchanged unless a real provider is supplied.