@@ -475,7 +475,7 @@ func TestSilenceLimits(t *testing.T) {
475
475
// Insert sil2 should fail because maximum number of silences
476
476
// has been exceeded.
477
477
sil2 := & pb.Silence {
478
- Matchers : []* pb.Matcher {{Name : "a " , Pattern : "b " }},
478
+ Matchers : []* pb.Matcher {{Name : "c " , Pattern : "d " }},
479
479
StartsAt : time .Now (),
480
480
EndsAt : time .Now ().Add (5 * time .Minute ),
481
481
}
@@ -492,10 +492,7 @@ func TestSilenceLimits(t *testing.T) {
492
492
require .NoError (t , s .Set (sil2 ))
493
493
require .NotEqual (t , "" , sil2 .Id )
494
494
495
- // Should be able to update sil2 without hitting the limit.
496
- require .NoError (t , s .Set (sil2 ))
497
-
498
- // Expire sil2.
495
+ // Expire sil2 and run the GC.
499
496
require .NoError (t , s .Expire (sil2 .Id ))
500
497
n , err = s .GC ()
501
498
require .NoError (t , err )
@@ -505,16 +502,16 @@ func TestSilenceLimits(t *testing.T) {
505
502
sil3 := & pb.Silence {
506
503
Matchers : []* pb.Matcher {
507
504
{
508
- Name : strings .Repeat ("a " , 2 << 9 ),
509
- Pattern : strings .Repeat ("b " , 2 << 9 ),
505
+ Name : strings .Repeat ("e " , 2 << 9 ),
506
+ Pattern : strings .Repeat ("f " , 2 << 9 ),
510
507
},
511
508
{
512
- Name : strings .Repeat ("c " , 2 << 9 ),
513
- Pattern : strings .Repeat ("d " , 2 << 9 ),
509
+ Name : strings .Repeat ("g " , 2 << 9 ),
510
+ Pattern : strings .Repeat ("h " , 2 << 9 ),
514
511
},
515
512
},
516
- CreatedBy : strings .Repeat ("e " , 2 << 9 ),
517
- Comment : strings .Repeat ("f " , 2 << 9 ),
513
+ CreatedBy : strings .Repeat ("i " , 2 << 9 ),
514
+ Comment : strings .Repeat ("j " , 2 << 9 ),
518
515
StartsAt : time .Now (),
519
516
EndsAt : time .Now ().Add (5 * time .Minute ),
520
517
}
@@ -523,8 +520,44 @@ func TestSilenceLimits(t *testing.T) {
523
520
// Do not check the exact size as it can change between consecutive runs
524
521
// due to padding.
525
522
require .Contains (t , err .Error (), "silence exceeded maximum size" )
526
- // TODO: Once we fix https://github.com/prometheus/alertmanager/issues/3878 this should be require.Equal.
527
523
require .NotEqual (t , "" , sil3 .Id )
524
+
525
+ // Should be able to insert sil4 and then update it without modifications.
526
+ sil4 := & pb.Silence {
527
+ Matchers : []* pb.Matcher {{Name : "k" , Pattern : "l" }},
528
+ StartsAt : time .Now (),
529
+ EndsAt : time .Now ().Add (5 * time .Minute ),
530
+ }
531
+ require .NoError (t , s .Set (sil4 ))
532
+ require .NotEqual (t , "" , sil4 .Id )
533
+
534
+ // Update without modifications.
535
+ id4 := sil4 .Id
536
+ require .NoError (t , s .Set (sil4 ))
537
+ require .Equal (t , id4 , sil4 .Id )
538
+
539
+ // Should be able to update the comment.
540
+ sil5 := cloneSilence (sil4 )
541
+ sil5 .Comment = "m"
542
+ require .NoError (t , s .Set (sil5 ))
543
+ require .Equal (t , sil4 .Id , sil5 .Id )
544
+
545
+ // Should not be able to update the start and end time as this requires
546
+ // sil5 to be expired and a new silence to be created. However, this would
547
+ // exceed the maximum number of silences, which counts both active and
548
+ // expired silences.
549
+ sil6 := cloneSilence (sil5 )
550
+ sil6 .StartsAt = time .Now ().Add (5 * time .Minute )
551
+ sil6 .EndsAt = time .Now ().Add (10 * time .Minute )
552
+ err = s .Set (sil6 )
553
+ require .Error (t , err )
554
+ require .EqualError (t , err , "exceeded maximum number of silences: 1 (limit: 1)" )
555
+ require .NotEqual (t , "" , sil6 .Id )
556
+
557
+ // sil5 should not be expired because the update failed.
558
+ sil5 , err = s .QueryOne (QIDs (sil5 .Id ))
559
+ require .NoError (t , err )
560
+ require .Equal (t , types .SilenceStateActive , getState (sil5 , s .nowUTC ()))
528
561
}
529
562
530
563
func TestSilenceNoLimits (t * testing.T ) {
0 commit comments