fix(evaluate): a region without results no longer keeps a monitor up
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / test (pull_request) Successful in 9m3s
ci / lint (pull_request) Successful in 10m9s
ci / build (pull_request) Successful in 9m54s
ci / image (pull_request) Successful in 3m16s
ci / lint (push) Skipped
ci / test (push) Skipped
ci / build (push) Skipped
ci / image (push) Skipped
ci / test (pull_request) Successful in 9m3s
ci / lint (pull_request) Successful in 10m9s
ci / build (pull_request) Successful in 9m54s
ci / image (pull_request) Successful in 3m16s
A monitor went down only when every assigned region had failed and reported recently, so one region whose checkers were gone kept a monitor up for good, even while all other regions reported its target failing. Regions without recent results are now left out: a monitor goes down when every region that reported recently has failed. One region failing while another succeeds still does not alert, and with every region silent nothing is judged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
4d03a86614
commit
2054660625
5 files changed
+38
-16
No files matched your search
@@ -1,9 +1,11 @@
|
||||
// Package evaluate turns per-region check results into a monitor state.
|
||||
//
|
||||
// A monitor goes down only when every region it is assigned to has failed
|
||||
// the configured number of times in a row and reported recently. A region
|
||||
// without recent results counts as unknown and keeps the monitor up: one
|
||||
// checker losing its network must not page anyone. Any successful region
|
||||
// A monitor goes down when every region it is assigned to that reported
|
||||
// recently has failed the configured number of times in a row: one region
|
||||
// failing while another succeeds is the checker's problem, not the
|
||||
// target's. A region without recent results counts as unknown and is left
|
||||
// out, so a dead region neither keeps a monitor up nor takes it down; with
|
||||
// every region unknown nothing is judged at all. Any successful region
|
||||
// brings the monitor back up.
|
||||
//
|
||||
// The state lives in Redis and each observation is applied by one Lua
|
||||
@@ -86,12 +88,17 @@ if state == 'down' then
|
||||
end
|
||||
return 'none'
|
||||
end
|
||||
local reporting = 0
|
||||
for i = 7, #ARGV do
|
||||
local r = ARGV[i]
|
||||
local fails = tonumber(redis.call('HGET', key, 'f:' .. r) or '0')
|
||||
local seen = tonumber(redis.call('HGET', key, 'a:' .. r) or '0')
|
||||
if fails < need or seen < stale then return 'none' end
|
||||
if seen >= stale then
|
||||
local fails = tonumber(redis.call('HGET', key, 'f:' .. r) or '0')
|
||||
if fails < need then return 'none' end
|
||||
reporting = reporting + 1
|
||||
end
|
||||
end
|
||||
if reporting == 0 then return 'none' end
|
||||
redis.call('HSET', key, 'state', 'down')
|
||||
return 'down'
|
||||
`)
|
||||
|
||||
@@ -55,9 +55,9 @@ func play(t *testing.T, e *Evaluator, now *time.Time, regions []string, confirma
|
||||
func TestDownOnlyWhenAllRegionsFail(t *testing.T) {
|
||||
e, now := newTest(t)
|
||||
play(t, e, now, []string{"eu", "us"}, 2, []step{
|
||||
{"eu", false, None},
|
||||
{"eu", false, None}, // eu confirmed down, us has not reported
|
||||
{"us", true, None},
|
||||
{"eu", false, None},
|
||||
{"eu", false, None}, // eu confirmed down, us still fine
|
||||
{"us", false, None},
|
||||
{"eu", false, None},
|
||||
{"us", false, Down}, // both regions failed twice in a row
|
||||
@@ -79,7 +79,7 @@ func TestSingleRegionWithConfirmations(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestSilentRegionBlocksAlert(t *testing.T) {
|
||||
func TestSilentRegionIsLeftOut(t *testing.T) {
|
||||
e, now := newTest(t)
|
||||
id := uuid.New()
|
||||
obs := func(region string, ok bool) Transition {
|
||||
@@ -92,12 +92,27 @@ func TestSilentRegionBlocksAlert(t *testing.T) {
|
||||
}
|
||||
return got
|
||||
}
|
||||
obs("us", false)
|
||||
// us stops reporting for longer than three intervals.
|
||||
obs("us", true)
|
||||
// us stops reporting for longer than three intervals: the failures of
|
||||
// eu alone decide.
|
||||
*now = now.Add(5 * time.Minute)
|
||||
if got := obs("eu", false); got != None {
|
||||
t.Errorf("eu failure with us silent = %v, want none", got)
|
||||
if got := obs("eu", false); got != Down {
|
||||
t.Errorf("eu failure with us silent = %v, want down", got)
|
||||
}
|
||||
// us reporting a success again brings the monitor back up.
|
||||
*now = now.Add(time.Second)
|
||||
if got := obs("us", true); got != Up {
|
||||
t.Errorf("us success after the outage = %v, want up", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReportingRegionStillVetoes(t *testing.T) {
|
||||
e, now := newTest(t)
|
||||
play(t, e, now, []string{"eu", "us"}, 1, []step{
|
||||
{"us", true, None},
|
||||
{"eu", false, None}, // us reported recently and was fine
|
||||
{"eu", false, None},
|
||||
})
|
||||
}
|
||||
|
||||
func TestOutOfOrderResultIgnored(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user