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

Function TestAlertmanagerStoreAPI

integration/alertmanager_test.go:106–174  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

104}
105
106func TestAlertmanagerStoreAPI(t *testing.T) {
107 s, err := e2e.NewScenario(networkName)
108 require.NoError(t, err)
109 defer s.Close()
110
111 flags := mergeFlags(AlertmanagerFlags(), AlertmanagerS3Flags())
112
113 minio := e2edb.NewMinio(9000, alertsBucketName)
114 require.NoError(t, s.StartAndWaitReady(minio))
115
116 am := e2ecortex.NewAlertmanager(
117 "alertmanager",
118 flags,
119 "",
120 )
121
122 require.NoError(t, s.StartAndWaitReady(am))
123 require.NoError(t, am.WaitSumMetrics(e2e.Equals(1), "alertmanager_cluster_members"))
124
125 c, err := e2ecortex.NewClient("", "", am.HTTPEndpoint(), "", "user-1")
126 require.NoError(t, err)
127
128 _, err = c.GetAlertmanagerConfig(context.Background())
129 require.Error(t, err)
130 require.EqualError(t, err, e2ecortex.ErrNotFound.Error())
131
132 err = c.SetAlertmanagerConfig(context.Background(), cortexAlertmanagerUserConfigYaml, map[string]string{})
133 require.NoError(t, err)
134
135 require.NoError(t, am.WaitSumMetricsWithOptions(e2e.Equals(1), []string{"cortex_alertmanager_config_last_reload_successful"},
136 e2e.WithLabelMatchers(labels.MustNewMatcher(labels.MatchEqual, "user", "user-1")),
137 e2e.WaitMissingMetrics))
138 require.NoError(t, am.WaitSumMetricsWithOptions(e2e.Greater(0), []string{"cortex_alertmanager_config_last_reload_successful_seconds"},
139 e2e.WithLabelMatchers(labels.MustNewMatcher(labels.MatchEqual, "user", "user-1")),
140 e2e.WaitMissingMetrics))
141
142 cfg, err := c.GetAlertmanagerConfig(context.Background())
143 require.NoError(t, err)
144
145 // Ensure the returned status config matches the loaded config
146 require.NotNil(t, cfg)
147 require.Equal(t, "example_receiver", cfg.Route.Receiver)
148 require.Len(t, cfg.Route.GroupByStr, 1)
149 require.Equal(t, "example_groupby", cfg.Route.GroupByStr[0])
150 require.Len(t, cfg.Receivers, 1)
151 require.Equal(t, "example_receiver", cfg.Receivers[0].Name)
152
153 err = c.SendAlertToAlermanager(context.Background(), &model.Alert{Labels: model.LabelSet{"foo": "bar"}})
154 require.NoError(t, err)
155
156 require.NoError(t, am.WaitSumMetricsWithOptions(e2e.Equals(1), []string{"cortex_alertmanager_alerts_received_total"},
157 e2e.WithLabelMatchers(labels.MustNewMatcher(labels.MatchEqual, "user", "user-1")),
158 e2e.WaitMissingMetrics))
159
160 err = c.DeleteAlertmanagerConfig(context.Background())
161 require.NoError(t, err)
162
163 // The deleted config is applied asynchronously, so we should wait until the metric

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
StartAndWaitReadyMethod · 0.95
GetAlertmanagerConfigMethod · 0.95
SetAlertmanagerConfigMethod · 0.95
NewScenarioFunction · 0.92
NewAlertmanagerFunction · 0.92
EqualsFunction · 0.92
NewClientFunction · 0.92
WithLabelMatchersFunction · 0.92
GreaterFunction · 0.92

Tested by

no test coverage detected