Skip to content

Commit 3675f8f

Browse files
authored
Clean up setup experience cancellation behavior (#43437)
Fixes #34288. # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] Added/updated automated tests - [ ] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Setup experience cancellations now create explicit cancellation activities for skipped/failed software and VPP app installs, plus a new "Canceled setup experience" activity type and a from_setup_experience flag. Activity text and host activity views now indicate "during setup experience" when applicable. * **Tests** * Added and updated tests for cancellation activity creation, VPP license-failure handling, and WasFromAutomation/from_setup_experience behaviors. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a3b7e29 commit 3675f8f

31 files changed

Lines changed: 1206 additions & 219 deletions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Added activity when setup experience is canceled due to software install failure
2+
- Added cancel activities for each VPP app install skipped due to setup experience cancellation, and switched "failed" activity to "canceled" for package-based software installs in the same situation
3+
- Added install failure activity when VPP installs fail due to licensing issues during setup experience

cmd/fleet/cron.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,7 @@ func newAppleMDMWorkerSchedule(
10701070
commander *apple_mdm.MDMAppleCommander,
10711071
bootstrapPackageStore fleet.MDMBootstrapPackageStore,
10721072
vppInstaller fleet.AppleMDMVPPInstaller,
1073+
newActivityFn fleet.NewActivityFunc,
10731074
) (*schedule.Schedule, error) {
10741075
const (
10751076
name = string(fleet.CronAppleMDMWorker)
@@ -1087,6 +1088,7 @@ func newAppleMDMWorkerSchedule(
10871088
Commander: commander,
10881089
BootstrapPackageStore: bootstrapPackageStore,
10891090
VPPInstaller: vppInstaller,
1091+
NewActivityFn: newActivityFn,
10901092
}
10911093

10921094
w.Register(appleMDM)

cmd/fleet/serve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ func runServeCmd(cmd *cobra.Command, configManager configpkg.Manager, debug, dev
12491249
if err := cronSchedules.StartCronSchedule(func() (fleet.CronSchedule, error) {
12501250
commander := apple_mdm.NewMDMAppleCommander(mdmStorage, mdmPushService)
12511251
vppInstaller := svc.(fleet.AppleMDMVPPInstaller)
1252-
return newAppleMDMWorkerSchedule(ctx, instanceID, ds, logger, commander, bootstrapPackageStore, vppInstaller)
1252+
return newAppleMDMWorkerSchedule(ctx, instanceID, ds, logger, commander, bootstrapPackageStore, vppInstaller, svc.NewActivity)
12531253
}); err != nil {
12541254
initFatal(err, "failed to register apple_mdm_worker schedule")
12551255
}

ee/server/service/devices.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,10 @@ func (svc *Service) getHostSetupExperienceStatus(ctx context.Context, host *flee
319319
return nil, ctxerr.Wrap(ctx, err, "listing setup experience results")
320320
}
321321

322-
// Mark canceled items as failed.
323-
err = svc.failCancelledSetupExperienceInstalls(ctx, host.ID, hostUUID, host.DisplayName(), results)
322+
// Add activities for canceled installs + setup experience run
323+
err = svc.recordCanceledSetupExperienceSoftwareActivities(ctx, host.ID, hostUUID, host.DisplayName(), results)
324324
if err != nil {
325-
return nil, ctxerr.Wrap(ctx, err, "failing cancelled setup experience installs")
325+
return nil, ctxerr.Wrap(ctx, err, "recording cancelled setup experience installs")
326326
}
327327

328328
var software []*fleet.SetupExperienceStatusResult

ee/server/service/orbit.go

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,8 @@ func (svc *Service) GetOrbitSetupExperienceStatus(ctx context.Context, orbitNode
169169
}
170170
}
171171

172-
err = svc.failCancelledSetupExperienceInstalls(ctx, host.ID, host.UUID, host.DisplayName(), res)
173-
if err != nil {
174-
return nil, ctxerr.Wrap(ctx, err, "failing cancelled setup experience installs")
172+
if err = svc.recordCanceledSetupExperienceSoftwareActivities(ctx, host.ID, host.UUID, host.DisplayName(), res); err != nil {
173+
return nil, ctxerr.Wrap(ctx, err, "recording cancelled setup experience installs")
175174
}
176175

177176
payload := &fleet.SetupExperienceStatusPayload{
@@ -229,7 +228,7 @@ func (svc *Service) GetOrbitSetupExperienceStatus(ctx context.Context, orbitNode
229228
return payload, nil
230229
}
231230

232-
func (svc *Service) failCancelledSetupExperienceInstalls(
231+
func (svc *Service) recordCanceledSetupExperienceSoftwareActivities(
233232
ctx context.Context,
234233
hostID uint,
235234
hostUUID string,
@@ -241,51 +240,34 @@ func (svc *Service) failCancelledSetupExperienceInstalls(
241240
continue
242241
}
243242
r.Status = fleet.SetupExperienceStatusFailure
244-
svc.logger.InfoContext(ctx, "marking setup experience software as failed due to cancellation", "host_uuid", hostUUID, "software_name", r.Name)
243+
svc.logger.InfoContext(ctx, "emitting activity for canceled setup experience software", "host_uuid", hostUUID, "software_name", r.Name)
245244
err := svc.ds.UpdateSetupExperienceStatusResult(ctx, r)
246245
if err != nil {
247-
return ctxerr.Wrap(ctx, err, "failing cancelled setup experience software install")
246+
return ctxerr.Wrap(ctx, err, "marking canceled setup experience software install as failed")
248247
}
249-
// TODO -- support recording activity for failed VPP apps as well.
250-
// https://github.com/fleetdm/fleet/issues/34288
251248
if r.IsForSoftwarePackage() {
252-
softwarePackage := ""
253-
var source *string
254-
installerMeta, err := svc.ds.GetSoftwareInstallerMetadataByID(ctx, *r.SoftwareInstallerID)
255-
if err != nil && !fleet.IsNotFound(err) {
256-
return ctxerr.Wrap(ctx, err, "getting software installer metadata for cancelled setup experience software install")
257-
}
258-
if installerMeta != nil {
259-
softwarePackage = installerMeta.Name
260-
// Get the software title to retrieve the source
261-
if installerMeta.TitleID != nil {
262-
title, err := svc.ds.SoftwareTitleByID(ctx, *installerMeta.TitleID, nil, fleet.TeamFilter{})
263-
if err != nil && !fleet.IsNotFound(err) {
264-
return ctxerr.Wrap(ctx, err, "getting software title for cancelled setup experience software install")
265-
}
266-
if title != nil {
267-
source = &title.Source
268-
}
269-
}
270-
}
271-
activity := fleet.ActivityTypeInstalledSoftware{
249+
if err := svc.NewActivity(ctx, nil, fleet.ActivityTypeCanceledInstallSoftware{
272250
HostID: hostID,
273251
HostDisplayName: hostDisplayName,
274252
SoftwareTitle: r.Name,
275-
SoftwarePackage: softwarePackage,
276-
InstallUUID: ptr.ValOrZero(r.HostSoftwareInstallsExecutionID),
277-
Status: "failed",
278-
SelfService: false,
279-
Source: source,
253+
SoftwareTitleID: ptr.ValOrZero(r.SoftwareTitleID),
280254
FromSetupExperience: true,
255+
}); err != nil {
256+
return ctxerr.Wrap(ctx, err, "creating activity for canceled setup experience software install")
281257
}
282-
err = svc.NewActivity(ctx, nil, activity)
283-
if err != nil {
284-
return ctxerr.Wrap(ctx, err, "creating activity for cancelled setup experience software install")
258+
} else if r.IsForVPPApp() {
259+
if err := svc.NewActivity(ctx, nil, fleet.ActivityTypeCanceledInstallAppStoreApp{
260+
HostID: hostID,
261+
HostDisplayName: hostDisplayName,
262+
SoftwareTitle: r.Name,
263+
SoftwareTitleID: ptr.ValOrZero(r.SoftwareTitleID),
264+
FromSetupExperience: true,
265+
}); err != nil {
266+
return ctxerr.Wrap(ctx, err, "creating activity for canceled setup experience VPP app install")
285267
}
286268
}
287-
continue
288269
}
270+
289271
return nil
290272
}
291273

0 commit comments

Comments
 (0)