Skip to content

Commit

Permalink
Add new action type force_full_control_data_fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Jul 16, 2024
1 parent 6e482b0 commit 153dc0d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 3 additions & 0 deletions cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/kolide/launcher/ee/agent/storage"
agentbbolt "github.com/kolide/launcher/ee/agent/storage/bbolt"
"github.com/kolide/launcher/ee/agent/timemachine"
"github.com/kolide/launcher/ee/control"
"github.com/kolide/launcher/ee/control/actionqueue"
"github.com/kolide/launcher/ee/control/consumers/acceleratecontrolconsumer"
"github.com/kolide/launcher/ee/control/consumers/flareconsumer"
Expand Down Expand Up @@ -449,6 +450,8 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl
actionsQueue.RegisterActor(uninstallconsumer.UninstallSubsystem, uninstallconsumer.New(k))
// register flare consumer
actionsQueue.RegisterActor(flareconsumer.FlareSubsystem, flareconsumer.New(k))
// register force full control data fetch consumer
actionsQueue.RegisterActor(control.ForceFullControlDataFetchAction, controlService)

// create notification consumer
notificationConsumer, err := notificationconsumer.NewNotifyConsumer(
Expand Down
19 changes: 15 additions & 4 deletions ee/control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"golang.org/x/exp/slices"
)

const ForceFullControlDataFetchAction = "force_full_control_data_fetch"

// ControlService is the main object that manages the control service. It is responsible for fetching
// and caching control data, and updating consumers and subscribers.
type ControlService struct {
Expand Down Expand Up @@ -96,7 +98,7 @@ func (cs *ControlService) Start(ctx context.Context) {
startUpMessageSuccess := false

for {
fetchErr := cs.Fetch()
fetchErr := cs.Fetch(false)
switch {
case fetchErr != nil:
cs.slogger.Log(ctx, slog.LevelWarn,
Expand Down Expand Up @@ -208,7 +210,7 @@ func (cs *ControlService) requestIntervalChanged(newInterval time.Duration) {
// Perform a fetch now, to retrieve data faster in case this change
// was triggered by localserver or the user clicking on the menu bar app
// instead of by a control server change.
if err := cs.Fetch(); err != nil {
if err := cs.Fetch(false); err != nil {
// if we got an error, log it and move on
cs.slogger.Log(context.TODO(), slog.LevelWarn,
"failed to fetch data from control server. Not fatal, moving on",
Expand Down Expand Up @@ -248,7 +250,7 @@ func (cs *ControlService) readRequestInterval() time.Duration {
}

// Performs a retrieval of the latest control server data, and notifies observers of updates.
func (cs *ControlService) Fetch() error {
func (cs *ControlService) Fetch(fetchFull bool) error {
// Do not block in the case where:
// 1. `Start` called `Fetch` on an interval
// 2. The control service received an updated `ControlRequestInterval` from the server
Expand Down Expand Up @@ -286,7 +288,7 @@ func (cs *ControlService) Fetch() error {
}
}

if hash == lastHash && !cs.knapsack.ForceControlSubsystems() {
if hash == lastHash && !cs.knapsack.ForceControlSubsystems() && !fetchFull {
// The last fetched update is still fresh
// Nothing to do, skip to the next subsystem
continue
Expand Down Expand Up @@ -382,3 +384,12 @@ func (cs *ControlService) update(subsystem string, reader io.Reader) error {

return nil
}

// Do handles the force_full_control_data_fetch action.
func (cs *ControlService) Do(data io.Reader) error {
cs.slogger.Log(context.TODO(), slog.LevelDebug,
"received request to perform full fetch of all subsystems",
)

return cs.Fetch(true)
}
4 changes: 2 additions & 2 deletions ee/control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func TestControlServiceFetch(t *testing.T) {

// Repeat fetches to verify no changes
for i := 0; i < tt.fetches; i++ {
err = cs.Fetch()
err = cs.Fetch(false)
require.NoError(t, err)

// Expect consumer to have gotten exactly one update
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestControlServicePersistLastFetched(t *testing.T) {
err := cs.RegisterConsumer(tt.subsystem, tt.c)
require.NoError(t, err)

err = cs.Fetch()
err = cs.Fetch(false)
require.NoError(t, err)
}

Expand Down

0 comments on commit 153dc0d

Please sign in to comment.