Skip to main content

KafkaMetric

Struct KafkaMetric 

Source
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

Source

pub fn config(&self) -> Arc<MetricConfig>

Get the configuration of this metric.

Source

pub fn set_config(&self, config: Arc<MetricConfig>)

Set the metric config.

Source

pub fn is_measurable(&self) -> bool

Determine if the metric value provider is of type Measurable.

Source

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.

Trait Implementations§

Source§

impl Metric for KafkaMetric

Source§

fn metric_name(&self) -> &MetricName

A name for this metric.
Source§

fn metric_value(&self) -> MetricValue

The value of the metric, which may be measurable or a non-measurable gauge.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V