CollectibleMetrics

Trait CollectibleMetrics 

Source
pub trait CollectibleMetrics:
    Clone
    + Debug
    + Send
    + Sync
    + Default
    + 'static {
    // Required methods
    fn reset(&mut self);
    fn merge(&mut self, other: &Self);
    fn summary(&self) -> HashMap<String, String>;
    fn metric_type(&self) -> String;
    fn validate(&self) -> Result<(), PipelineError>;
}
Expand description

Generic trait for metrics that can be collected and aggregated

This trait defines the interface for metrics that can be collected, aggregated, and reported by the generic metrics collector. It provides a type-safe way to define custom metrics with validation and summarization capabilities.

§Key Features

  • Reset Capability: Reset metrics to initial state for new collection periods
  • Merge Operations: Combine metrics from different sources or time periods
  • Summary Generation: Generate human-readable summaries of metrics
  • Type Identification: Identify metric types for proper handling
  • Validation: Validate metric consistency and correctness

§Implementation Requirements

Implementing types must:

  • Be cloneable for metrics aggregation
  • Be debuggable for error reporting
  • Be thread-safe (Send + Sync)
  • Have a default constructor for initialization
  • Have a stable lifetime ('static)

§Examples

Required Methods§

Source

fn reset(&mut self)

Resets all metrics to their initial state

Source

fn merge(&mut self, other: &Self)

Merges metrics from another instance

Source

fn summary(&self) -> HashMap<String, String>

Returns a summary of key metrics as key-value pairs

Source

fn metric_type(&self) -> String

Returns the metric type identifier

Source

fn validate(&self) -> Result<(), PipelineError>

Validates that the metrics are in a consistent state

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§