Split up apple and windows profile management cron jobs (#23975)

for #22824 

This PR splits up the `newMDMProfileManager` function into two functions
`newAppleMDMProfileManager` and `newWindowsMDMProfileManager`, the
latter containing the code to start the windows-specific profile
management job. This allows scheduling and scaling the Apple and Windows
profile management jobs separately.

Tested locally by checking that the jobs were scheduled at startup, and
then triggering the `mdm_apple_profile_manager` and
`mdm_windows_profile_manager` schedules via the `/trigger` API; nothing
blew up.
This commit is contained in:
Scott Gress 2024-11-26 16:57:32 -06:00 committed by GitHub
parent e7605d2d2f
commit 98917e7547
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 49 additions and 4 deletions

View file

@ -1182,7 +1182,7 @@ func appleMDMDEPSyncerJob(
}
}
func newMDMProfileManager(
func newAppleMDMProfileManagerSchedule(
ctx context.Context,
instanceID string,
ds fleet.Datastore,
@ -1207,6 +1207,29 @@ func newMDMProfileManager(
schedule.WithJob("manage_apple_declarations", func(ctx context.Context) error {
return service.ReconcileAppleDeclarations(ctx, ds, commander, logger)
}),
)
return s, nil
}
func newWindowsMDMProfileManagerSchedule(
ctx context.Context,
instanceID string,
ds fleet.Datastore,
logger kitlog.Logger,
) (*schedule.Schedule, error) {
const (
name = string(fleet.CronMDMWindowsProfileManager)
// Note: per a request from #g-product we are running this cron
// every 30 seconds, we should re-evaluate how we handle the
// cron interval as we scale to more hosts.
defaultInterval = 30 * time.Second
)
logger = kitlog.With(logger, "cron", name)
s := schedule.New(
ctx, name, instanceID, defaultInterval, ds, ds,
schedule.WithLogger(logger),
schedule.WithJob("manage_windows_profiles", func(ctx context.Context) error {
return service.ReconcileWindowsProfiles(ctx, ds, logger)
}),

View file

@ -23,14 +23,24 @@ import (
kitlog "github.com/go-kit/log"
)
func TestNewMDMProfileManagerWithoutConfig(t *testing.T) {
func TestNewAppleMDMProfileManagerWithoutConfig(t *testing.T) {
ctx := context.Background()
mdmStorage := &mdmmock.MDMAppleStore{}
ds := new(mock.Store)
cmdr := apple_mdm.NewMDMAppleCommander(mdmStorage, nil)
logger := kitlog.NewNopLogger()
sch, err := newMDMProfileManager(ctx, "foo", ds, cmdr, logger)
sch, err := newAppleMDMProfileManagerSchedule(ctx, "foo", ds, cmdr, logger)
require.NotNil(t, sch)
require.NoError(t, err)
}
func TestNewWindowsMDMProfileManagerWithoutConfig(t *testing.T) {
ctx := context.Background()
ds := new(mock.Store)
logger := kitlog.NewNopLogger()
sch, err := newWindowsMDMProfileManagerSchedule(ctx, "foo", ds, logger)
require.NotNil(t, sch)
require.NoError(t, err)
}

View file

@ -924,7 +924,7 @@ the way that the Fleet server works.
}
if err := cronSchedules.StartCronSchedule(func() (fleet.CronSchedule, error) {
return newMDMProfileManager(
return newAppleMDMProfileManagerSchedule(
ctx,
instanceID,
ds,
@ -935,6 +935,17 @@ the way that the Fleet server works.
initFatal(err, "failed to register mdm_apple_profile_manager schedule")
}
if err := cronSchedules.StartCronSchedule(func() (fleet.CronSchedule, error) {
return newWindowsMDMProfileManagerSchedule(
ctx,
instanceID,
ds,
logger,
)
}); err != nil {
initFatal(err, "failed to register mdm_windows_profile_manager schedule")
}
if err := cronSchedules.StartCronSchedule(func() (fleet.CronSchedule, error) {
return newMDMAPNsPusher(
ctx,

View file

@ -21,6 +21,7 @@ const (
CronWorkerIntegrations CronScheduleName = "integrations"
CronActivitiesStreaming CronScheduleName = "activities_streaming"
CronMDMAppleProfileManager CronScheduleName = "mdm_apple_profile_manager"
CronMDMWindowsProfileManager CronScheduleName = "mdm_windows_profile_manager"
CronAppleMDMIPhoneIPadRefetcher CronScheduleName = "apple_mdm_iphone_ipad_refetcher"
CronAppleMDMAPNsPusher CronScheduleName = "apple_mdm_apns_pusher"
CronCalendar CronScheduleName = "calendar"