fleet/server
Victor Lyuboslavsky 9c714c544d
Optimized policy_stats updates to NOT lock the policy_membership table (#18720)
#16562

Optimized policy_stats updates to NOT lock the policy_membership table.
This should improve deployment performance with many global policies and
team hosts.

The original implementation that used INSERT ... SELECT (SELECT
COUNT(*)) ... caused performance issues. Given 50 global policies, 10
teams, and 10,000 hosts per team, the INSERT query took 30-60 seconds to
complete. Since it was an INSERT query, it blocked other hosts from
updating their policy results in policy_membership.

Now, we separate the INSERT from the SELECT, since SELECT by itself does
not block other hosts from updating their policy results. In addition,
we process one global policy at a time, which reduces the time to
complete the SELECT query to <2 seconds, and limits the memory usage. We
are not using a transaction to reduce locks. This means that INSERT may
fail if the policy was deleted by a parallel process. Also, the INSERT
may overwrite a clearing of the stats. This is acceptable, since these
are very rare cases. We log and proceed in that case.


# 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. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-05-06 09:48:37 -05:00
..
authz Merge conflicts 2024-04-16 10:20:59 -05:00
bindata Allow users to be readded if they were ever removed (#1945) 2021-09-07 13:33:40 -03:00
config Added --server_frequent_cleanups_enabled (FLEET_SERVER_FREQUENT_CLEANUPS_ENABLED) flag (#17235) 2024-02-28 09:59:25 -06:00
contexts Merge branch 'main' into 15919-vulnerabilities-page 2024-02-22 16:27:15 -06:00
cron Per Figma, using default policy description/resolution if either is missing. (#18714) 2024-05-02 15:11:54 -05:00
datastore Optimized policy_stats updates to NOT lock the policy_membership table (#18720) 2024-05-06 09:48:37 -05:00
errorstore Enable errcheck linter for golangci-lint (#8899) 2022-12-05 16:50:49 -06:00
fleet AI generated policy description/resolution (#18713) 2024-05-03 15:23:27 -05:00
goose Move external dependency goose to monorepo (#15859) 2024-01-02 17:52:00 -03:00
health Separate health checks for MySQL and Redis (#6468) 2022-07-01 08:08:03 -03:00
launcher Performance stats for live queries (#15440) 2023-12-13 14:46:59 -06:00
live_query Address multiple redis-related issues observed with live queries (#16855) 2024-02-27 19:35:27 -06:00
logging Move nanodep dependency in monorepo (#16984) 2024-02-26 10:26:00 -05:00
mail Dynamically set copyright year in email templates (#16092) 2024-01-15 15:28:49 -06:00
mdm add consistent MDM host lifecycle management (#18510) 2024-04-29 16:43:15 -03:00
mock Updated datastore mock. 2024-05-02 12:14:09 -05:00
policies Refactor webhooks cron to new schedule package (#7840) 2022-09-20 14:26:36 -05:00
ptr Add Description text to CVE Metadata (#13856) 2023-09-15 11:24:10 -06:00
pubsub Address multiple redis-related issues observed with live queries (#16855) 2024-02-27 19:35:27 -06:00
service Cleanup query results after host is transferred to another team (#18712) 2024-05-03 17:37:55 -03:00
sso chore: remove refs to deprecated io/ioutil (#14485) 2023-10-27 15:28:54 -03:00
test Merge conflicts 2024-04-16 10:20:59 -05:00
version Move external dependency fleetdm/kolide-kit to monorepo (#15861) 2024-01-02 18:22:52 -03:00
vulnerabilities 18601 add ubuntu sources (#18602) 2024-05-02 13:20:00 -06:00
webhooks Calendar config updates -- policy table now has calendar_events_enabled (#17645) 2024-03-26 13:39:36 -05:00
websocket Enable errcheck linter for golangci-lint (#8899) 2022-12-05 16:50:49 -06:00
worker Adding logging level to frequent server log messages. (#18486) 2024-04-24 20:52:31 -05:00
utils.go fix: return bad request error during MDM migration when appropriate (#16551) 2024-03-06 15:38:44 -05:00
utils_test.go feature: target profiles by labels (#16202) 2024-01-26 11:00:58 -05:00