Skip to content

Commit

Permalink
Fix silence tests
Browse files Browse the repository at this point in the history
This commit fixes the silence tests, using the exact same tests
in prometheus/alertmanager to avoid regressions due to modules,
but using the New function in pkg/alertmanager/alertmanager.go
to ensure the correct limits are set.

It bumps go.mod to commit 2410524 which is a no-op as Mimir
does not vendor tests, but its meant to indicate we are using
the fix from prometheus/alertmanager#3866.
  • Loading branch information
grobinson-grafana committed Jun 5, 2024
1 parent 011c02f commit 1b87f97
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,4 @@ replace github.com/opentracing-contrib/go-stdlib => github.com/grafana/opentraci
replace github.com/opentracing-contrib/go-grpc => github.com/charleskorn/go-grpc v0.0.0-20231024023642-e9298576254f

// Replacing prometheus/alertmanager with our fork.
replace github.com/prometheus/alertmanager => github.com/grafana/prometheus-alertmanager v0.25.1-0.20240603081606-9f1bbb0feb0c
replace github.com/prometheus/alertmanager => github.com/grafana/prometheus-alertmanager v0.25.1-0.20240605140724-241052410551
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,8 @@ github.com/grafana/mimir-prometheus v0.0.0-20240515135245-e5b85c151ba8 h1:XmqfG3
github.com/grafana/mimir-prometheus v0.0.0-20240515135245-e5b85c151ba8/go.mod h1:ZlD3SoAHSwXK5VGLHv78Jh5kOpgSLaQAzt9gxq76fLM=
github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956 h1:em1oddjXL8c1tL0iFdtVtPloq2hRPen2MJQKoAWpxu0=
github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956/go.mod h1:qtI1ogk+2JhVPIXVc6q+NHziSmy2W5GbdQZFUHADCBU=
github.com/grafana/prometheus-alertmanager v0.25.1-0.20240603081606-9f1bbb0feb0c h1:Zgf0KrZy6of/6MQTRvzCVvKni/wWxEMWnipeqbo+0ek=
github.com/grafana/prometheus-alertmanager v0.25.1-0.20240603081606-9f1bbb0feb0c/go.mod h1:01sXtHoRwI8W324IPAzuxDFOmALqYLCOhvSC2fUHWXc=
github.com/grafana/prometheus-alertmanager v0.25.1-0.20240605140724-241052410551 h1:nj+Z280xVVSxeW9bbgEs2gxd//gRIwCxQFuSv4oh5MQ=
github.com/grafana/prometheus-alertmanager v0.25.1-0.20240605140724-241052410551/go.mod h1:01sXtHoRwI8W324IPAzuxDFOmALqYLCOhvSC2fUHWXc=
github.com/grafana/pyroscope-go/godeltaprof v0.1.6 h1:nEdZ8louGAplSvIJi1HVp7kWvFvdiiYg3COLlTwJiFo=
github.com/grafana/pyroscope-go/godeltaprof v0.1.6/go.mod h1:Tk376Nbldo4Cha9RgiU7ik8WKFkNpfds98aUzS8omLE=
github.com/grafana/regexp v0.0.0-20240531075221-3685f1377d7b h1:oMAq12GxTpwo9jxbnG/M4F/HdpwbibTaVoxNA0NZprY=
Expand Down
21 changes: 14 additions & 7 deletions pkg/alertmanager/alertmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,7 @@ func testLimiter(t *testing.T, limits Limits, ops []callbackOp) {
}

func TestSilenceLimits(t *testing.T) {
t.Skip()

user := "test"
user := "foo"

r := prometheus.NewPedanticRegistry()
am, err := New(&Config{
Expand All @@ -345,13 +343,14 @@ func TestSilenceLimits(t *testing.T) {
Store: prepareInMemoryAlertStore(),
Replicator: &stubReplicator{},
ReplicationFactor: 1,
// Set the interval to 1s as this test can trigger multiple broadcasts
// creating and expiring silences.
PersisterConfig: PersisterConfig{Interval: time.Second},
PersisterConfig: PersisterConfig{Interval: time.Hour},
}, r)
require.NoError(t, err)
defer am.StopAndWait()

// Override SetBroadcast as we just want to test limits.
am.silences.SetBroadcast(func(_ []byte) {})

// Insert sil1 should succeed without error.
sil1 := &silencepb.Silence{
Matchers: []*silencepb.Matcher{{Name: "a", Pattern: "b"}},
Expand All @@ -373,8 +372,13 @@ func TestSilenceLimits(t *testing.T) {
require.EqualError(t, err, "exceeded maximum number of silences: 1 (limit: 1)")
require.Equal(t, "", id2)

// Expire sil1. This should allow sil2 to be inserted.
// Expire sil1 and run the GC. This should allow sil2 to be
// inserted.
require.NoError(t, am.silences.Expire(id1))
n, err := am.silences.GC()
require.NoError(t, err)
require.Equal(t, 1, n)

id2, err = am.silences.Set(sil2)
require.NoError(t, err)
require.NotEqual(t, "", id2)
Expand All @@ -385,6 +389,9 @@ func TestSilenceLimits(t *testing.T) {

// Expire sil2.
require.NoError(t, am.silences.Expire(id2))
n, err = am.silences.GC()
require.NoError(t, err)
require.Equal(t, 1, n)

// Insert sil3 should fail because it exceeds maximum size.
sil3 := &silencepb.Silence{
Expand Down
4 changes: 2 additions & 2 deletions vendor/modules.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1b87f97

Please sign in to comment.