diff --git a/pkg/promtail/promtail_test.go b/pkg/promtail/promtail_test.go index 31f5b2aaa580e73c935e4e89fbda21564fbc67e8..02cfa5c11302e27ed2657283a3a83405256c4e9c 100644 --- a/pkg/promtail/promtail_test.go +++ b/pkg/promtail/promtail_test.go @@ -31,10 +31,11 @@ import ( "github.com/grafana/loki/pkg/promtail/scrape" ) +const httpTestPort = 9080 + func TestPromtail(t *testing.T) { // Setup. - w := log.NewSyncWriter(os.Stderr) logger := log.NewLogfmtLogger(w) logger = level.NewFilter(logger, level.AllowInfo()) @@ -71,7 +72,7 @@ func TestPromtail(t *testing.T) { } }() go func() { - if err = http.ListenAndServe("127.0.0.1:3100", nil); err != nil { + if err = http.ListenAndServe("localhost:3100", nil); err != nil { err = errors.Wrap(err, "Failed to start web server to receive logs") } }() @@ -398,7 +399,7 @@ func (h *testServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func getPromMetrics(t *testing.T) ([]byte, string) { - resp, err := http.Get("http://localhost:80/metrics") + resp, err := http.Get(fmt.Sprintf("http://localhost:%d/metrics", httpTestPort)) if err != nil { t.Fatal("Could not query metrics endpoint", err) } @@ -457,6 +458,11 @@ func buildTestConfig(t *testing.T, positionsFileName string, logDirName string) // Init everything with default values. flagext.RegisterFlags(&cfg) + // Make promtail listen on localhost to avoid prompts on MacOS. + cfg.ServerConfig.HTTPListenHost = "localhost" + cfg.ServerConfig.HTTPListenPort = httpTestPort + cfg.ServerConfig.GRPCListenHost = "localhost" + // Override some of those defaults cfg.ClientConfig.URL = clientURL cfg.ClientConfig.BatchWait = 10 * time.Millisecond