Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into becca/osquery-app-b…
Browse files Browse the repository at this point in the history
…undle
  • Loading branch information
RebeccaMahany committed Sep 15, 2023
2 parents 573d9ba + d64473a commit ad2a1bc
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions ee/localserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/kolide/krypto/pkg/echelper"
"github.com/kolide/launcher/pkg/agent"
"github.com/kolide/launcher/pkg/agent/types"
"github.com/kolide/launcher/pkg/backoff"
"github.com/kolide/launcher/pkg/osquery"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"golang.org/x/time/rate"
Expand Down Expand Up @@ -214,36 +213,26 @@ func (ls *localServer) runAsyncdWorkers() time.Time {
}

func (ls *localServer) Start() error {
// Spawn background workers. This loop is a bit weird on startup. We want to populate this data as soon as we can, but because the underlying launcher
// run group isn't ordered, this is likely to happen before querier is ready. So we retry at a frequent interval for a couple of minutes, then we drop
// back to a slower poll interval. Note that this polling is merely a check against time, we don't repopulate this data nearly so often. (But we poll
// frequently to account for the difference between wall clock time, and sleep time)
// Spawn background workers. The information gathered here is not critical for DT flow- so to reduce early osquery contention
// we wait for <pollInterval> and before starting and then only rerun if the previous run was unsuccessful,
// or has been greater than <recalculateInterval>. Note that this polling is merely a check against time,
// we don't repopulate this data nearly so often. (But we poll frequently to account for the difference between
// wall clock time, and sleep time)
const (
initialPollInterval = 10 * time.Second
initialPollTimeout = 2 * time.Minute
pollInterval = 15 * time.Minute
recalculateInterval = 24 * time.Hour
)

go func() {
// Initial load, run pretty often, at least for the first chunk of time.
var lastRun time.Time
if err := backoff.WaitFor(func() error {
lastRun = ls.runAsyncdWorkers()
if (lastRun == time.Time{}) {
return errors.New("async tasks not success on initial boot (no surprise)")
}
return nil
},
initialPollTimeout,
initialPollInterval,
); err != nil {
level.Info(ls.logger).Log("message", "Initial async runs unsuccessful. Will retry in the future.", "err", err)
}

// Now that we're done with the initial population, fall back to a periodic polling
// note that this will trigger the check for the first time after pollInterval (not immediately)
for range time.Tick(pollInterval) {
if time.Since(lastRun) > (recalculateInterval) {
if time.Since(lastRun) > recalculateInterval {
lastRun = ls.runAsyncdWorkers()
if lastRun.IsZero() {
level.Debug(ls.logger).Log("message", "runAsyncdWorkers unsuccessful, will retry in the future.")
}
}
}
}()
Expand Down

0 comments on commit ad2a1bc

Please sign in to comment.