@@ -106,6 +106,90 @@ class StatCalculatorTest(
106
106
}
107
107
}
108
108
109
+ `when `("there is a paused monitor - last update before the period") {
110
+
111
+ val enabledUpMonitor = createMonitor(monitorRepository, enabled = true)
112
+ val enabledDownMonitor = createMonitor(monitorRepository, enabled = true)
113
+ val pausedMonitor = createMonitor(monitorRepository, enabled = false)
114
+ val now = getCurrentTimestamp()
115
+
116
+ // enabledUpMonitor's incidents
117
+ createUptimeEventRecord(
118
+ dslContext = dslContext,
119
+ monitorId = enabledUpMonitor.id,
120
+ startedAt = now.minusDays(10),
121
+ status = UptimeStatus .DOWN ,
122
+ endedAt = now.minusDays(5), // 5 days DOWN , 1 day in the period
123
+ )
124
+ createUptimeEventRecord(
125
+ dslContext = dslContext,
126
+ monitorId = enabledUpMonitor.id,
127
+ startedAt = now.minusDays(5),
128
+ status = UptimeStatus .UP ,
129
+ endedAt = null, // 5 days UP
130
+ )
131
+ createSSLEventRecord(
132
+ dslContext = dslContext,
133
+ monitorId = enabledUpMonitor.id,
134
+ status = SslStatus .INVALID ,
135
+ startedAt = now.minusDays(10),
136
+ endedAt = null,
137
+ )
138
+ // enabledDownMonitor's incidents
139
+ createUptimeEventRecord(
140
+ dslContext = dslContext,
141
+ monitorId = enabledDownMonitor.id,
142
+ startedAt = now.minusHours(12),
143
+ status = UptimeStatus .DOWN ,
144
+ endedAt = null, // 0.5 day DOWN
145
+ )
146
+ createSSLEventRecord(
147
+ dslContext = dslContext,
148
+ monitorId = enabledDownMonitor.id,
149
+ status = SslStatus .VALID ,
150
+ startedAt = now.minusDays(10),
151
+ endedAt = null,
152
+ )
153
+ // pausedMonitor's incidents
154
+ createUptimeEventRecord(
155
+ dslContext = dslContext,
156
+ monitorId = pausedMonitor.id,
157
+ startedAt = now.minusDays(12),
158
+ status = UptimeStatus .DOWN ,
159
+ endedAt = null,
160
+ updatedAt = now.minusDays(8),
161
+ )
162
+ createSSLEventRecord(
163
+ dslContext = dslContext,
164
+ monitorId = pausedMonitor.id,
165
+ status = SslStatus .VALID ,
166
+ startedAt = now.minusDays(10),
167
+ endedAt = null,
168
+ updatedAt = now.minusDays(7)
169
+ )
170
+
171
+ then("it should not count the obsolete events from the paused monitor") {
172
+ val stats = statCalculator.calculateOverallHttpStats(Duration .ofDays(6))
173
+ stats.actual.uptimeStats.total shouldBe 3 // 2 enabled monitors + 1 paused monitor
174
+ stats.actual.uptimeStats.down shouldBe 1
175
+ stats.actual.uptimeStats.up shouldBe 1
176
+ stats.actual.uptimeStats.paused shouldBe 1
177
+ stats.actual.uptimeStats.inProgress shouldBe 0
178
+
179
+ stats.actual.sslStats.valid shouldBe 1
180
+ stats.actual.sslStats.invalid shouldBe 1
181
+ stats.actual.sslStats.willExpire shouldBe 0
182
+ stats.actual.sslStats.inProgress shouldBe 0
183
+
184
+ stats.history.uptimeStats.incidents shouldBe 2
185
+ stats.history.uptimeStats.affectedMonitors shouldBe 2
186
+ // 1.5 days DOWN inside the period
187
+ stats.history.uptimeStats.totalDowntimeSeconds shouldBe 36 * 60 * 60
188
+ // 5 days UP, 1.5 days DOWN
189
+ stats.history.uptimeStats.uptimeRatio shouldBe 5 .toDouble() / 6.5
190
+ }
191
+ }
192
+
109
193
`when `("there is a monitor that was just created") {
110
194
111
195
createMonitor(monitorRepository, enabled = true, sslCheckEnabled = true)
@@ -410,6 +494,7 @@ class StatCalculatorTest(
410
494
val upMonitor = createMonitor(monitorRepository, enabled = true)
411
495
val downMonitor = createMonitor(monitorRepository, enabled = true)
412
496
val pausedMonitor = createMonitor(monitorRepository, enabled = false)
497
+ val pausedMonitor2 = createMonitor(monitorRepository, enabled = false)
413
498
414
499
// upMonitor's events: UP
415
500
createUptimeEventRecord(
@@ -447,6 +532,16 @@ class StatCalculatorTest(
447
532
endedAt = now.minusDays(2),
448
533
)
449
534
535
+ // pausedMonitor2's events: DOWN, but update date is before the period, so it should not be counted
536
+ createUptimeEventRecord(
537
+ dslContext = dslContext,
538
+ monitorId = pausedMonitor2.id,
539
+ startedAt = now.minusDays(10),
540
+ status = UptimeStatus .DOWN ,
541
+ endedAt = null,
542
+ updatedAt = now.minusDays(7),
543
+ )
544
+
450
545
then("it should correctly calculate the stats for all statuses") {
451
546
val statsOfInProgressUpMonitor = statCalculator.calculateHistoricalHttpUptimeStats(
452
547
period = Duration .ofDays(6),
@@ -483,6 +578,15 @@ class StatCalculatorTest(
483
578
statsOfPausedMonitor.affectedMonitors shouldBe 1
484
579
statsOfPausedMonitor.totalDowntimeSeconds shouldBe 24 * 60 * 60 // 1 day
485
580
statsOfPausedMonitor.uptimeRatio shouldBe 0.5
581
+
582
+ val statsOfPausedMonitor2 = statCalculator.calculateHistoricalHttpUptimeStats(
583
+ period = Duration .ofDays(6),
584
+ monitorId = pausedMonitor2.id,
585
+ )
586
+ statsOfPausedMonitor2.incidents shouldBe 0
587
+ statsOfPausedMonitor2.affectedMonitors shouldBe 0
588
+ statsOfPausedMonitor2.totalDowntimeSeconds shouldBe 0
589
+ statsOfPausedMonitor2.uptimeRatio shouldBe null
486
590
}
487
591
}
488
592
}
0 commit comments