Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion installer/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func Cloud(c *types.Config, update bool) error {
}

indexURL := "http://localhost:9200/.utm-geoip?pretty"
indexExists, err := utils.CheckIndexExists(indexURL)
indexExists, err := utils.CheckIndexExistsWithRetry(indexURL)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion installer/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func Master(c *types.Config) error {
}

indexURL := "http://localhost:9200/.utm-geoip?pretty"
indexExists, err := utils.CheckIndexExists(indexURL)
indexExists, err := utils.CheckIndexExistsWithRetry(indexURL)
if err != nil {
return err
}
Expand Down
20 changes: 20 additions & 0 deletions installer/utils/elastic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package utils
import (
"fmt"
"net/http"
"time"
)

// CheckIndexExists checks if the given Elasticsearch index exists by sending an HTTP GET
Expand All @@ -26,3 +27,22 @@ func CheckIndexExists(url string) (bool, error) {
return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
}

// retrying every 5 seconds up to a total duration of 1 minute.
func CheckIndexExistsWithRetry(url string) (bool, error) {
timeout := time.Minute
interval := 5 * time.Second
deadline := time.Now().Add(timeout)

var lastErr error
for time.Now().Before(deadline) {
exists, err := CheckIndexExists(url)
if err == nil {
return exists, nil
}
lastErr = err
fmt.Printf("Attempt failed: %v. Retrying in %v...\n", err, interval)
time.Sleep(interval)
}
return false, fmt.Errorf("failed after retries: %v", lastErr)
}
Loading