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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
//! # Incident Metrics
//!
//! Incident response time decomposes into distinct phases: **mean time to
//! detect (MTTD)**, how long before the organization notices something is
//! wrong; **mean time to acknowledge (MTTA)**, how long before someone takes
//! ownership of responding; and **mean time to resolve or recover (MTTR)**,
//! how long from ownership to genuine recovery. Reporting these separately,
//! rather than only a single blended total, matters because each phase
//! points to a different fix: slow detection points to a monitoring gap,
//! slow acknowledgement points to an on-call process gap, and slow
//! resolution points to a tooling or runbook gap.
//!
//! ## Formula
//!
//! ```text
//! MTTD = mean(detection durations)
//! MTTA = mean(acknowledgement durations)
//! MTTR = mean(resolution durations)
//! Mean duration = mean(total incident durations)
//! ```
//!
//! ## Why it matters
//!
//! Track incident frequency and MTTR together, never in isolation, mirroring
//! DORA's speed-and-stability pairing discipline: an improving MTTR
//! alongside a rising incident frequency might indicate a team getting
//! better at firefighting while underlying reliability actually degrades, and
//! a falling frequency alongside a worsening MTTR might indicate rarer but
//! more severe, harder-to-diagnose failures replacing frequent minor ones.
//! Reviewing both together, rather than either alone, is what gives an
//! honest combined picture.
//!
//! ## Example
//!
//! ```rust
//! use software_engineering::incident_metrics::{
//! mean_time_to_detect_minutes, mean_time_to_acknowledge_minutes,
//! mean_time_to_resolve_minutes, mean_incident_duration_minutes,
//! };
//!
//! let detection = [5.0, 15.0];
//! let acknowledgement = [2.0, 4.0];
//! let resolution = [30.0, 90.0];
//! let total = [37.0, 109.0];
//!
//! assert_eq!(mean_time_to_detect_minutes(&detection), Some(10.0));
//! assert_eq!(mean_time_to_acknowledge_minutes(&acknowledgement), Some(3.0));
//! assert_eq!(mean_time_to_resolve_minutes(&resolution), Some(60.0));
//! assert_eq!(mean_incident_duration_minutes(&total), Some(73.0));
//! ```
//!
//! ## Pitfalls
//!
//! - **Reporting only a single blended total** instead of the three
//! decomposed phases — hides which specific gap (monitoring, on-call
//! process, or tooling) is driving a slow response.
//! - **Reviewing incident frequency and MTTR in isolation** — misses the
//! pattern where one metric's improvement masks the other's decline.
//! - **Inconsistent severity classification across teams** — makes
//! organization-wide incident data as unreliable for comparison as
//! inconsistently classified defect data.
//! - **Extracting no systemic action items from postmortems** — produces
//! insight with no follow-through, wasting the organizational learning
//! the process is meant to capture.
//!
//! ## Sources
//!
//! - Chapter 6.2, Incident metrics.
//!
//! Topic doc: software-engineering-metrics/locales/en-001/chapters/06-02-incident-metrics.md
/// The arithmetic mean of a slice of per-incident durations, in minutes.
///
/// Shared by all four public functions in this module, each of which
/// applies it to a different phase of incident response.
/// Mean time to detect (MTTD): the mean, across incidents, of the duration
/// from a failure's actual onset to someone noticing it.
///
/// # Arguments
///
/// * `detection_durations_minutes` — per-incident detection durations, in
/// minutes.
///
/// # Returns
///
/// The mean detection duration, or `None` if the slice is empty.
///
/// # Examples
///
/// ```rust
/// use software_engineering::incident_metrics::mean_time_to_detect_minutes;
///
/// assert_eq!(mean_time_to_detect_minutes(&[5.0, 15.0]), Some(10.0));
/// assert_eq!(mean_time_to_detect_minutes(&[]), None);
/// ```
/// Mean time to acknowledge (MTTA): the mean, across incidents, of the
/// duration from notification to someone taking ownership of the response.
///
/// # Arguments
///
/// * `acknowledgement_durations_minutes` — per-incident acknowledgement
/// durations, in minutes.
///
/// # Returns
///
/// The mean acknowledgement duration, or `None` if the slice is empty.
///
/// # Examples
///
/// ```rust
/// use software_engineering::incident_metrics::mean_time_to_acknowledge_minutes;
///
/// assert_eq!(mean_time_to_acknowledge_minutes(&[2.0, 4.0]), Some(3.0));
/// assert_eq!(mean_time_to_acknowledge_minutes(&[]), None);
/// ```
/// Mean time to resolve or recover (MTTR): the mean, across incidents, of
/// the duration from ownership to genuine recovery.
///
/// # Arguments
///
/// * `resolution_durations_minutes` — per-incident resolution durations, in
/// minutes.
///
/// # Returns
///
/// The mean resolution duration, or `None` if the slice is empty.
///
/// # Examples
///
/// ```rust
/// use software_engineering::incident_metrics::mean_time_to_resolve_minutes;
///
/// assert_eq!(mean_time_to_resolve_minutes(&[30.0, 90.0]), Some(60.0));
/// assert_eq!(mean_time_to_resolve_minutes(&[]), None);
/// ```
/// Mean total incident duration, from detection start to full resolution —
/// the blended total to report *alongside*, never instead of, the three
/// decomposed phases above.
///
/// # Arguments
///
/// * `total_durations_minutes` — per-incident total durations, in minutes.
///
/// # Returns
///
/// The mean total duration, or `None` if the slice is empty.
///
/// # Examples
///
/// ```rust
/// use software_engineering::incident_metrics::mean_incident_duration_minutes;
///
/// assert_eq!(mean_incident_duration_minutes(&[37.0, 109.0]), Some(73.0));
/// assert_eq!(mean_incident_duration_minutes(&[]), None);
/// ```