Skip to content

Commit 0276213

Browse files
authored
Add logs and shorter upgrade time check (#167)
Now check every 5 mins and add logs for what happened
1 parent d9dde36 commit 0276213

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

app/jobs/selfupdatejob/selfupdatejob.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func (j *SelfUpdateJob) Shutdown() {
127127
// runUpdate performs a single update check and apply cycle.
128128
func (j *SelfUpdateJob) runUpdate(ctx context.Context) error {
129129
// Step 1: Check for updates
130+
log.Infof("checking for updates (current_version=%s, os=%s, arch=%s)", j.config.CurrentVersion, runtime.GOOS, runtime.GOARCH)
130131
info, err := j.config.UpdateChecker.Check()
131132
if err != nil {
132133
// Log unsupported platform at WARN level and return nil (not an error condition)
@@ -137,26 +138,33 @@ func (j *SelfUpdateJob) runUpdate(ctx context.Context) error {
137138
return fmt.Errorf("update check failed: %w", err)
138139
}
139140
if !info.UpdateAvailable {
141+
log.Infof("no update available, current version %s is up to date", j.config.CurrentVersion)
140142
return nil
141143
}
142144

143145
updateID := uuid.NewString()
144-
log.Infof("update available: %s -> %s (update_id=%s)", j.config.CurrentVersion, info.TargetVersion, updateID)
146+
log.Infof("update available: %s -> %s (update_id=%s, url=%s, size=%d)", j.config.CurrentVersion, info.TargetVersion, updateID, info.AgentURL, info.AgentSize)
145147

146148
// Step 2: Pre-flight checks
149+
log.Infof("running preflight checks (update_id=%s)", updateID)
147150
requiredSpace := info.AgentSize
148151
if requiredSpace == 0 {
149152
requiredSpace = defaultRequiredSpace
150153
}
151154
result := j.config.PreflightChecker.Check(requiredSpace)
152155
if !result.Passed {
156+
log.Warnf("preflight checks failed (update_id=%s): %v", updateID, result.Errors)
153157
return fmt.Errorf("preflight checks failed: %v", result.Errors)
154158
}
159+
log.Infof("preflight checks passed (update_id=%s)", updateID)
155160

156161
// Step 3: Acquire lock
162+
log.Infof("acquiring update lock (update_id=%s)", updateID)
157163
if err := j.config.LockManager.TryLockWithRetry(5*time.Minute, 3, 5*time.Second); err != nil {
164+
log.Warnf("failed to acquire update lock (update_id=%s): %v", updateID, err)
158165
return fmt.Errorf("failed to acquire update lock: %w", err)
159166
}
167+
log.Infof("update lock acquired (update_id=%s)", updateID)
160168

161169
// From here on, we must release the lock on any failure
162170
locked := true
@@ -192,23 +200,29 @@ func (j *SelfUpdateJob) runUpdate(ctx context.Context) error {
192200
}
193201

194202
// Step 5: Download agent tarball
203+
log.Infof("downloading agent tarball (update_id=%s, url=%s)", updateID, info.AgentURL)
195204
agentDest := filepath.Join(j.config.StagingDir, updatedownload.AgentTarballName)
196205
if _, err := j.config.Downloader.DownloadAndVerify(ctx, info.AgentURL, agentDest, info.AgentSHA256); err != nil {
206+
log.Errorf("failed to download agent (update_id=%s): %v", updateID, err)
197207
writeErrorState(fmt.Sprintf("failed to download agent: %s", err))
198208
return fmt.Errorf("failed to download agent: %w", err)
199209
}
210+
log.Infof("agent tarball downloaded successfully (update_id=%s, dest=%s)", updateID, agentDest)
200211

201212
if err := ctx.Err(); err != nil {
202213
writeErrorState(err.Error())
203214
return err
204215
}
205216

206217
// Step 6: Extract hostlink binary from tarball to staging dir
218+
log.Infof("extracting binary from tarball (update_id=%s)", updateID)
207219
stagedBinary := filepath.Join(j.config.StagingDir, "hostlink")
208220
if err := j.config.InstallBinary(agentDest, stagedBinary); err != nil {
221+
log.Errorf("failed to extract binary (update_id=%s): %v", updateID, err)
209222
writeErrorState(fmt.Sprintf("failed to extract binary from tarball: %s", err))
210223
return fmt.Errorf("failed to extract binary from tarball: %w", err)
211224
}
225+
log.Infof("binary extracted successfully (update_id=%s, staged=%s)", updateID, stagedBinary)
212226

213227
if err := ctx.Err(); err != nil {
214228
writeErrorState(err.Error())
@@ -231,16 +245,19 @@ func (j *SelfUpdateJob) runUpdate(ctx context.Context) error {
231245
}
232246

233247
// Step 8: Release lock before spawning upgrade
248+
log.Infof("releasing update lock before spawn (update_id=%s)", updateID)
234249
j.config.LockManager.Unlock()
235250
locked = false
236251

237252
// Step 9: Spawn staged binary with upgrade subcommand
238253
args := []string{"upgrade", "--install-path", j.config.InstallPath, "--update-id", updateID, "--source-version", j.config.CurrentVersion}
254+
log.Infof("spawning upgrade process (update_id=%s, binary=%s, args=%v)", updateID, stagedBinary, args)
239255
if err := j.config.Spawn(stagedBinary, args); err != nil {
256+
log.Errorf("failed to spawn upgrade (update_id=%s): %v", updateID, err)
240257
writeErrorState(err.Error())
241258
return fmt.Errorf("failed to spawn upgrade: %w", err)
242259
}
243260

244-
log.Infof("upgrade spawned for version %s", info.TargetVersion)
261+
log.Infof("upgrade spawned successfully (update_id=%s, target_version=%s)", updateID, info.TargetVersion)
245262
return nil
246263
}

app/jobs/selfupdatejob/selfupdatejob_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ func TestRegister_RespectsParentContextCancellation(t *testing.T) {
9999

100100
// --- Trigger Tests ---
101101

102-
func TestDefaultTriggerConfig_OneHourInterval(t *testing.T) {
102+
func TestDefaultTriggerConfig_FiveMinuteInterval(t *testing.T) {
103103
cfg := DefaultTriggerConfig()
104-
if cfg.Interval != 1*time.Hour {
105-
t.Errorf("expected default interval 1h, got %v", cfg.Interval)
104+
if cfg.Interval != 5*time.Minute {
105+
t.Errorf("expected default interval 5m, got %v", cfg.Interval)
106106
}
107107
}
108108

app/jobs/selfupdatejob/trigger.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ type TriggerConfig struct {
1212
Interval time.Duration
1313
}
1414

15-
// DefaultTriggerConfig returns the default trigger configuration (1 hour interval).
15+
// DefaultTriggerConfig returns the default trigger configuration (5 minute interval for debugging).
1616
func DefaultTriggerConfig() TriggerConfig {
1717
return TriggerConfig{
18-
Interval: 1 * time.Hour,
18+
Interval: 5 * time.Minute,
1919
}
2020
}
2121

0 commit comments

Comments
 (0)