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