@@ -65,8 +65,13 @@ func resourceMonitorAPI(t *testing.T) (*agentapi.ResourcesMonitoringAPI, databas
65
65
Database : db ,
66
66
NotificationsEnqueuer : notifyEnq ,
67
67
Config : resourcesmonitor.Config {
68
- MinimumNOKsToAlert : 4 ,
69
- ConsecutiveNOKsToAlert : 10 ,
68
+ NumDatapoints : 20 ,
69
+ CollectionInterval : 10 * time .Second ,
70
+
71
+ Alert : resourcesmonitor.AlertConfig {
72
+ MinimumNOKsPercent : 20 ,
73
+ ConsecutiveNOKsPercent : 50 ,
74
+ },
70
75
},
71
76
Debounce : 1 * time .Minute ,
72
77
}, user , clock , notifyEnq
@@ -87,7 +92,7 @@ func TestMemoryResourceMonitorDebounce(t *testing.T) {
87
92
// 5. OK -> NOK |> sends a notification as debounce period exceeded
88
93
89
94
api , user , clock , notifyEnq := resourceMonitorAPI (t )
90
- api .Config .ConsecutiveNOKsToAlert = 1
95
+ api .Config .Alert . ConsecutiveNOKsPercent = 100
91
96
92
97
// Given: A monitor in an OK state
93
98
dbgen .WorkspaceAgentMemoryResourceMonitor (t , api .Database , database.WorkspaceAgentMemoryResourceMonitor {
@@ -281,8 +286,6 @@ func TestMemoryResourceMonitor(t *testing.T) {
281
286
t .Parallel ()
282
287
283
288
api , user , clock , notifyEnq := resourceMonitorAPI (t )
284
- api .Config .MinimumNOKsToAlert = 4
285
- api .Config .ConsecutiveNOKsToAlert = 10
286
289
287
290
datapoints := make ([]* agentproto.PushResourcesMonitoringUsageRequest_Datapoint , 0 , len (tt .memoryUsage ))
288
291
collectedAt := clock .Now ()
@@ -327,8 +330,8 @@ func TestMemoryResourceMonitorMissingData(t *testing.T) {
327
330
t .Parallel ()
328
331
329
332
api , _ , clock , notifyEnq := resourceMonitorAPI (t )
330
- api .Config .ConsecutiveNOKsToAlert = 2
331
- api .Config .MinimumNOKsToAlert = 10
333
+ api .Config .Alert . ConsecutiveNOKsPercent = 50
334
+ api .Config .Alert . MinimumNOKsPercent = 100
332
335
333
336
// Given: A monitor in an OK state.
334
337
dbgen .WorkspaceAgentMemoryResourceMonitor (t , api .Database , database.WorkspaceAgentMemoryResourceMonitor {
@@ -376,8 +379,8 @@ func TestMemoryResourceMonitorMissingData(t *testing.T) {
376
379
t .Parallel ()
377
380
378
381
api , _ , clock , _ := resourceMonitorAPI (t )
379
- api .Config .ConsecutiveNOKsToAlert = 2
380
- api .Config .MinimumNOKsToAlert = 10
382
+ api .Config .Alert . ConsecutiveNOKsPercent = 50
383
+ api .Config .Alert . MinimumNOKsPercent = 100
381
384
382
385
// Given: A monitor in a NOK state.
383
386
dbgen .WorkspaceAgentMemoryResourceMonitor (t , api .Database , database.WorkspaceAgentMemoryResourceMonitor {
@@ -448,7 +451,6 @@ func TestVolumeResourceMonitorDebounce(t *testing.T) {
448
451
secondVolumePath := "/dev/coder"
449
452
450
453
api , _ , clock , notifyEnq := resourceMonitorAPI (t )
451
- api .Config .MinimumNOKsToAlert = 1
452
454
453
455
// Given:
454
456
// - First monitor in an OK state
@@ -627,17 +629,13 @@ func TestVolumeResourceMonitor(t *testing.T) {
627
629
previousState database.WorkspaceAgentMonitorState
628
630
expectState database.WorkspaceAgentMonitorState
629
631
shouldNotify bool
630
- minimumNOKs int
631
- consecutiveNOKs int
632
632
}{
633
633
{
634
634
name : "WhenOK/NeverExceedsThreshold" ,
635
635
volumePath : "/home/coder" ,
636
636
volumeUsage : []int64 {2 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 2 , 3 , 1 , 2 },
637
637
volumeTotal : 10 ,
638
638
thresholdPercent : 80 ,
639
- consecutiveNOKs : 4 ,
640
- minimumNOKs : 10 ,
641
639
previousState : database .WorkspaceAgentMonitorStateOK ,
642
640
expectState : database .WorkspaceAgentMonitorStateOK ,
643
641
shouldNotify : false ,
@@ -648,8 +646,6 @@ func TestVolumeResourceMonitor(t *testing.T) {
648
646
volumeUsage : []int64 {9 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 2 , 3 , 1 , 2 },
649
647
volumeTotal : 10 ,
650
648
thresholdPercent : 80 ,
651
- consecutiveNOKs : 4 ,
652
- minimumNOKs : 10 ,
653
649
previousState : database .WorkspaceAgentMonitorStateOK ,
654
650
expectState : database .WorkspaceAgentMonitorStateOK ,
655
651
shouldNotify : false ,
@@ -660,8 +656,6 @@ func TestVolumeResourceMonitor(t *testing.T) {
660
656
volumeUsage : []int64 {2 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 8 , 9 , 8 , 9 },
661
657
volumeTotal : 10 ,
662
658
thresholdPercent : 80 ,
663
- consecutiveNOKs : 4 ,
664
- minimumNOKs : 10 ,
665
659
previousState : database .WorkspaceAgentMonitorStateOK ,
666
660
expectState : database .WorkspaceAgentMonitorStateNOK ,
667
661
shouldNotify : true ,
@@ -672,8 +666,6 @@ func TestVolumeResourceMonitor(t *testing.T) {
672
666
volumeUsage : []int64 {2 , 8 , 2 , 9 , 2 , 8 , 2 , 9 , 2 , 8 , 4 , 9 , 1 , 8 , 2 , 8 , 9 },
673
667
volumeTotal : 10 ,
674
668
thresholdPercent : 80 ,
675
- minimumNOKs : 4 ,
676
- consecutiveNOKs : 10 ,
677
669
previousState : database .WorkspaceAgentMonitorStateOK ,
678
670
expectState : database .WorkspaceAgentMonitorStateNOK ,
679
671
shouldNotify : true ,
@@ -684,8 +676,6 @@ func TestVolumeResourceMonitor(t *testing.T) {
684
676
volumeUsage : []int64 {2 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 2 , 3 , 1 , 2 },
685
677
volumeTotal : 10 ,
686
678
thresholdPercent : 80 ,
687
- consecutiveNOKs : 4 ,
688
- minimumNOKs : 10 ,
689
679
previousState : database .WorkspaceAgentMonitorStateNOK ,
690
680
expectState : database .WorkspaceAgentMonitorStateOK ,
691
681
shouldNotify : false ,
@@ -696,8 +686,6 @@ func TestVolumeResourceMonitor(t *testing.T) {
696
686
volumeUsage : []int64 {9 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 2 , 3 , 1 , 2 },
697
687
volumeTotal : 10 ,
698
688
thresholdPercent : 80 ,
699
- consecutiveNOKs : 4 ,
700
- minimumNOKs : 10 ,
701
689
previousState : database .WorkspaceAgentMonitorStateNOK ,
702
690
expectState : database .WorkspaceAgentMonitorStateNOK ,
703
691
shouldNotify : false ,
@@ -708,8 +696,6 @@ func TestVolumeResourceMonitor(t *testing.T) {
708
696
volumeUsage : []int64 {2 , 3 , 2 , 4 , 2 , 3 , 2 , 1 , 2 , 3 , 4 , 4 , 1 , 8 , 9 , 8 , 9 },
709
697
volumeTotal : 10 ,
710
698
thresholdPercent : 80 ,
711
- consecutiveNOKs : 4 ,
712
- minimumNOKs : 10 ,
713
699
previousState : database .WorkspaceAgentMonitorStateNOK ,
714
700
expectState : database .WorkspaceAgentMonitorStateNOK ,
715
701
shouldNotify : false ,
@@ -720,8 +706,6 @@ func TestVolumeResourceMonitor(t *testing.T) {
720
706
volumeUsage : []int64 {2 , 8 , 2 , 9 , 2 , 8 , 2 , 9 , 2 , 8 , 4 , 9 , 1 , 8 , 2 , 8 , 9 },
721
707
volumeTotal : 10 ,
722
708
thresholdPercent : 80 ,
723
- minimumNOKs : 4 ,
724
- consecutiveNOKs : 10 ,
725
709
previousState : database .WorkspaceAgentMonitorStateNOK ,
726
710
expectState : database .WorkspaceAgentMonitorStateNOK ,
727
711
shouldNotify : false ,
@@ -735,8 +719,6 @@ func TestVolumeResourceMonitor(t *testing.T) {
735
719
t .Parallel ()
736
720
737
721
api , user , clock , notifyEnq := resourceMonitorAPI (t )
738
- api .Config .MinimumNOKsToAlert = tt .minimumNOKs
739
- api .Config .ConsecutiveNOKsToAlert = tt .consecutiveNOKs
740
722
741
723
datapoints := make ([]* agentproto.PushResourcesMonitoringUsageRequest_Datapoint , 0 , len (tt .volumeUsage ))
742
724
collectedAt := clock .Now ()
@@ -785,7 +767,7 @@ func TestVolumeResourceMonitorMultiple(t *testing.T) {
785
767
t .Parallel ()
786
768
787
769
api , _ , clock , notifyEnq := resourceMonitorAPI (t )
788
- api .Config .ConsecutiveNOKsToAlert = 1
770
+ api .Config .Alert . ConsecutiveNOKsPercent = 100
789
771
790
772
// Given: two different volume resource monitors
791
773
dbgen .WorkspaceAgentVolumeResourceMonitor (t , api .Database , database.WorkspaceAgentVolumeResourceMonitor {
@@ -843,8 +825,8 @@ func TestVolumeResourceMonitorMissingData(t *testing.T) {
843
825
volumePath := "/home/coder"
844
826
845
827
api , _ , clock , notifyEnq := resourceMonitorAPI (t )
846
- api .Config .ConsecutiveNOKsToAlert = 2
847
- api .Config .MinimumNOKsToAlert = 10
828
+ api .Config .Alert . ConsecutiveNOKsPercent = 50
829
+ api .Config .Alert . MinimumNOKsPercent = 100
848
830
849
831
// Given: A monitor in an OK state.
850
832
dbgen .WorkspaceAgentVolumeResourceMonitor (t , api .Database , database.WorkspaceAgentVolumeResourceMonitor {
@@ -902,8 +884,8 @@ func TestVolumeResourceMonitorMissingData(t *testing.T) {
902
884
volumePath := "/home/coder"
903
885
904
886
api , _ , clock , _ := resourceMonitorAPI (t )
905
- api .Config .ConsecutiveNOKsToAlert = 2
906
- api .Config .MinimumNOKsToAlert = 10
887
+ api .Config .Alert . ConsecutiveNOKsPercent = 50
888
+ api .Config .Alert . MinimumNOKsPercent = 100
907
889
908
890
// Given: A monitor in a NOK state.
909
891
dbgen .WorkspaceAgentVolumeResourceMonitor (t , api .Database , database.WorkspaceAgentVolumeResourceMonitor {
0 commit comments