@@ -84,6 +84,7 @@ func TestMemoryResourceMonitorDebounce(t *testing.T) {
8484 // 5. OK -> NOK |> sends a notification as debounce period exceeded
8585
8686 api , user , clock , notifyEnq := resourceMonitorAPI (t )
87+ api .ConsecutiveNOKsToAlert = 1
8788
8889 // Given: A monitor in an OK state
8990 dbgen .WorkspaceAgentMemoryResourceMonitor (t , api .Database , database.WorkspaceAgentMemoryResourceMonitor {
@@ -197,103 +198,76 @@ func TestMemoryResourceMonitor(t *testing.T) {
197198 t .Parallel ()
198199
199200 tests := []struct {
200- name string
201- memoryUsage []int64
202- memoryTotal int64
203- thresholdPercent int32
204- minimumNOKs int
205- consecutiveNOKs int
206- previousState database.WorkspaceAgentMonitorState
207- expectState database.WorkspaceAgentMonitorState
208- shouldNotify bool
201+ name string
202+ memoryUsage []int64
203+ memoryTotal int64
204+ previousState database.WorkspaceAgentMonitorState
205+ expectState database.WorkspaceAgentMonitorState
206+ shouldNotify bool
209207 }{
210208 {
211- name : "WhenOK/NeverExceedsThreshold" ,
212- memoryUsage : []int64 {2 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 2 , 3 , 1 , 2 },
213- memoryTotal : 10 ,
214- thresholdPercent : 80 ,
215- consecutiveNOKs : 4 ,
216- minimumNOKs : 10 ,
217- previousState : database .WorkspaceAgentMonitorStateOK ,
218- expectState : database .WorkspaceAgentMonitorStateOK ,
219- shouldNotify : false ,
209+ name : "WhenOK/NeverExceedsThreshold" ,
210+ memoryUsage : []int64 {2 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 2 , 3 , 1 , 2 },
211+ memoryTotal : 10 ,
212+ previousState : database .WorkspaceAgentMonitorStateOK ,
213+ expectState : database .WorkspaceAgentMonitorStateOK ,
214+ shouldNotify : false ,
220215 },
221216 {
222- name : "WhenOK/ShouldStayInOK" ,
223- memoryUsage : []int64 {9 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 2 , 3 , 1 , 2 },
224- memoryTotal : 10 ,
225- thresholdPercent : 80 ,
226- consecutiveNOKs : 4 ,
227- minimumNOKs : 10 ,
228- previousState : database .WorkspaceAgentMonitorStateOK ,
229- expectState : database .WorkspaceAgentMonitorStateOK ,
230- shouldNotify : false ,
217+ name : "WhenOK/ShouldStayInOK" ,
218+ memoryUsage : []int64 {9 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 2 , 3 , 1 , 2 },
219+ memoryTotal : 10 ,
220+ previousState : database .WorkspaceAgentMonitorStateOK ,
221+ expectState : database .WorkspaceAgentMonitorStateOK ,
222+ shouldNotify : false ,
231223 },
232224 {
233- name : "WhenOK/ConsecutiveExceedsThreshold" ,
234- memoryUsage : []int64 {2 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 8 , 9 , 8 , 9 },
235- memoryTotal : 10 ,
236- thresholdPercent : 80 ,
237- consecutiveNOKs : 4 ,
238- minimumNOKs : 10 ,
239- previousState : database .WorkspaceAgentMonitorStateOK ,
240- expectState : database .WorkspaceAgentMonitorStateNOK ,
241- shouldNotify : true ,
225+ name : "WhenOK/ConsecutiveExceedsThreshold" ,
226+ memoryUsage : []int64 {2 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 8 , 9 , 8 , 9 },
227+ memoryTotal : 10 ,
228+ previousState : database .WorkspaceAgentMonitorStateOK ,
229+ expectState : database .WorkspaceAgentMonitorStateNOK ,
230+ shouldNotify : true ,
242231 },
243232 {
244- name : "WhenOK/MinimumExceedsThreshold" ,
245- memoryUsage : []int64 {2 , 8 , 2 , 9 , 2 , 8 , 2 , 9 , 2 , 8 , 4 , 9 , 1 , 8 , 2 , 8 , 9 },
246- memoryTotal : 10 ,
247- thresholdPercent : 80 ,
248- minimumNOKs : 4 ,
249- consecutiveNOKs : 10 ,
250- previousState : database .WorkspaceAgentMonitorStateOK ,
251- expectState : database .WorkspaceAgentMonitorStateNOK ,
252- shouldNotify : true ,
233+ name : "WhenOK/MinimumExceedsThreshold" ,
234+ memoryUsage : []int64 {2 , 8 , 2 , 9 , 2 , 8 , 2 , 9 , 2 , 8 , 4 , 9 , 1 , 8 , 2 , 8 , 9 },
235+ memoryTotal : 10 ,
236+ previousState : database .WorkspaceAgentMonitorStateOK ,
237+ expectState : database .WorkspaceAgentMonitorStateNOK ,
238+ shouldNotify : true ,
253239 },
254240 {
255- name : "WhenNOK/NeverExceedsThreshold" ,
256- memoryUsage : []int64 {2 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 2 , 3 , 1 , 2 },
257- memoryTotal : 10 ,
258- thresholdPercent : 80 ,
259- consecutiveNOKs : 4 ,
260- minimumNOKs : 10 ,
261- previousState : database .WorkspaceAgentMonitorStateNOK ,
262- expectState : database .WorkspaceAgentMonitorStateOK ,
263- shouldNotify : false ,
241+ name : "WhenNOK/NeverExceedsThreshold" ,
242+ memoryUsage : []int64 {2 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 2 , 3 , 1 , 2 },
243+ memoryTotal : 10 ,
244+ previousState : database .WorkspaceAgentMonitorStateNOK ,
245+ expectState : database .WorkspaceAgentMonitorStateOK ,
246+ shouldNotify : false ,
264247 },
265248 {
266- name : "WhenNOK/ShouldStayInNOK" ,
267- memoryUsage : []int64 {9 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 2 , 3 , 1 , 2 },
268- memoryTotal : 10 ,
269- thresholdPercent : 80 ,
270- consecutiveNOKs : 4 ,
271- minimumNOKs : 10 ,
272- previousState : database .WorkspaceAgentMonitorStateNOK ,
273- expectState : database .WorkspaceAgentMonitorStateNOK ,
274- shouldNotify : false ,
249+ name : "WhenNOK/ShouldStayInNOK" ,
250+ memoryUsage : []int64 {9 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 2 , 3 , 1 , 2 },
251+ memoryTotal : 10 ,
252+ previousState : database .WorkspaceAgentMonitorStateNOK ,
253+ expectState : database .WorkspaceAgentMonitorStateNOK ,
254+ shouldNotify : false ,
275255 },
276256 {
277- name : "WhenNOK/ConsecutiveExceedsThreshold" ,
278- memoryUsage : []int64 {2 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 8 , 9 , 8 , 9 },
279- memoryTotal : 10 ,
280- thresholdPercent : 80 ,
281- consecutiveNOKs : 4 ,
282- minimumNOKs : 10 ,
283- previousState : database .WorkspaceAgentMonitorStateNOK ,
284- expectState : database .WorkspaceAgentMonitorStateNOK ,
285- shouldNotify : false ,
257+ name : "WhenNOK/ConsecutiveExceedsThreshold" ,
258+ memoryUsage : []int64 {2 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 8 , 9 , 8 , 9 },
259+ memoryTotal : 10 ,
260+ previousState : database .WorkspaceAgentMonitorStateNOK ,
261+ expectState : database .WorkspaceAgentMonitorStateNOK ,
262+ shouldNotify : false ,
286263 },
287264 {
288- name : "WhenNOK/MinimumExceedsThreshold" ,
289- memoryUsage : []int64 {2 , 8 , 2 , 9 , 2 , 8 , 2 , 9 , 2 , 8 , 4 , 9 , 1 , 8 , 2 , 8 , 9 },
290- memoryTotal : 10 ,
291- thresholdPercent : 80 ,
292- minimumNOKs : 4 ,
293- consecutiveNOKs : 10 ,
294- previousState : database .WorkspaceAgentMonitorStateNOK ,
295- expectState : database .WorkspaceAgentMonitorStateNOK ,
296- shouldNotify : false ,
265+ name : "WhenNOK/MinimumExceedsThreshold" ,
266+ memoryUsage : []int64 {2 , 8 , 2 , 9 , 2 , 8 , 2 , 9 , 2 , 8 , 4 , 9 , 1 , 8 , 2 , 8 , 9 },
267+ memoryTotal : 10 ,
268+ previousState : database .WorkspaceAgentMonitorStateNOK ,
269+ expectState : database .WorkspaceAgentMonitorStateNOK ,
270+ shouldNotify : false ,
297271 },
298272 }
299273
@@ -304,8 +278,8 @@ func TestMemoryResourceMonitor(t *testing.T) {
304278 t .Parallel ()
305279
306280 api , user , clock , notifyEnq := resourceMonitorAPI (t )
307- api .MinimumNOKsToAlert = tt . minimumNOKs
308- api .ConsecutiveNOKsToAlert = tt . consecutiveNOKs
281+ api .MinimumNOKsToAlert = 4
282+ api .ConsecutiveNOKsToAlert = 10
309283
310284 datapoints := make ([]* agentproto.PushResourcesMonitoringUsageRequest_Datapoint , 0 , len (tt .memoryUsage ))
311285 collectedAt := clock .Now ()
@@ -323,7 +297,7 @@ func TestMemoryResourceMonitor(t *testing.T) {
323297 dbgen .WorkspaceAgentMemoryResourceMonitor (t , api .Database , database.WorkspaceAgentMemoryResourceMonitor {
324298 AgentID : api .AgentID ,
325299 State : tt .previousState ,
326- Threshold : tt . thresholdPercent ,
300+ Threshold : 80 ,
327301 })
328302
329303 clock .Set (collectedAt )
@@ -373,6 +347,7 @@ func TestVolumeResourceMonitorDebounce(t *testing.T) {
373347 secondVolumePath := "/dev/coder"
374348
375349 api , _ , clock , notifyEnq := resourceMonitorAPI (t )
350+ api .MinimumNOKsToAlert = 1
376351
377352 // Given:
378353 // - First monitor in an OK state
@@ -709,6 +684,7 @@ func TestVolumeResourceMonitorMultiple(t *testing.T) {
709684 t .Parallel ()
710685
711686 api , _ , clock , notifyEnq := resourceMonitorAPI (t )
687+ api .ConsecutiveNOKsToAlert = 1
712688
713689 // Given: two different volume resource monitors
714690 dbgen .WorkspaceAgentVolumeResourceMonitor (t , api .Database , database.WorkspaceAgentVolumeResourceMonitor {
0 commit comments