@@ -84,6 +84,7 @@ func TestMemoryResourceMonitorDebounce(t *testing.T) {
84
84
// 5. OK -> NOK |> sends a notification as debounce period exceeded
85
85
86
86
api , user , clock , notifyEnq := resourceMonitorAPI (t )
87
+ api .ConsecutiveNOKsToAlert = 1
87
88
88
89
// Given: A monitor in an OK state
89
90
dbgen .WorkspaceAgentMemoryResourceMonitor (t , api .Database , database.WorkspaceAgentMemoryResourceMonitor {
@@ -197,103 +198,76 @@ func TestMemoryResourceMonitor(t *testing.T) {
197
198
t .Parallel ()
198
199
199
200
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
209
207
}{
210
208
{
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 ,
220
215
},
221
216
{
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 ,
231
223
},
232
224
{
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 ,
242
231
},
243
232
{
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 ,
253
239
},
254
240
{
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 ,
264
247
},
265
248
{
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 ,
275
255
},
276
256
{
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 ,
286
263
},
287
264
{
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 ,
297
271
},
298
272
}
299
273
@@ -304,8 +278,8 @@ func TestMemoryResourceMonitor(t *testing.T) {
304
278
t .Parallel ()
305
279
306
280
api , user , clock , notifyEnq := resourceMonitorAPI (t )
307
- api .MinimumNOKsToAlert = tt . minimumNOKs
308
- api .ConsecutiveNOKsToAlert = tt . consecutiveNOKs
281
+ api .MinimumNOKsToAlert = 4
282
+ api .ConsecutiveNOKsToAlert = 10
309
283
310
284
datapoints := make ([]* agentproto.PushResourcesMonitoringUsageRequest_Datapoint , 0 , len (tt .memoryUsage ))
311
285
collectedAt := clock .Now ()
@@ -323,7 +297,7 @@ func TestMemoryResourceMonitor(t *testing.T) {
323
297
dbgen .WorkspaceAgentMemoryResourceMonitor (t , api .Database , database.WorkspaceAgentMemoryResourceMonitor {
324
298
AgentID : api .AgentID ,
325
299
State : tt .previousState ,
326
- Threshold : tt . thresholdPercent ,
300
+ Threshold : 80 ,
327
301
})
328
302
329
303
clock .Set (collectedAt )
@@ -373,6 +347,7 @@ func TestVolumeResourceMonitorDebounce(t *testing.T) {
373
347
secondVolumePath := "/dev/coder"
374
348
375
349
api , _ , clock , notifyEnq := resourceMonitorAPI (t )
350
+ api .MinimumNOKsToAlert = 1
376
351
377
352
// Given:
378
353
// - First monitor in an OK state
@@ -709,6 +684,7 @@ func TestVolumeResourceMonitorMultiple(t *testing.T) {
709
684
t .Parallel ()
710
685
711
686
api , _ , clock , notifyEnq := resourceMonitorAPI (t )
687
+ api .ConsecutiveNOKsToAlert = 1
712
688
713
689
// Given: two different volume resource monitors
714
690
dbgen .WorkspaceAgentVolumeResourceMonitor (t , api .Database , database.WorkspaceAgentVolumeResourceMonitor {
0 commit comments