Skip to content

Commit

Permalink
fix: handle scale up instance fetching timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
assafgi committed Sep 30, 2024
1 parent f8b9c9e commit 8f4ee91
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cloud-functions/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"context"
"encoding/json"
"errors"
"fmt"
"math/rand"
"strconv"
Expand Down Expand Up @@ -416,11 +417,12 @@ func GetInstancesByLabel(ctx context.Context, project, zone, labelKey, labelValu
listInstanceIter := instanceClient.List(ctx, listInstanceRequest)

for {
resp, err := listInstanceIter.Next()
if err == iterator.Done {
resp, err2 := listInstanceIter.Next()
if errors.Is(err2, iterator.Done) {
break
}
if err != nil {
if err2 != nil {
err = fmt.Errorf("error getting next instances by label: %w", err2)
log.Error().Err(err).Send()
break
}
Expand Down
2 changes: 2 additions & 0 deletions cloud-functions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ func ScaleUp(w http.ResponseWriter, r *http.Request) {
err = fmt.Errorf("failed getting instances by cluster label: %w", err)
log.Error().Err(err).Send()
respondWithErr(w, err, http.StatusBadRequest)
return
}

backendsNumber := len(backends)
log.Info().Msgf("Number of backends is: %d", backendsNumber)

Expand Down

0 comments on commit 8f4ee91

Please sign in to comment.