Skip to main content

confluent_kafka/common/metrics/
stat.rs

1// Copyright 2025 Confluent Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! A `Stat` is a quantity computed off the stream of updates to a sensor
16//! (`org.apache.kafka.common.metrics.Stat`).
17
18use crate::common::metrics::MetricConfig;
19
20/// A `Stat` is a quantity such as average, max, etc that is computed off the
21/// stream of updates to a sensor.
22///
23/// # Translation notes
24///
25/// `record` takes `&self`, so a stat uses interior mutability.
26// The simple cumulative stats use atomics so that recording is lock-free, the
27// minimal Rust equivalent of Java guarding the stat field with the sensor's
28// `synchronized`.
29#[doc(alias = "org.apache.kafka.common.metrics.Stat")]
30pub trait Stat: Send + Sync {
31    /// Record the given value.
32    ///
33    /// # Arguments
34    ///
35    /// - `config` - The configuration to use for this metric
36    /// - `value` - The value to record
37    /// - `time_ms` - The POSIX time in milliseconds this value occurred
38    #[doc(alias = "org.apache.kafka.common.metrics.Stat#record")]
39    fn record(&self, config: &MetricConfig, value: f64, time_ms: i64);
40}