fleet/server/datastore/mysql
Jordan Montgomery 612d3de968
Mark setup experience installs as "cancelled" and later fail them when certain bulk actions happen (#29355)
Still adding tests but wanted to get this up for review of the overall
"shape" of the fix

When certain things happen like installer updates we delete pending
upcoming_activities(UA) and host_software_install(HSI) entries and need
to mark setup_experience_status_results(SESR) cancelled. When this
happens if that UA/HSI are being depended on by setup experience we need
to make sure that that setup experience result eventually gets marked
failed.

I kind of went back and forth a few times on how best to do this and
avoid race conditions. One thing I tried was looking at existence of the
UA/HSI but found that naively just trying to look at that in relation to
the SESR entry seemed to have a few race conditions that were hard to
resolve. There are a few possible states here we need to account for
such as:

un-activated, totally not yet running software install cancelled
activated but not yet running on the host software install cancelled
activated and running on the host software install cancelled before
results are completely reported back

What I eventually came around to was essentially that we want to mark
the SESR cancelled in the same transaction we delete the HSI/UA in. We
then finalize it by marking it failed and sending the activity the next
time the host fetches setupm experience results. The new cancelled
status never leaves fleet. This is a bit ugly but in my testing avoided
the race conditions and works well.

Note that to actually avoid setup experience hanging entirely we still
need to fix #29357 which encompasses several cases where the unified
queue can get completely stuck for a host

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [ ] 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.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Added/updated automated tests
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Make sure fleetd is compatible with the latest released version of
Fleet (see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)).
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
- [ ] For unreleased bug fixes in a release candidate, confirmed that
the fix is not expected to adversely impact load test results or alerted
the release DRI if additional load testing is needed.
2025-05-27 16:52:51 -04:00
..
common_mysql Basic Android enroll functionality (#26386) 2025-02-24 14:31:21 -06:00
migrations Mark setup experience installs as "cancelled" and later fail them when certain bulk actions happen (#29355) 2025-05-27 16:52:51 -04:00
activities.go Bugfix: catch-all cron job to avoid blocked upcoming activities queue (#29477) 2025-05-27 16:38:39 -04:00
activities_test.go Bugfix: catch-all cron job to avoid blocked upcoming activities queue (#29477) 2025-05-27 16:38:39 -04:00
aggregated_stats.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
aggregated_stats_test.go Performance stats for live queries (#15440) 2023-12-13 14:46:59 -06:00
android.go Refactoring Android datastore interface (#26982) 2025-03-13 14:28:52 -05:00
android_test.go Refactoring Android datastore interface (#26982) 2025-03-13 14:28:52 -05:00
app_configs.go Update to Go 1.24.1 (#27506) 2025-03-31 11:14:09 -05:00
app_configs_test.go Include Linux disk encryption status in configuration profiles aggregate status response when applicable, fix disk encryption/MDM configuration order-of-operations issues, add integration tests for LUKS (#24114) 2024-11-25 08:34:43 -06:00
apple_mdm.go BRP: cancel profile delivery on deletion of profiles in batch via fleetctl gitops (#29145) 2025-05-21 10:50:38 -04:00
apple_mdm_ddm_test.go Fixing issues with Apple DDM profile status (#29059) 2025-05-15 13:05:25 -05:00
apple_mdm_test.go BRP: cancel single profile on delete via UI (#29107) 2025-05-20 08:55:51 -04:00
ca_config_assets.go Add custom SCEP configs (#27045) 2025-03-14 12:16:51 -05:00
ca_config_assets_test.go Add custom SCEP configs (#27045) 2025-03-14 12:16:51 -05:00
calendar_events.go Enable staticcheck Go linter. (#23487) 2024-11-05 11:16:24 -06:00
calendar_events_test.go Correctly handle NULL timezones (#20605) 2024-07-22 10:04:29 -07:00
campaigns.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
campaigns_test.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
carves.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
carves_test.go
config.go Refactoring common mysql (#26367) 2025-02-18 15:28:54 -06:00
cron_stats.go Monitor and alert on errors in cron jobs (#24347) 2024-12-19 15:55:29 -06:00
cron_stats_test.go Monitor and alert on errors in cron jobs (#24347) 2024-12-19 15:55:29 -06:00
delete.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
delete_test.go Updated factory method for creating queries in tests 2023-07-07 09:05:51 -04:00
disk_encryption.go Re-verify Linux disk encryption #26693 (#29034) 2025-05-22 16:15:26 -04:00
disk_encryption_test.go Re-verify Linux disk encryption #26693 (#29034) 2025-05-22 16:15:26 -04:00
email_changes.go Add mechanism to force read from primary DB, use it for puppet matching (#12396) 2023-06-19 13:55:15 -04:00
email_changes_test.go
errors.go Refactoring common mysql (#26367) 2025-02-18 15:28:54 -06:00
fulltext.go Update to Go 1.24.1 (#27506) 2025-03-31 11:14:09 -05:00
fulltext_test.go
host_certificates.go NDES cert renewal (#28712) 2025-05-01 12:16:45 -05:00
host_certificates_test.go Custom SCEP renewal (#28616) 2025-04-30 15:31:45 -04:00
hosts.go add host filtering by mdm config profile and the profile status (#29287) 2025-05-21 18:29:13 +01:00
hosts_test.go add host filtering by mdm config profile and the profile status (#29287) 2025-05-21 18:29:13 +01:00
invites.go Allow opting in users to email verification on login (#24273) 2024-12-05 08:37:10 -06:00
invites_test.go Allow opting in users to email verification on login (#24273) 2024-12-05 08:37:10 -06:00
jobs.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
jobs_test.go Send DeviceConfigured MDM command after DEP enrollment (#17737) 2024-03-25 13:25:29 -04:00
labels.go Add author ID to labels (#27055) 2025-03-20 16:05:16 -05:00
labels_test.go IdP vars: store profile-variable associations when new profile is created/updated (#28645) 2025-04-30 16:03:23 -04:00
linux_mdm.go Linux OS settings + disk encryption host filter fixes (#24200) 2024-11-26 19:26:22 -06:00
linux_mdm_test.go Disk encryption keys are now archived when created/updated (#25638) 2025-01-22 14:54:40 -06:00
locks.go Optimize software_titles query to use indexes (#25722) 2025-01-23 15:48:21 -03:00
locks_test.go Improvements for select next Apple MDM command query. (#24128) 2024-12-05 12:02:48 -06:00
maintained_apps.go Support for fleet maintained apps in gitops (#28751) 2025-05-07 18:16:08 -05:00
maintained_apps_test.go Support for fleet maintained apps in gitops (#28751) 2025-05-07 18:16:08 -05:00
mdm.go Add timestamp to host_mdm_apple_profiles for variable update times (#29074) 2025-05-13 17:22:27 -04:00
mdm_test.go BRP: cancel profile delivery on deletion of profiles in batch via fleetctl gitops (#29145) 2025-05-21 10:50:38 -04:00
microsoft_mdm.go BRP: cancel profile delivery on deletion of profiles in batch via fleetctl gitops (#29145) 2025-05-21 10:50:38 -04:00
microsoft_mdm_test.go IdP vars: add integration test, address last PR comments (#28794) 2025-05-05 11:46:10 -04:00
migrations_test.go Refactoring common mysql (#26367) 2025-02-18 15:28:54 -06:00
mysql.go Refactoring Android datastore interface (#26982) 2025-03-13 14:28:52 -05:00
mysql_test.go Refactoring common mysql (#26367) 2025-02-18 15:28:54 -06:00
nanomdm_storage.go Bugfix: Clear the unified queue when turning off and re-enrolling in MDM (#26816) 2025-03-05 08:59:07 -05:00
nanomdm_storage_test.go 19016 ingest certs on start (#19360) 2024-05-30 18:18:42 -03:00
operating_system_vulnerabilities.go Don't update updated_at on OS vulnerabilities when nothing changed in the result (#28429) 2025-04-22 09:07:18 -04:00
operating_system_vulnerabilities_test.go Don't update updated_at on OS vulnerabilities when nothing changed in the result (#28429) 2025-04-22 09:07:18 -04:00
operating_systems.go Android scaffold (#26274) 2025-02-13 14:32:19 -06:00
operating_systems_test.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
packs.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
packs_test.go Enable staticcheck Go linter. (#23487) 2024-11-05 11:16:24 -06:00
password_reset.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
password_reset_test.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
policies.go Add GitOps for policy labels (#27781) 2025-04-04 09:46:51 -05:00
policies_test.go Bugfix: Activate next activity on delete policy with associated software install/script exec (#29450) 2025-05-27 15:08:16 -04:00
queries.go Add retry when applying queries (#28951) 2025-05-13 12:06:20 -05:00
queries_test.go Add labels to queries using gitops (#27259) 2025-03-20 15:32:52 -05:00
query_results.go Added server_settings.query_report_cap (#19692) 2024-06-14 12:24:01 -03:00
query_results_test.go Added server_settings.query_report_cap (#19692) 2024-06-14 12:24:01 -03:00
scep.go 19016 ingest certs on start (#19360) 2024-05-30 18:18:42 -03:00
scep_test.go use Fleet instead of FleetDM in certificates (#19748) 2024-06-14 11:08:49 -03:00
scheduled_queries.go Update to Go 1.24.1 (#27506) 2025-03-31 11:14:09 -05:00
scheduled_queries_test.go Performance stats for live queries (#15440) 2023-12-13 14:46:59 -06:00
schema.sql Mark setup experience installs as "cancelled" and later fail them when certain bulk actions happen (#29355) 2025-05-27 16:52:51 -04:00
scim.go Improve MDM device-to-user mapping for Apple devices (#29239) 2025-05-19 13:29:46 -05:00
scim_test.go BRP: cancel single profile on delete via UI (#29107) 2025-05-20 08:55:51 -04:00
scripts.go Bugfix: Activate next activity on batch-set scripts (delete/edit) (#29456) 2025-05-27 15:45:09 -04:00
scripts_test.go Bugfix: Activate next activity on batch-set scripts (delete/edit) (#29456) 2025-05-27 15:45:09 -04:00
secret_variables.go Exclude certain sections from var interpolation when running gitops cmd (#28625) 2025-04-29 15:09:25 -04:00
secret_variables_test.go Update Apple config/DDM profiles if secret variables changed (#24995) 2024-12-30 17:58:39 -06:00
sessions.go Include expiration info, drop "personalized", in MFA email (#24630) 2024-12-10 18:58:40 -06:00
sessions_test.go Include expiration info, drop "personalized", in MFA email (#24630) 2024-12-10 18:58:40 -06:00
setup_experience.go feat: do not run setup experience on hosts in a team with no software or script configured (#24073) 2024-11-22 13:52:28 -05:00
setup_experience_test.go SSVL: Add labels to upload endpoint; add validations and related datastore methods (#24733) 2024-12-16 18:17:13 -06:00
software.go Added SHA256 hash from mac apps on install paths (#29280) 2025-05-20 23:38:59 -05:00
software_installers.go Mark setup experience installs as "cancelled" and later fail them when certain bulk actions happen (#29355) 2025-05-27 16:52:51 -04:00
software_installers_test.go Mark setup experience installs as "cancelled" and later fail them when certain bulk actions happen (#29355) 2025-05-27 16:52:51 -04:00
software_test.go Added SHA256 hash from mac apps on install paths (#29280) 2025-05-20 23:38:59 -05:00
software_titles.go Move fleet_maintained_app_id from title level to package level in software title list endpoint (#29033) 2025-05-12 12:37:09 -05:00
software_titles_test.go Add hash_sha256 field to "List Software Titles" API response (#28447) 2025-04-24 12:08:59 -05:00
statistics.go Add statistic to measure ABM pending hosts (#28226) 2025-04-15 11:30:07 -04:00
statistics_test.go Add statistic to measure ABM pending hosts (#28226) 2025-04-15 11:30:07 -04:00
targets.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
targets_test.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
teams.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
teams_test.go IdP vars: store profile-variable associations when new profile is created/updated (#28645) 2025-04-30 16:03:23 -04:00
testing_utils.go Bugfix: Activate next activity on delete policy with associated software install/script exec (#29450) 2025-05-27 15:08:16 -04:00
unicode_test.go Bugfix: only count hosts that user has permission to see in count field of label endpoints (#18859) 2024-05-21 12:02:08 -04:00
users.go Added Android activity and better handling of deleted users. (#26640) 2025-02-27 14:19:15 -06:00
users_test.go Added Android activity and better handling of deleted users. (#26640) 2025-02-27 14:19:15 -06:00
vpp.go feat: software categories in gitops (#28863) 2025-05-07 11:19:33 -04:00
vpp_test.go fix: don't re-use title ID from a windows app for a vpp app (#26546) 2025-02-24 17:51:12 -05:00
vulnerabilities.go Adjust vuln host count batch size (#25957) 2025-01-31 16:49:36 -07:00
vulnerabilities_test.go Refactoring common mysql (#26367) 2025-02-18 15:28:54 -06:00
windows_updates.go Add mechanism to force read from primary DB, use it for puppet matching (#12396) 2023-06-19 13:55:15 -04:00
windows_updates_test.go Updating golangci-lint to 1.61.0 (#22973) 2024-10-18 12:38:26 -05:00
wstep.go Add certificate management for Microsoft MDM (WSTEP) (#12543) 2023-06-29 19:31:53 -03:00
wstep_test.go Move nanomdm dependency in monorepo (#16015) 2024-01-11 23:28:48 -03:00