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

Function TestNotifierSendsUserIDHeader

pkg/ruler/ruler_test.go:391–431  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

389var _ MultiTenantManager = &DefaultMultiTenantManager{}
390
391func 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(&notifier.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
433func TestNotifierSendExternalLabels(t *testing.T) {
434 ctx, cancel := context.WithCancel(context.Background())

Callers

nothing calls this directly

Calls 12

defaultRulerConfigFunction · 0.85
newManagerFunction · 0.85
DoneMethod · 0.80
getOrCreateNotifierMethod · 0.80
AlertmanagersMethod · 0.80
EqualMethod · 0.65
CloseMethod · 0.65
StopMethod · 0.65
SendMethod · 0.65
AddMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected