feldera_types/
memory_pressure.rs1use std::fmt::Display;
2
3use serde::{Deserialize, Serialize};
4use utoipa::ToSchema;
5
6pub const MODERATE_MEMORY_PRESSURE_THRESHOLD: f64 = 0.85;
7pub const HIGH_MEMORY_PRESSURE_THRESHOLD: f64 = 0.90;
8pub const CRITICAL_MEMORY_PRESSURE_THRESHOLD: f64 = 0.95;
9
10#[derive(
23 Debug, Default, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize, ToSchema,
24)]
25#[repr(u8)]
26#[serde(rename_all = "snake_case")]
27pub enum MemoryPressure {
28 #[default]
30 Low = 0,
31 Moderate = 1,
33 High = 2,
35 Critical = 3,
37}
38
39impl TryFrom<u8> for MemoryPressure {
40 type Error = ();
41
42 fn try_from(value: u8) -> Result<Self, Self::Error> {
43 match value {
44 0 => Ok(MemoryPressure::Low),
45 1 => Ok(MemoryPressure::Moderate),
46 2 => Ok(MemoryPressure::High),
47 3 => Ok(MemoryPressure::Critical),
48 _ => Err(()),
49 }
50 }
51}
52
53impl MemoryPressure {
54 pub fn as_str(&self) -> &'static str {
55 match self {
56 MemoryPressure::Low => "low",
57 MemoryPressure::Moderate => "moderate",
58 MemoryPressure::High => "high",
59 MemoryPressure::Critical => "critical",
60 }
61 }
62}
63
64impl Display for MemoryPressure {
65 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
66 f.write_str(self.as_str())
67 }
68}