Skip to content

Commit 952eca8

Browse files
committed
chore: cleanup comments
1 parent 486b343 commit 952eca8

6 files changed

Lines changed: 52 additions & 38 deletions

File tree

src/charting/rasciigraph.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ use std::vec::Vec;
66
/// Configuration for ASCII graph plotting
77
#[derive(Default)]
88
pub struct Config {
9+
/// Width of the graph for data point interpolation.
910
width: u32,
11+
/// Height of the graph in terminal rows.
1012
height: u32,
13+
/// Offset for Y-axis labels from the left edge.
1114
offset: u32,
15+
/// Caption text displayed below the graph.
1216
caption: String,
1317
/// Number of decimal places for Y-axis labels
1418
y_precision: Option<i32>,

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use tracing::level_filters::LevelFilter;
1010
pub struct LogLevelArg(LevelFilter);
1111

1212
impl LogLevelArg {
13-
/// String representation suitable for `RUST_LOG`.
13+
/// Returns the string representation suitable for `RUST_LOG`.
1414
pub fn as_str(&self) -> &'static str {
1515
match self.0 {
1616
LevelFilter::OFF => "off",
@@ -79,7 +79,7 @@ pub enum LogKind {
7979
}
8080

8181
impl LogKind {
82-
/// String representation for file paths and display.
82+
/// Returns the string representation for file paths and display.
8383
pub fn as_str(&self) -> &'static str {
8484
match self {
8585
LogKind::Stdout => "stdout",

src/constants.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
66
use std::{cmp::Ordering, str::FromStr, time::Duration};
77

8-
// ============================================================================
9-
// Lock Management and Ordering
10-
// ============================================================================
11-
128
/// Typed lock abstraction for enforcing proper lock acquisition order in the daemon.
139
///
1410
/// This enum ensures that locks are always acquired in a consistent order to prevent
@@ -100,10 +96,6 @@ impl Ord for DaemonLock {
10096
}
10197
}
10298

103-
// ============================================================================
104-
// File System Constants
105-
// ============================================================================
106-
10799
/// Name of the PID file stored in the state directory.
108100
/// Contains mappings of service names to process IDs.
109101
pub const PID_FILE_NAME: &str = "pid.xml";
@@ -115,20 +107,12 @@ pub const PID_LOCK_SUFFIX: &str = ".lock";
115107
/// Contains the current state and metadata for all managed services.
116108
pub const STATE_FILE_NAME: &str = "state.xml";
117109

118-
// ============================================================================
119-
// Shell Execution Constants
120-
// ============================================================================
121-
122110
/// Default shell used for executing service commands and hooks.
123111
pub const DEFAULT_SHELL: &str = "sh";
124112

125113
/// Shell argument flag for executing command strings.
126114
pub const SHELL_COMMAND_FLAG: &str = "-c";
127115

128-
// ============================================================================
129-
// Process Management Timing
130-
// ============================================================================
131-
132116
/// Number of checks to perform when waiting for a process to become ready.
133117
/// Used in conjunction with PROCESS_CHECK_INTERVAL.
134118
pub const PROCESS_READY_CHECKS: usize = 10;
@@ -149,33 +133,17 @@ pub const POST_RESTART_VERIFY_ATTEMPTS: usize = 2;
149133
/// Delay between post-restart verification attempts.
150134
pub const POST_RESTART_VERIFY_DELAY: Duration = Duration::from_millis(200);
151135

152-
// ============================================================================
153-
// Logging and Output Constants
154-
// ============================================================================
155-
156136
/// Maximum number of log lines to display in status output.
157137
/// Prevents overwhelming the terminal with excessive log data.
158138
pub const MAX_STATUS_LOG_LINES: usize = 50;
159139

160140
/// Buffer size for log output streams (stdout/stderr).
161141
pub const LOG_BUFFER_SIZE: usize = 8192;
162142

163-
// ============================================================================
164-
// Hook Execution Constants
165-
// ============================================================================
166-
167143
/// Format string for hook labels combining stage and outcome.
168144
/// Example: "pre_start.pending", "post_start.success"
169145
pub const HOOK_LABEL_FORMAT: &str = "{}.{}";
170146

171-
// ============================================================================
172-
// Linux-specific Constants
173-
// ============================================================================
174-
175-
// ============================================================================
176-
// Error Messages and Formats
177-
// ============================================================================
178-
179147
/// Error message for malformed environment file lines.
180148
pub const ENV_FILE_MALFORMED_MSG: &str =
181149
"Ignoring malformed line in env file for '{}': {}";
@@ -195,10 +163,6 @@ pub const INSUFFICIENT_SIGNAL_PERMISSIONS_MSG: &str =
195163
pub const PROCESS_TREE_TERM_FAILURE_MSG: &str =
196164
"Failed to terminate process tree rooted at PID {} for '{}'";
197165

198-
// ============================================================================
199-
// Service Management Constants
200-
// ============================================================================
201-
202166
/// Deployment strategies for service restarts.
203167
///
204168
/// This enum provides type-safe handling of deployment strategies, ensuring

src/metrics/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,47 @@ const DEFAULT_MAX_MEMORY_BYTES: usize = 10 * 1024 * 1024;
3131
/// Sample collected for a managed unit at a specific timestamp.
3232
#[derive(Debug, Clone, Serialize, Deserialize)]
3333
pub struct MetricSample {
34+
/// Timestamp when this sample was collected.
3435
pub timestamp: DateTime<Utc>,
36+
/// CPU usage percentage (0-100+ for multi-core).
3537
pub cpu_percent: f32,
38+
/// Resident set size in bytes.
3639
pub rss_bytes: u64,
40+
/// Total bytes read from disk.
3741
pub io_read_bytes: u64,
42+
/// Total bytes written to disk.
3843
pub io_write_bytes: u64,
44+
/// Total bytes received from network.
3945
pub net_rx_bytes: u64,
46+
/// Total bytes transmitted to network.
4047
pub net_tx_bytes: u64,
4148
}
4249

4350
/// Summary statistics derived from recent samples.
4451
#[derive(Debug, Clone, Serialize, Deserialize)]
4552
pub struct MetricsSummary {
53+
/// Most recent CPU usage percentage.
4654
pub latest_cpu_percent: f32,
55+
/// Average CPU usage across all samples.
4756
pub average_cpu_percent: f32,
57+
/// Maximum CPU usage observed.
4858
pub max_cpu_percent: f32,
59+
/// Most recent resident set size in bytes.
4960
pub latest_rss_bytes: u64,
61+
/// Total number of samples used for statistics.
5062
pub samples: usize,
5163
}
5264

5365
/// Configuration for runtime metrics collection.
5466
#[derive(Debug, Clone)]
5567
pub struct MetricsSettings {
68+
/// How long to retain metrics in memory.
5669
pub retention: Duration,
70+
/// Interval between metric samples.
5771
pub sample_interval: Duration,
72+
/// Maximum memory used for metrics storage.
5873
pub max_memory_bytes: usize,
74+
/// Optional spillover configuration for disk persistence.
5975
pub spillover: Option<SpilloverSettings>,
6076
}
6177

@@ -73,17 +89,24 @@ impl Default for MetricsSettings {
7389
/// Spillover configuration used to persist evicted samples to disk.
7490
#[derive(Debug, Clone)]
7591
pub struct SpilloverSettings {
92+
/// Directory where spillover segments are written.
7693
pub directory: PathBuf,
94+
/// Maximum total bytes allowed for spillover storage.
7795
pub max_bytes: u64,
96+
/// Target size for individual spillover segment files.
7897
pub segment_bytes: u64,
7998
}
8099

100+
/// Errors that can occur during metrics operations.
81101
#[derive(Debug, Error)]
82102
pub enum MetricsError {
103+
/// Failed to create spillover directory.
83104
#[error("failed to create spillover directory: {0}")]
84105
CreateDir(std::io::Error),
106+
/// Failed to write spillover segment to disk.
85107
#[error("failed to write spillover segment: {0}")]
86108
SpilloverWrite(std::io::Error),
109+
/// Failed to serialize spillover record.
87110
#[error("failed to serialise spillover record: {0}")]
88111
SpilloverSerialize(serde_json::Error),
89112
}
@@ -440,21 +463,26 @@ struct SpilloverRecord<'a> {
440463
sample: &'a MetricSample,
441464
}
442465

466+
/// Creates a new shared, thread-safe metrics store with the given settings.
443467
pub fn shared_store(settings: MetricsSettings) -> Result<MetricsHandle, MetricsError> {
444468
Ok(Arc::new(RwLock::new(MetricsStore::new(settings)?)))
445469
}
446470

447471
/// Unit metadata used by the collector to emit samples.
448472
#[derive(Debug)]
449473
pub struct UnitTarget {
474+
/// Unique hash identifying the unit.
450475
pub hash: String,
476+
/// Process ID if the unit has a running process.
451477
pub pid: Option<u32>,
452478
}
453479

454480
/// Result of sampling a unit in the collector.
455481
#[derive(Debug)]
456482
pub struct CollectedSample {
483+
/// Hash of the unit that was sampled.
457484
pub hash: String,
485+
/// Collected metric sample data.
458486
pub sample: MetricSample,
459487
}
460488

src/status/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,37 @@ pub enum StatusError {
7575
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
7676
#[serde(rename_all = "snake_case")]
7777
pub enum OverallHealth {
78+
/// All services are running as expected.
7879
Healthy,
80+
/// Some services are not functioning properly, but system is operational.
7981
Degraded,
82+
/// Critical services are failing, system health is compromised.
8083
Failing,
8184
}
8285

8386
/// Describes what type of unit is represented by a status entry.
8487
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
8588
#[serde(rename_all = "snake_case")]
8689
pub enum UnitKind {
90+
/// Regular service managed by the supervisor.
8791
Service,
92+
/// Cron-scheduled job that runs at specified intervals.
8893
Cron,
94+
/// Orphaned process from a removed or renamed service.
8995
Orphaned,
9096
}
9197

9298
/// Health classification for a specific unit.
9399
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
94100
#[serde(rename_all = "snake_case")]
95101
pub enum UnitHealth {
102+
/// Unit is operating normally.
96103
Healthy,
104+
/// Unit is operational but experiencing issues.
97105
Degraded,
106+
/// Unit is not functioning properly.
98107
Failing,
108+
/// Unit is currently inactive or stopped.
99109
Inactive,
100110
}
101111

@@ -1283,12 +1293,16 @@ pub fn format_elapsed(total_seconds: u64) -> String {
12831293
}
12841294
}
12851295

1296+
/// Represents the state of a process in the system.
12861297
#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
12871298
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
12881299
#[serde(rename_all = "snake_case")]
12891300
pub enum ProcessState {
1301+
/// Process is currently running.
12901302
Running,
1303+
/// Process has terminated but not been reaped by its parent.
12911304
Zombie,
1305+
/// Process is not found in the process table.
12921306
Missing,
12931307
}
12941308

src/test_utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ use std::sync::{Mutex, OnceLock};
55
/// to prevent race conditions between parallel test executions.
66
pub static ENV_LOCK: OnceLock<Mutex<()>> = OnceLock::new();
77

8+
/// Acquires the global environment lock for safe environment variable modifications in tests.
9+
///
10+
/// This function should be called by any test that modifies environment variables
11+
/// to prevent race conditions in parallel test execution.
812
pub fn env_lock() -> std::sync::MutexGuard<'static, ()> {
913
ENV_LOCK
1014
.get_or_init(|| Mutex::new(()))

0 commit comments

Comments
 (0)