MCPcopy Index your code
hub / github.com/cortexproject/cortex / TestRulerAlertmanager

Function TestRulerAlertmanager

integration/ruler_test.go:980–1026  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

978}
979
980func TestRulerAlertmanager(t *testing.T) {
981 var namespaceOne = "test_/encoded_+namespace/?"
982 ruleGroup := createTestRuleGroup(t)
983
984 s, err := e2e.NewScenario(networkName)
985 require.NoError(t, err)
986 defer s.Close()
987
988 // Start dependencies.
989 consul := e2edb.NewConsul()
990 minio := e2edb.NewMinio(9000, rulestoreBucketName, bucketName)
991 require.NoError(t, s.StartAndWaitReady(consul, minio))
992
993 // Have at least one alertmanager configuration.
994 require.NoError(t, writeFileToSharedDir(s, "alertmanager_configs/user-1.yaml", []byte(cortexAlertmanagerUserConfigYaml)))
995
996 // Start Alertmanagers.
997 amFlags := mergeFlags(AlertmanagerFlags(), AlertmanagerLocalFlags())
998 am1 := e2ecortex.NewAlertmanager("alertmanager1", amFlags, "")
999 am2 := e2ecortex.NewAlertmanager("alertmanager2", amFlags, "")
1000 require.NoError(t, s.StartAndWaitReady(am1, am2))
1001
1002 am1URL := "http://" + am1.HTTPEndpoint()
1003 am2URL := "http://" + am2.HTTPEndpoint()
1004
1005 // Connect the ruler to Alertmanagers
1006 configOverrides := map[string]string{
1007 "-ruler.alertmanager-url": strings.Join([]string{am1URL, am2URL}, ","),
1008 }
1009
1010 // Start Ruler.
1011 ruler := e2ecortex.NewRuler("ruler", consul.NetworkHTTPEndpoint(), mergeFlags(BlocksStorageFlags(), RulerFlags(), configOverrides), "")
1012 require.NoError(t, s.StartAndWaitReady(ruler))
1013
1014 // Create a client with the ruler address configured
1015 c, err := e2ecortex.NewClient("", "", "", ruler.HTTPEndpoint(), "user-1")
1016 require.NoError(t, err)
1017
1018 // Set the rule group into the ruler
1019 require.NoError(t, c.SetRuleGroup(ruleGroup, namespaceOne))
1020
1021 // Wait until the user manager is created
1022 require.NoError(t, ruler.WaitSumMetrics(e2e.Equals(1), "cortex_ruler_managers_total"))
1023
1024 // Wait until we've discovered the alertmanagers.
1025 require.NoError(t, ruler.WaitSumMetricsWithOptions(e2e.Equals(2), []string{"cortex_prometheus_notifications_alertmanagers_discovered"}, e2e.WaitMissingMetrics))
1026}
1027
1028func TestRulerAlertmanagerTLS(t *testing.T) {
1029 var namespaceOne = "test_/encoded_+namespace/?"

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
StartAndWaitReadyMethod · 0.95
SetRuleGroupMethod · 0.95
NewScenarioFunction · 0.92
NewAlertmanagerFunction · 0.92
NewRulerFunction · 0.92
NewClientFunction · 0.92
EqualsFunction · 0.92
createTestRuleGroupFunction · 0.85
writeFileToSharedDirFunction · 0.85
HTTPEndpointMethod · 0.80
JoinMethod · 0.80

Tested by

no test coverage detected