@@ -329,13 +329,13 @@ func runQueryFrontend(
329329 return err
330330 }
331331
332- roundTripper , err := cortexfrontend .NewDownstreamRoundTripper (cfg .DownstreamURL , downstreamTripper )
332+ downstreamRT , err := cortexfrontend .NewDownstreamRoundTripper (cfg .DownstreamURL , downstreamTripper )
333333 if err != nil {
334334 return errors .Wrap (err , "setup downstream roundtripper" )
335335 }
336336
337337 // Wrap the downstream RoundTripper into query frontend Tripperware.
338- roundTripper = tripperWare (roundTripper )
338+ roundTripper : = tripperWare (downstreamRT )
339339
340340 // Create the query frontend transport.
341341 handler := transport .NewHandler (* cfg .CortexHandlerConfig , roundTripper , logger , nil )
@@ -402,17 +402,9 @@ func runQueryFrontend(
402402 ctx , cancel := context .WithCancel (context .Background ())
403403
404404 g .Add (func () error {
405-
406405 var firstRun = true
407- for {
408- if ! firstRun {
409- select {
410- case <- ctx .Done ():
411- return nil
412- case <- time .After (10 * time .Second ):
413- }
414- }
415406
407+ doCheckDownstream := func () (rerr error ) {
416408 timeoutCtx , cancel := context .WithTimeout (ctx , 10 * time .Second )
417409 defer cancel ()
418410
@@ -422,23 +414,33 @@ func runQueryFrontend(
422414 return errors .Wrap (err , "creating request to downstream URL" )
423415 }
424416
425- resp , err := roundTripper .RoundTrip (req )
417+ resp , err := downstreamRT .RoundTrip (req )
426418 if err != nil {
427- level .Warn (logger ).Log ("msg" , "failed to reach downstream URL" , "err" , err , "readiness_url" , readinessUrl )
428- statusProber .NotReady (err )
429- firstRun = false
430- continue
419+ return errors .Wrapf (err , "roundtripping to downstream URL %s" , readinessUrl )
431420 }
432- runutil .ExhaustCloseWithLogOnErr ( logger , resp .Body , "downstream health check response body" )
421+ defer runutil .CloseWithErrCapture ( & rerr , resp .Body , "downstream health check response body" )
433422
434423 if resp .StatusCode / 100 == 4 || resp .StatusCode / 100 == 5 {
435- level .Warn (logger ).Log ("msg" , "downstream URL returned an error" , "status_code" , resp .StatusCode , "readiness_url" , readinessUrl )
436- statusProber .NotReady (errors .Errorf ("downstream URL %s returned an error: %d" , readinessUrl , resp .StatusCode ))
437- firstRun = false
438- continue
424+ return errors .Errorf ("downstream URL %s returned an error: %d" , readinessUrl , resp .StatusCode )
425+ }
426+
427+ return nil
428+ }
429+ for {
430+ if ! firstRun {
431+ select {
432+ case <- ctx .Done ():
433+ return nil
434+ case <- time .After (10 * time .Second ):
435+ }
439436 }
437+ firstRun = false
440438
441- statusProber .Ready ()
439+ if err := doCheckDownstream (); err != nil {
440+ statusProber .NotReady (err )
441+ } else {
442+ statusProber .Ready ()
443+ }
442444 }
443445 }, func (err error ) {
444446 cancel ()
0 commit comments