diff --git a/tests/fixture/e2e/env.go b/tests/fixture/e2e/env.go index 6f359b499ef0..694ff2af6f5c 100644 --- a/tests/fixture/e2e/env.go +++ b/tests/fixture/e2e/env.go @@ -79,6 +79,11 @@ func (te *TestEnvironment) Marshal() []byte { func NewTestEnvironment(tc tests.TestContext, flagVars *FlagVars, desiredNetwork *tmpnet.Network) *TestEnvironment { require := require.New(tc) + // Start collectors for any command but stop + if flagVars.StartCollectors() && !flagVars.StopNetwork() { + require.NoError(tmpnet.StartCollectors(tc.DefaultContext(), tc.Log())) + } + var network *tmpnet.Network // Need to load the network if it is being stopped or reused if flagVars.StopNetwork() || flagVars.ReuseNetwork() { @@ -130,10 +135,6 @@ func NewTestEnvironment(tc tests.TestContext, flagVars *FlagVars, desiredNetwork } } - if flagVars.StartCollectors() { - require.NoError(tmpnet.StartCollectors(tc.DefaultContext(), tc.Log())) - } - // Start a new network if network == nil { network = desiredNetwork @@ -151,6 +152,11 @@ func NewTestEnvironment(tc tests.TestContext, flagVars *FlagVars, desiredNetwork ) } + // Once one or more nodes are running it should be safe to wait for promtail to report readiness + if flagVars.StartCollectors() { + require.NoError(tmpnet.WaitForPromtailReadiness(tc.DefaultContext(), tc.Log())) + } + if flagVars.StartNetwork() { os.Exit(0) } diff --git a/tests/fixture/tmpnet/monitor_processes.go b/tests/fixture/tmpnet/monitor_processes.go index ebcf53b0c4f9..639c053f637e 100644 --- a/tests/fixture/tmpnet/monitor_processes.go +++ b/tests/fixture/tmpnet/monitor_processes.go @@ -63,16 +63,9 @@ func StartCollectors(ctx context.Context, log logging.Logger) error { return err } - // Wait for readiness. These checks are performed separately from start to - // minimize time to readiness. - readinessURLs := map[string]string{ - promtailCmd: promtailReadinessURL, - prometheusCmd: prometheusReadinessURL, - } - for cmdName, readinessURLs := range readinessURLs { - if err := waitForReadiness(ctx, log, cmdName, readinessURLs); err != nil { - return err - } + log.Info("skipping promtail readiness check until one or more nodes have written their service discovery configuration") + if err := waitForReadiness(ctx, log, prometheusCmd, prometheusReadinessURL); err != nil { + return err } log.Info("To stop: tmpnetctl stop-collectors") @@ -80,6 +73,12 @@ func StartCollectors(ctx context.Context, log logging.Logger) error { return nil } +// WaitForPromtailReadiness waits until prometheus is ready. It can only succeed after +// one or more nodes have written their service discovery configuration. +func WaitForPromtailReadiness(ctx context.Context, log logging.Logger) error { + return waitForReadiness(ctx, log, promtailCmd, promtailReadinessURL) +} + // EnsureCollectorsStopped ensures collectors are not running. func StopCollectors(ctx context.Context, log logging.Logger) error { if _, ok := ctx.Deadline(); !ok { @@ -354,7 +353,7 @@ func getPrometheusURL() string { } func getLokiURL() string { - return GetEnvWithDefault("LOKI_URL", defaultPrometheusURL) + return GetEnvWithDefault("LOKI_URL", defaultLokiURL) } // getCollectorCredentials retrieves the username and password for the command. @@ -488,9 +487,7 @@ func waitForReadiness(ctx context.Context, log logging.Logger, cmdName string, r }); err != nil { return err } - log.Info(cmdName+" ready", - zap.String("url", readinessURL), - ) + log.Info(cmdName + " ready") return nil }