Skip to content

Commit

Permalink
Enable early-return rule
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Dec 14, 2023
1 parent 26f48eb commit 9650fcb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ linters-settings:
disabled: false
- name: unreachable-code
disabled: false
- name: early-return
disabled: false

issues:
exclude-rules:
Expand Down
9 changes: 4 additions & 5 deletions pkg/osquery/runtime/history/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ func (h *History) load() error {

var instances []*Instance

if instancesBytes != nil {
if err := json.Unmarshal(instancesBytes, &instances); err != nil {
return fmt.Errorf("error unmarshalling osquery_instance_history: %w", err)
}
} else {
if instancesBytes == nil {
return nil
}
if err := json.Unmarshal(instancesBytes, &instances); err != nil {
return fmt.Errorf("error unmarshalling osquery_instance_history: %w", err)
}

h.instances = instances
return nil
Expand Down
22 changes: 10 additions & 12 deletions pkg/osquery/runtime/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,24 +546,22 @@ func (r *Runner) launchOsqueryInstance() error {
// better for a Limiter
maxHealthChecks := 5
for i := 1; i <= maxHealthChecks; i++ {
if err := r.Healthy(); err != nil {
if i == maxHealthChecks {
level.Info(o.logger).Log("msg", "Health check failed. Giving up", "attempt", i, "err", err)
return fmt.Errorf("health check failed: %w", err)
}

level.Debug(o.logger).Log("msg", "Health check failed. Will retry", "attempt", i, "err", err)
time.Sleep(1 * time.Second)

} else {
// err was nil, clear failed
err := r.Healthy()
if err == nil {
// err was nil, clear failed attempts
if i > 1 {
level.Debug(o.logger).Log("msg", "Health check passed. Clearing error", "attempt", i)
}

break
}

if i == maxHealthChecks {
level.Info(o.logger).Log("msg", "Health check failed. Giving up", "attempt", i, "err", err)
return fmt.Errorf("health check failed: %w", err)
}

level.Debug(o.logger).Log("msg", "Health check failed. Will retry", "attempt", i, "err", err)
time.Sleep(1 * time.Second)
}
}
}
Expand Down

0 comments on commit 9650fcb

Please sign in to comment.