v0.15.5: Fix startup hub report — Push() returns real errors, startup retries 3x with 15s delay
This commit is contained in:
@@ -290,10 +290,20 @@ func main() {
|
||||
if hubPusher != nil {
|
||||
if cfg.Hub.Enabled {
|
||||
r := report.BuildReport(cfg, stackMgr, backupMgr, cpuCollector, metricsStore, Version, sett.GetStoragePaths())
|
||||
if err := hubPusher.Push(r); err != nil {
|
||||
logger.Printf("[WARN] Startup hub report failed: %v", err)
|
||||
} else {
|
||||
logger.Println("[INFO] Startup hub report sent")
|
||||
var pushErr error
|
||||
for attempt := 1; attempt <= 3; attempt++ {
|
||||
pushErr = hubPusher.Push(r)
|
||||
if pushErr == nil {
|
||||
logger.Println("[INFO] Startup hub report sent")
|
||||
break
|
||||
}
|
||||
logger.Printf("[WARN] Startup hub report attempt %d/3 failed: %v", attempt, pushErr)
|
||||
if attempt < 3 {
|
||||
time.Sleep(15 * time.Second)
|
||||
}
|
||||
}
|
||||
if pushErr != nil {
|
||||
logger.Printf("[WARN] Startup hub report failed after 3 attempts — next scheduled push in %s", cfg.Hub.PushInterval)
|
||||
}
|
||||
} else {
|
||||
// Send a minimal "disabled" notification so hub knows reporting is intentionally off
|
||||
|
||||
@@ -36,7 +36,6 @@ func NewPusher(cfg *config.HubConfig, logger *log.Logger) *Pusher {
|
||||
}
|
||||
|
||||
// Push sends a report to the hub. Retries 3 times with 5s backoff.
|
||||
// Never returns error to caller — push failures should not affect controller operation.
|
||||
func (p *Pusher) Push(report *Report) error {
|
||||
if !p.enabled {
|
||||
return nil
|
||||
@@ -44,8 +43,7 @@ func (p *Pusher) Push(report *Report) error {
|
||||
|
||||
data, err := json.Marshal(report)
|
||||
if err != nil {
|
||||
p.logger.Printf("[WARN] Hub report marshal failed: %v", err)
|
||||
return nil
|
||||
return fmt.Errorf("marshal report: %w", err)
|
||||
}
|
||||
|
||||
url := p.hubURL + "/api/v1/report"
|
||||
@@ -81,8 +79,7 @@ func (p *Pusher) Push(report *Report) error {
|
||||
lastErr = fmt.Errorf("HTTP %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
p.logger.Printf("[WARN] Hub report push failed after 3 attempts: %v", lastErr)
|
||||
return nil
|
||||
return fmt.Errorf("hub push failed after 3 attempts: %w", lastErr)
|
||||
}
|
||||
|
||||
// PushOnce sends a single report regardless of the enabled flag.
|
||||
|
||||
Reference in New Issue
Block a user