Trait MetricsProvider

Source
pub trait MetricsProvider: Send + Sync {
    // Required method
    fn get_metrics<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        resource_id: &'life1 str,
        context: &'life2 CallbackContext,
    ) -> Pin<Box<dyn Future<Output = LighthouseResult<Option<ResourceMetrics>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided method
    fn validate_metrics<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        metrics: &'life1 ResourceMetrics,
        _context: &'life2 CallbackContext,
    ) -> Pin<Box<dyn Future<Output = LighthouseResult<Option<ResourceMetrics>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Trait for handling metric collection and validation

Implement this to provide metrics to the lighthouse engine. This allows you to integrate with any monitoring system.

Required Methods§

Source

fn get_metrics<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, resource_id: &'life1 str, context: &'life2 CallbackContext, ) -> Pin<Box<dyn Future<Output = LighthouseResult<Option<ResourceMetrics>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Fetch current metrics for a specific resource

§Arguments
  • resource_id - The resource to get metrics for
  • context - Additional context for the callback
§Returns
  • Ok(Some(metrics)) - Successfully fetched metrics
  • Ok(None) - Resource exists but no metrics available
  • Err(error) - Failed to fetch metrics

Provided Methods§

Source

fn validate_metrics<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, metrics: &'life1 ResourceMetrics, _context: &'life2 CallbackContext, ) -> Pin<Box<dyn Future<Output = LighthouseResult<Option<ResourceMetrics>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Validate that metrics are reasonable/expected

This is called before metrics are processed by scaling policies. Use this to filter out bad data, apply smoothing, etc.

§Arguments
  • metrics - The raw metrics to validate
  • context - Additional context for the callback
§Returns
  • Ok(Some(validated_metrics)) - Metrics are valid (possibly modified)
  • Ok(None) - Metrics should be ignored
  • Err(error) - Validation failed

Implementors§