hyperi-rustlib 2.8.6

There's plenty of sage advice out there about how to run Rust services in production at scale — config cascades, structured logging, masking secrets, multi-backend secrets management, Prometheus, OpenTelemetry, Kafka transports, tiered disk-spillover sinks, adaptive worker pools, graceful shutdown — but almost none of it as code you can just install and use. This is that code. Opinionated, drop-in, working out of the box. The patterns from blog posts, watercooler chats and beers with your Google mates as actual library — not a framework you assemble from twenty crates and 8 weeks of munging.
Documentation
// Project:   hyperi-rustlib
// File:      src/metrics/dfe_groups/backpressure.rs
// Purpose:   DFE backpressure metrics group
// Language:  Rust
//
// License:   BUSL-1.1
// Copyright: (c) 2026 HYPERI PTY LIMITED

//! Backpressure metrics.

use metrics::Counter;

use super::super::MetricsManager;

/// Backpressure event tracking.
///
/// Counts backpressure activations and cumulative pause duration.
#[derive(Clone)]
pub struct BackpressureMetrics {
    pub events: Counter,
    pub duration: Counter,
}

impl BackpressureMetrics {
    #[must_use]
    pub fn new(manager: &MetricsManager) -> Self {
        Self {
            events: manager.counter_with_labels(
                "backpressure_events_total",
                "Backpressure activation events",
                &[],
                "backpressure",
            ),
            duration: manager.counter_with_labels(
                "backpressure_duration_seconds_total",
                "Cumulative time paused by backpressure",
                &[],
                "backpressure",
            ),
        }
    }

    #[inline]
    pub fn record_event(&self) {
        self.events.increment(1);
    }

    /// Record backpressure pause duration in seconds.
    #[inline]
    pub fn record_duration(&self, seconds: f64) {
        // Duration is always non-negative and fits in u64 for practical values.
        #[allow(clippy::cast_sign_loss, clippy::cast_possible_truncation)]
        self.duration.increment(seconds as u64);
    }
}