Skip to content

Commit

Permalink
chore: make the status check of the gateway client to be executed con…
Browse files Browse the repository at this point in the history
…currently (#6347)

Signed-off-by: Jintao Zhang <[email protected]>
  • Loading branch information
tao12345666333 authored Jul 30, 2024
1 parent 1f74d23 commit 56c2598
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions internal/clients/readiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"sync"
"time"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -118,25 +119,43 @@ func (c DefaultReadinessChecker) checkPendingClient(
// checkAlreadyExistingClients checks if the already existing clients are still ready to be used and returns the ones
// that are not.
func (c DefaultReadinessChecker) checkAlreadyExistingClients(ctx context.Context, alreadyCreatedClients []AlreadyCreatedClient) (turnedPending []adminapi.DiscoveredAdminAPI) {
var wg sync.WaitGroup
pendingChan := make(chan adminapi.DiscoveredAdminAPI, len(alreadyCreatedClients))

for _, client := range alreadyCreatedClients {
// For ready clients we check readiness by calling the Status endpoint.
if ready := c.checkAlreadyCreatedClient(ctx, client); !ready {
podRef, ok := client.PodReference()
if !ok {
// This should never happen, but if it does, we want to log it.
c.logger.Error(
errors.New("missing pod reference"),
"Failed to get PodReference for client",
"address", client.BaseRootURL(),
)
continue
wg.Add(1)
go func(client AlreadyCreatedClient) {
defer wg.Done()

// For ready clients we check readiness by calling the Status endpoint.
if ready := c.checkAlreadyCreatedClient(ctx, client); !ready {
podRef, ok := client.PodReference()
if !ok {
// This should never happen, but if it does, we want to log it.
c.logger.Error(
errors.New("missing pod reference"),
"Failed to get PodReference for client",
"address", client.BaseRootURL(),
)
return
}
pendingChan <- adminapi.DiscoveredAdminAPI{
Address: client.BaseRootURL(),
PodRef: podRef,
}
}
turnedPending = append(turnedPending, adminapi.DiscoveredAdminAPI{
Address: client.BaseRootURL(),
PodRef: podRef,
})
}
}(client)
}

go func() {
wg.Wait()
close(pendingChan)
}()

for pendingClient := range pendingChan {
turnedPending = append(turnedPending, pendingClient)
}

return turnedPending
}

Expand Down

0 comments on commit 56c2598

Please sign in to comment.