pub struct KafkaMetric { /* private fields */ }Expand description
A metric tracked by the registry. Holds a MetricName, a (mutable)
MetricConfig and a MetricValueProvider.
In Java the config field is volatile and metricValue/measurableValue
read under a per-metric lock to make the stat read consistent with sensor
records. Because our simple stats are themselves lock-free (atomic), the
value read needs no extra lock; we still guard config with a Mutex so the
config(new) setter is observed atomically, matching Java’s synchronized
setter + volatile read.
Implementations§
Source§impl KafkaMetric
impl KafkaMetric
Sourcepub fn config(&self) -> Arc<MetricConfig>
pub fn config(&self) -> Arc<MetricConfig>
Get the configuration of this metric.
Sourcepub fn set_config(&self, config: Arc<MetricConfig>)
pub fn set_config(&self, config: Arc<MetricConfig>)
Set the metric config.
Sourcepub fn is_measurable(&self) -> bool
pub fn is_measurable(&self) -> bool
Determine if the metric value provider is of type Measurable.
Sourcepub fn measurable(&self) -> Result<&dyn Measurable, Error>
pub fn measurable(&self) -> Result<&dyn Measurable, Error>
Get the underlying Measurable value provider.
Returns Error::LocalIllegalState when the provider is a
MetricValueProvider::Gauge instead — Java’s measurable() throws
IllegalStateException("Not a measurable: " + class) in that case
(KafkaMetric.java). Per CLAUDE.md §12.2 an unchecked-but-recoverable
Java exception becomes a Result rather than a panic.
Java returns the provider so callers can compare it by identity (see
KafkaMetricTest.testIsMeasurable); Rust returns a borrow of the boxed
trait object, which is the closest equivalent — trait objects have no
meaningful value equality, so callers assert on is_ok() / the measured
value instead.