Skip to main content

Module scaling

Module scaling 

Source
Available on crate feature scaling only.
Expand description

Scaling pressure calculation for autoscaler integration.

Produces a 0.0-100.0 composite metric based on weighted application signals with two hard gates (circuit breaker, memory pressure). Designed for KEDA but works with any autoscaler that reads Prometheus gauges.

§Architecture

App signals ──→ ScalingPressure ──→ {prefix}_scaling_pressure gauge
                 ├─ Gate: circuit breaker open → 0.0
                 ├─ Gate: memory ≥ threshold → 100.0
                 └─ Weighted composite → 0.0-100.0

§Usage

  1. Define components with weights and saturation points
  2. Create ScalingPressure with base config + components
  3. Update component values from your pipeline (lock-free)
  4. Call calculate() when rendering Prometheus metrics
use hyperi_rustlib::scaling::{ScalingPressure, ScalingPressureConfig, ScalingComponent};

let pressure = ScalingPressure::new(
    ScalingPressureConfig::default(),
    vec![
        ScalingComponent::new("kafka_lag", 0.35, 100_000.0),
        ScalingComponent::new("buffer_depth", 0.25, 10_000.0),
        ScalingComponent::new("memory", 0.40, 1.0),
    ],
);

// Update from pipeline (lock-free, call from any thread)
pressure.set_component("kafka_lag", 50_000.0);
pressure.set_memory(400_000_000, 1_000_000_000);

// Render in Prometheus endpoint
let value = pressure.calculate();
assert!(value >= 0.0 && value <= 100.0);

§CPU Scaling

CPU is intentionally not included in the composite. KEDA’s native CPU trigger reads from the Kubernetes metrics-server (container-level CPU utilisation). Configure both triggers independently in your KEDA ScaledObject:

  • scaling_pressure gauge → Prometheus scaler (app-level signals)
  • CPU utilisation → CPU scaler (container-level, via metrics-server)

KEDA scales to the MAX of all triggers.

Structs§

ComponentSnapshot
Per-component diagnostic snapshot.
PressureSnapshot
Full diagnostic snapshot of scaling pressure state.
RateWindow
Sliding window rate calculator.
ScalingComponent
Named scaling component with weight and saturation point.
ScalingPressure
Lock-free scaling pressure calculator.
ScalingPressureConfig
Base configuration for scaling pressure calculation.

Enums§

GateType
Active gate preventing normal composite calculation.