Fixing code review comments. (#17240)

Fixing code review comments from
https://github.com/fleetdm/fleet/pull/16855
Also, moving `CleanupDistributedQueryCampaigns` back to once an hour, so
that it is not disabled.
This commit is contained in:
Victor Lyuboslavsky 2024-02-28 10:53:37 -06:00 committed by GitHub
parent f36b7d4d6d
commit 22dd392da7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 12 deletions

View file

@ -705,7 +705,6 @@ func newCleanupsAndAggregationSchedule(
ctx context.Context,
instanceID string,
ds fleet.Datastore,
lq fleet.LiveQueryStore,
logger kitlog.Logger,
enrollHostLimiter fleet.EnrollHostLimiter,
config *config.FleetConfig,
@ -721,6 +720,13 @@ func newCleanupsAndAggregationSchedule(
schedule.WithAltLockID("leader"),
schedule.WithLogger(kitlog.With(logger, "cron", name)),
// Run cleanup jobs first.
schedule.WithJob(
"distributed_query_campaigns",
func(ctx context.Context) error {
_, err := ds.CleanupDistributedQueryCampaigns(ctx, time.Now().UTC())
return err
},
),
schedule.WithJob(
"incoming_hosts",
func(ctx context.Context) error {
@ -846,16 +852,16 @@ func newFrequentCleanupsSchedule(
s := schedule.New(
ctx, name, instanceID, defaultInterval, ds, ds,
// Using leader for the lock to be backwards compatilibity with old deployments.
schedule.WithAltLockID("leader"),
schedule.WithAltLockID("leader_frequent_cleanups"),
schedule.WithLogger(kitlog.With(logger, "cron", name)),
// Run cleanup jobs first.
schedule.WithJob(
"distributed_query_campaigns",
"redis_live_queries",
func(ctx context.Context) error {
_, err := ds.CleanupDistributedQueryCampaigns(ctx, time.Now().UTC())
if err != nil {
return err
}
// It's necessary to avoid lingering live queries in case of:
// - (Unknown) bug in the implementation, or,
// - Redis is so overloaded already that the lq.StopQuery in svc.CompleteCampaign fails to execute, or,
// - MySQL is so overloaded that ds.SaveDistributedQueryCampaign in svc.CompleteCampaign fails to execute.
names, err := lq.LoadActiveQueryNames()
if err != nil {
return err
@ -865,10 +871,8 @@ func newFrequentCleanupsSchedule(
if err != nil {
return err
}
if err := lq.CleanupInactiveQueries(ctx, completed); err != nil {
return err
}
return nil
err = lq.CleanupInactiveQueries(ctx, completed)
return err
},
),
)

View file

@ -697,7 +697,7 @@ the way that the Fleet server works.
commander = apple_mdm.NewMDMAppleCommander(mdmStorage, mdmPushService)
}
return newCleanupsAndAggregationSchedule(
ctx, instanceID, ds, liveQueryStore, logger, redisWrapperDS, &config, commander,
ctx, instanceID, ds, logger, redisWrapperDS, &config, commander,
)
},
); err != nil {