(t *testing.T)
| 389 | var _ MultiTenantManager = &DefaultMultiTenantManager{} |
| 390 | |
| 391 | func TestNotifierSendsUserIDHeader(t *testing.T) { |
| 392 | var wg sync.WaitGroup |
| 393 | |
| 394 | // We do expect 1 API call for the user create with the getOrCreateNotifier() |
| 395 | wg.Add(1) |
| 396 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 397 | userID, _, err := users.ExtractTenantIDFromHTTPRequest(r) |
| 398 | assert.NoError(t, err) |
| 399 | assert.Equal(t, userID, "1") |
| 400 | wg.Done() |
| 401 | })) |
| 402 | defer ts.Close() |
| 403 | |
| 404 | cfg := defaultRulerConfig(t) |
| 405 | |
| 406 | cfg.AlertmanagerURL = ts.URL |
| 407 | cfg.AlertmanagerDiscovery = false |
| 408 | |
| 409 | manager := newManager(t, cfg) |
| 410 | defer manager.Stop() |
| 411 | |
| 412 | n, err := manager.getOrCreateNotifier("1", manager.registry) |
| 413 | require.NoError(t, err) |
| 414 | |
| 415 | // Loop until notifier discovery syncs up |
| 416 | for len(n.Alertmanagers()) == 0 { |
| 417 | time.Sleep(10 * time.Millisecond) |
| 418 | } |
| 419 | n.Send(¬ifier.Alert{ |
| 420 | Labels: labels.FromStrings("alertname", "testalert"), |
| 421 | }) |
| 422 | |
| 423 | wg.Wait() |
| 424 | |
| 425 | // Ensure we have metrics in the notifier. |
| 426 | assert.NoError(t, prom_testutil.GatherAndCompare(manager.registry.(*prometheus.Registry), strings.NewReader(` |
| 427 | # HELP prometheus_notifications_dropped_total Total number of alerts dropped due to errors when sending to Alertmanager. |
| 428 | # TYPE prometheus_notifications_dropped_total counter |
| 429 | prometheus_notifications_dropped_total 0 |
| 430 | `), "prometheus_notifications_dropped_total")) |
| 431 | } |
| 432 | |
| 433 | func TestNotifierSendExternalLabels(t *testing.T) { |
| 434 | ctx, cancel := context.WithCancel(context.Background()) |
nothing calls this directly
no test coverage detected