Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not perform osquery healthchecks while system is sleeping #1284

Merged
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
1 change: 1 addition & 0 deletions cmd/launcher/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func commonRunnerOptions(logger log.Logger, k types.Knapsack) []runtime.OsqueryI
)

return []runtime.OsqueryInstanceOption{
runtime.WithKnapsack(k),
runtime.WithOsquerydBinary(k.OsquerydPath()),
runtime.WithRootDirectory(k.RootDirectory()),
runtime.WithOsqueryExtensionPlugins(ktable.LauncherTables(k)...),
Expand Down
2 changes: 1 addition & 1 deletion cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func runLauncher(ctx context.Context, cancel func(), opts *launcher.Options) err
close(sigChannel)
})

powerEventWatcher, err := powereventwatcher.New(log.With(logger, "component", "power_event_watcher"))
powerEventWatcher, err := powereventwatcher.New(k, log.With(logger, "component", "power_event_watcher"))
if err != nil {
level.Debug(logger).Log("msg", "could not init power event watcher", "err", err)
} else {
Expand Down
9 changes: 9 additions & 0 deletions pkg/agent/flags/flag_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,12 @@ func (fc *FlagController) DisableTraceIngestTLS() bool {
WithDefaultBool(fc.cmdLineOpts.DisableTraceIngestTLS),
).get(fc.getControlServerValue(keys.DisableTraceIngestTLS))
}

func (fc *FlagController) SetInModernStandby(enabled bool) error {
return fc.setControlServerValue(keys.InModernStandby, boolToBytes(enabled))
}
func (fc *FlagController) InModernStandby() bool {
return NewBoolFlagValue(
WithDefaultBool(false),
).get(fc.getControlServerValue(keys.InModernStandby))
}
1 change: 1 addition & 0 deletions pkg/agent/flags/keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
LogIngestServerURL FlagKey = "log_ingest_url"
TraceIngestServerURL FlagKey = "trace_ingest_url"
DisableTraceIngestTLS FlagKey = "disable_trace_ingest_tls"
InModernStandby FlagKey = "in_modern_standby"
)

func (key FlagKey) String() string {
Expand Down
7 changes: 7 additions & 0 deletions pkg/agent/knapsack/knapsack.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,10 @@ func (k *knapsack) SetLogIngestServerURL(url string) error {
func (k *knapsack) LogIngestServerURL() string {
return k.flags.LogIngestServerURL()
}

func (k *knapsack) SetInModernStandby(enabled bool) error {
return k.flags.SetInModernStandby(enabled)
}
func (k *knapsack) InModernStandby() bool {
return k.flags.InModernStandby()
}
4 changes: 4 additions & 0 deletions pkg/agent/types/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,8 @@ type Flags interface {
// DisableTraceIngestTLS disables TLS for observability ingest server communication
SetDisableTraceIngestTLS(enabled bool) error
DisableTraceIngestTLS() bool

// InModernStandby indicates whether a Windows machine is awake or in modern standby
SetInModernStandby(enabled bool) error
InModernStandby() bool
}
86 changes: 57 additions & 29 deletions pkg/agent/types/mocks/flags.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 48 additions & 34 deletions pkg/agent/types/mocks/knapsack.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/log/checkpoint/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ func (c *checkPointer) logCheckPoint() {
}
c.logServerProvidedData()
c.logDesktopProcs()
if runtime.GOOS == "windows" {
c.logger.Log("in_modern_standby", c.knapsack.InModernStandby())
}
}

func (c *checkPointer) logDesktopProcs() {
Expand Down
8 changes: 8 additions & 0 deletions pkg/osquery/runtime/osqueryinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/kolide/launcher/pkg/agent"
"github.com/kolide/launcher/pkg/agent/types"
"github.com/kolide/launcher/pkg/autoupdate"
"github.com/kolide/launcher/pkg/backoff"
"github.com/kolide/launcher/pkg/osquery/runtime/history"
Expand Down Expand Up @@ -209,6 +210,12 @@ func WithAutoloadedExtensions(extensions ...string) OsqueryInstanceOption {
}
}

func WithKnapsack(k types.Knapsack) OsqueryInstanceOption {
return func(i *OsqueryInstance) {
i.knapsack = k
}
}

// OsqueryInstance is the type which represents a currently running instance
// of osqueryd.
type OsqueryInstance struct {
Expand All @@ -227,6 +234,7 @@ type OsqueryInstance struct {
usingTempDir bool
stats *history.Instance
startFunc func(cmd *exec.Cmd) error
knapsack types.Knapsack
}

// Healthy will check to determine whether or not the osquery process that is
Expand Down
6 changes: 6 additions & 0 deletions pkg/osquery/runtime/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ func (r *Runner) launchOsqueryInstance() error {
case <-o.doneCtx.Done():
return o.doneCtx.Err()
case <-ticker.C:
// If device is sleeping, we do not want to perform unnecessary healthchecks that
// may force an unnecessary restart.
if o.knapsack.InModernStandby() {
break
}

// Health check! Allow a couple
// failures before we tear everything
// down. This is pretty simple, it
Expand Down
Loading
Loading