1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#![cfg_attr(coverage_nightly, coverage(off))]
//! Worker monitoring system for distributed mutation testing
//!
//! Provides a worker state tracking and monitoring system that ensures
//! distributed mutation testing is reliable, observable, and recoverable.
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::sync::RwLock;
/// Current state of a worker
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum WorkerState {
/// Worker is idle and available for work
Idle,
/// Worker is currently processing a task
Processing,
/// Worker has failed
Failed,
/// Worker has been terminated
Terminated,
}
/// Metrics for a single worker
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WorkerMetrics {
/// Worker ID
pub id: usize,
/// Current state of the worker
pub state: WorkerState,
/// Number of tasks processed successfully
pub processed_count: usize,
/// Number of tasks that failed
pub failed_count: usize,
/// When the worker was last active (sent heartbeat)
#[serde(skip, default = "Instant::now")]
pub last_heartbeat: Instant,
/// Most recent error messages (up to 5)
pub recent_errors: Vec<String>,
/// Average processing time (ms)
pub avg_processing_time_ms: f64,
/// Number of heartbeats received
pub heartbeat_count: usize,
/// Custom metrics specific to this worker
pub custom_metrics: HashMap<String, String>,
}
/// Monitor tracking all workers in the distributed system
pub struct WorkerMonitor {
/// Collection of worker metrics
workers: RwLock<HashMap<usize, WorkerMetrics>>,
/// Timeout for considering a worker stalled
stall_timeout: Duration,
/// Total number of workers
worker_count: usize,
}
// WorkerMetrics method implementations
include!("worker_monitor_tracking.rs");
// WorkerMonitor method implementations
include!("worker_monitor_operations.rs");
// Tests
include!("worker_monitor_tests.rs");