CircuitBreakerMetricsCollector extends AbstractCircuitBreakerMetrics { public static CircuitBreakerMetricsCollector ofCircuitBreakerRegistry(MetricNames names, MetricOptions options, CircuitBreakerRegistry circuitBreakerRegistry) { return new CircuitBreakerMetricsCollector(names, options, circuitBreakerRegistry); } private  CircuitBreakerMetricsCollector(MetricNames names, MetricOptions options,
        CircuitBreakerRegistry circuitBreakerRegistry); static CircuitBreakerMetricsCollector ofCircuitBreakerRegistry(MetricNames names,
        MetricOptions options, CircuitBreakerRegistry circuitBreakerRegistry); static CircuitBreakerMetricsCollector ofCircuitBreakerRegistry(MetricNames names,
        CircuitBreakerRegistry circuitBreakerRegistry); static CircuitBreakerMetricsCollector ofCircuitBreakerRegistry(
        CircuitBreakerRegistry circuitBreakerRegistry); @Override List<MetricFamilySamples> collect();  }
@Test public void customMetricNamesOverrideDefaultOnes() { CollectorRegistry registry = new CollectorRegistry(); CircuitBreakerMetricsCollector.ofCircuitBreakerRegistry( custom().callsMetricName("custom_calls") .stateMetricName("custom_state") .bufferedCallsMetricName("custom_buffered_calls") .slowCallsMetricName("custom_slow_calls") .failureRateMetricName("custom_failure_rate") .slowCallRateMetricName("custom_slow_rate") .build(), circuitBreakerRegistry).register(registry); assertThat(registry.getSampleValue( "custom_buffered_calls", new String[]{"name", "kind"}, new String[]{"backendA", "successful"} )).isNotNull(); assertThat(registry.getSampleValue( "custom_buffered_calls", new String[]{"name", "kind"}, new String[]{"backendA", "failed"} )).isNotNull(); assertThat(registry.getSampleValue( "custom_state", new String[]{"name", "state"}, new String[]{"backendA", "closed"} )).isNotNull(); }
@Test public void customMetricNameBucketsOverrideDefaultOnes() { CollectorRegistry registry = new CollectorRegistry(); CircuitBreakerMetricsCollector.ofCircuitBreakerRegistry( MetricNames.ofDefaults(), MetricOptions.custom().buckets(new double[]{.005, .01}).build(), circuitBreakerRegistry).register(registry); circuitBreaker.onSuccess(2000, TimeUnit.NANOSECONDS); assertThat(registry.getSampleValue( DEFAULT_CIRCUIT_BREAKER_CALLS + "_bucket", new String[]{"name", "kind", "le"}, new String[]{circuitBreaker.getName(), "successful", "0.01"} )).isEqualTo(1d); assertThat(registry.getSampleValue( DEFAULT_CIRCUIT_BREAKER_CALLS + "_bucket", new String[]{"name", "kind", "le"}, new String[]{circuitBreaker.getName(), "successful", "0.025"} )).isNull(); }