Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
archeoss committed Dec 1, 2023
1 parent 1672b47 commit 2bdbf32
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 263 deletions.
57 changes: 55 additions & 2 deletions backend/src/models/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,37 @@ pub struct Disk {
pub iops: u64,
}

impl Disk {
#[must_use]
pub fn from_metrics(
disk_name: String,
disk_path: String,
raw_metrics: &dto::MetricsSnapshotModel,
raw_space: &dto::SpaceInfo,
) -> Self {
let status = DiskStatus::from_space_info(raw_space, &disk_name);
let used_space = raw_space
.occupied_disk_space_by_disk
.get(&disk_name)
.copied()
.unwrap_or_default();
let iops = raw_metrics
.metrics
.get(&format!("hardware.disks.{:?}_iops", disk_name))
.cloned()
.unwrap_or_default()
.value;
Self {
name: disk_name,
path: disk_path,
status,
total_space: raw_space.total_disk_space_bytes,
used_space,
iops,
}
}
}

/// Defines kind of problem on disk
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Serialize, Hash)]
#[cfg_attr(all(feature = "swagger", debug_assertions), derive(ToSchema))]
Expand Down Expand Up @@ -189,6 +220,12 @@ pub enum NodeStatus {
Offline,
}

impl Default for NodeStatus {
fn default() -> Self {
Self::Offline
}
}

impl NodeStatus {
#[must_use]
pub fn from_problems(problems: Vec<NodeProblem>) -> Self {
Expand Down Expand Up @@ -343,7 +380,7 @@ pub enum VDiskStatus {
Offline,
}

#[derive(Debug, Clone, Serialize)]
#[derive(Default, Debug, Clone, Serialize)]
#[cfg_attr(all(feature = "swagger", debug_assertions), derive(ToSchema))]
pub struct DetailedNode {
pub name: String,
Expand All @@ -360,7 +397,7 @@ pub struct DetailedNode {
pub disks: Vec<Disk>,
}

#[derive(Debug, Clone, Serialize)]
#[derive(Default, Debug, Clone, Serialize)]
#[cfg_attr(all(feature = "swagger", debug_assertions), derive(ToSchema))]
#[serde(rename_all = "camelCase")]
pub struct DetailedNodeMetrics {
Expand All @@ -381,6 +418,22 @@ pub struct DetailedNodeMetrics {
pub descr_amount: u64,
}

impl DetailedNodeMetrics {
#[must_use]
pub fn from_metrics(metrics: &TypedMetrics, space: SpaceInfo) -> Self {
Self {
rps: RPS::from_metrics(metrics),
alien_count: metrics[RawMetricEntry::BackendAlienCount].value,
corrupted_count: metrics[RawMetricEntry::BackendCorruptedBlobCount].value,
space,
cpu_load: metrics[RawMetricEntry::HardwareBobCpuLoad].value,
total_ram: metrics[RawMetricEntry::HardwareTotalRam].value,
used_ram: metrics[RawMetricEntry::HardwareUsedRam].value,
descr_amount: metrics[RawMetricEntry::HardwareDescrAmount].value,
}
}
}

/// Types of operations on BOB cluster
#[derive(Debug, Clone, Serialize, Hash, Eq, PartialEq, PartialOrd, Ord, EnumIter)]
#[cfg_attr(all(feature = "swagger", debug_assertions), derive(ToSchema))]
Expand Down
Loading

0 comments on commit 2bdbf32

Please sign in to comment.