fleet/server/fleet
Lucas Manuel Rodriguez 6415f062c6
Reduce size of DistributedQueryResult to improve live query performance (#11882)
This was found while working on #10957.

When running a live query, a lot of unused host data is stored in Redis
and sent on every live query result message via websockets. The frontend
and fleetctl just need `id`, `hostname` and `display_name`. (This
becomes worse every time we add new fields to the `Host` struct.)

Sample of one websocket message result when running `SELECT * from
osquery_info;`:

size in `main`: 2234 bytes
```
a["{\"type\":\"result\",\"data\":{\"distributed_query_execution_id\":57,\"host\":
{\"created_at\":\"2023-05-22T12:14:11Z\",\"updated_at\":\"2023-05-23T12:31:51Z\",
\"software_updated_at\":\"0001-01-01T00:00:00Z\",\"id\":106,\"detail_updated_at\":\"2023-05-23T11:50:04Z\",
\"label_updated_at\":\"2023-05-23T11:50:04Z\",\"policy_updated_at\":\"1970-01-02T00:00:00Z\",
\"last_enrolled_at\":\"2023-05-22T12:14:12Z\",
\"seen_time\":\"2023-05-23T09:52:23.876311-03:00\",\"refetch_requested\":false,
\"hostname\":\"lucass-macbook-pro.local\",\"uuid\":\"BD4DFA10-E334-41D9-8136-D2163A8FE588\",\"platform\":\"darwin\",\"osquery_version\":\"5.8.2\",\"os_version\":\"macOS 13.3.1\",\"build\":\"22E261\",\"platform_like\":\"darwin\",\"code_name\":\"\",
\"uptime\":91125000000000,\"memory\":34359738368,\"cpu_type\":\"x86_64h\",\"cpu_subtype\":\"Intel x86-64h Haswell\",\"cpu_brand\":\"Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz\",\"cpu_physical_cores\":4,\"cpu_logical_cores\":8,\"hardware_vendor\":\"Apple Inc.\",\"hardware_model\":\"MacBookPro16,2\",\"hardware_version\":\"1.0\",
\"hardware_serial\":\"0DPQR4HMD1FZ\",
\"computer_name\":\"Lucas’s MacBook Pro\",\"public_ip\":\"\",
\"primary_ip\":\"192.168.0.230\",\"primary_mac\":\"68:2f:67:8e:b6:1f\",
\"distributed_interval\":1,\"config_tls_refresh\":60,\"logger_tls_period\":10,\"team_id\":null,
\"pack_stats\":null,\"team_name\":null,
\"gigs_disk_space_available\":386.23,\"percent_disk_space_available\":40,
\"issues\":{\"total_issues_count\":0,\"failing_policies_count\":0},
\"mdm\":{\"enrollment_status\":null,\"server_url\":null,\"name\":\"\",\"encryption_key_available\":false},
\"status\":\"online\",\"display_text\":\"lucass-macbook-pro.local\",\"display_name\":\"Lucas’s MacBook Pro\"},
\"rows\":[{\"build_distro\":\"10.14\",\"build_platform\":\"darwin\",
\"config_hash\":\"b7ee9363a7c686e76e99ffb122e9c5241a791e69\",\"config_valid\":\"1\",
\"extensions\":\"active\",\"host_display_name\":\"Lucas’s MacBook Pro\",
\"host_hostname\":\"lucass-macbook-pro.local\",\"instance_id\":\"cde5de81-344b-4c76-b1c5-dae964fdd4f2\",\"pid\":\"8370\",\"platform_mask\":\"21\",\"start_time\":\"1684757652\",
\"uuid\":\"BD4DFA10-E334-41D9-8136-D2163A8FE588\",
\"version\":\"5.8.2\",\"watcher\":\"8364\"}],\"error\":null}}"]
```

vs. size of the message result on this branch: 675 bytes
```
a["{\"type\":\"result\",\"data\":{\"distributed_query_execution_id\":59,
\"host\":{\"id\":106,\"hostname\":\"lucass-macbook-pro.local\",
\"display_name\":\"Lucas’s MacBook Pro\"},
\"rows\":[{\"build_distro\":\"10.14\",\"build_platform\":\"darwin\",
\"config_hash\":\"f80dee827635db39077a458243379b3ad63311fd\",
\"config_valid\":\"1\",\"extensions\":\"active\",\"host_display_name\":\"Lucas’s MacBook Pro\",
\"host_hostname\":\"lucass-macbook-pro.local\",
\"instance_id\":\"cde5de81-344b-4c76-b1c5-dae964fdd4f2\",\"pid\":\"8370\",\"platform_mask\":\"21\",
\"start_time\":\"1684757652\",\"uuid\":\"BD4DFA10-E334-41D9-8136-D2163A8FE588\",\"version\":\"5.8.2\",
\"watcher\":\"8364\"}]}}"]
```

Manual tests included running with an old fleetctl running with a new
fleet server, and vice-versa, a new fleetctl running against an old
fleet server.

- [X] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [X] Documented any API changes (docs/Using-Fleet/REST-API.md or
docs/Contributing/API-for-contributors.md)
- ~[ ] Documented any permissions changes~
- ~[ ] 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.~
- [X] Added/updated tests
- [X] Manual QA for all new/changed functionality
  - ~For Orbit and Fleet Desktop changes:~
- ~[ ] 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)).~
2023-05-25 08:11:53 -03:00
..
policytest Migrate team-related endpoints to new pattern (#3740) 2022-01-19 10:52:14 -05:00
activities.go Allow end user authentication during automatic MDM enrollment to be enabled on a per-team basis (#11566) 2023-05-10 15:22:08 -05:00
agent_options.go Allow tls_dump in agent settings (#9916) 2023-02-20 11:24:12 -03:00
agent_options_test.go Remove value validation of agent_options.{packs,schedule} (#8066) 2022-10-03 16:43:47 -04:00
app.go Add mdm.macos_migration to app config endpoints (#11694) 2023-05-15 11:50:07 -05:00
app_test.go Add mdm.macos_migration to app config endpoints (#11694) 2023-05-15 11:50:07 -05:00
apple_mdm.go Track host DEP assignments in new table (#11875) 2023-05-23 13:01:04 -05:00
apple_mdm_test.go Track host DEP assignments in new table (#11875) 2023-05-23 13:01:04 -05:00
authz.go Remove old mdm_command action (do we really need it?) (#11222) 2023-04-18 07:53:33 -03:00
campaigns.go Reduce size of DistributedQueryResult to improve live query performance (#11882) 2023-05-25 08:11:53 -03:00
capabilities.go token rotation for fleet desktop (#7779) 2022-10-10 17:15:35 -03:00
capabilities_test.go add headers denoting capabilities between fleet server / desktop / orbit (#7833) 2022-09-26 07:53:53 -03:00
carves.go report errors that can occur during file carving (#8972) 2022-12-09 13:21:30 -03:00
cron_schedules.go Allow "not_before" timestamp for worker jobs, schedule more quickly (#11512) 2023-05-03 16:25:36 -04:00
datastore.go Track host DEP assignments in new table (#11875) 2023-05-23 13:01:04 -05:00
db.go Add the fleetctl debug {errors,db-locks} sub-commands (#3168) 2021-12-06 09:26:01 -05:00
device.go add migration support to FD and orbit (#11741) 2023-05-18 14:21:54 -03:00
emails.go Remove unneeded interfaces (#1779) 2021-08-24 18:49:56 -03:00
errors.go Add device-authenticated endpoint to trigger MDM migration webhook request (#11724) 2023-05-17 09:16:26 -05:00
errors_test.go Validate team spec unknown keys (#8265) 2022-10-24 08:49:44 -04:00
fleetctl.go Remove kolide types and packages from backend (#974) 2021-06-06 15:07:29 -07:00
gen_activity_doc.go Make activities typed and auto-generate docs for each type (#9069) 2022-12-23 13:05:16 -03:00
geoip.go Produce hosts' CSV report based on requested columns (#5656) 2022-05-10 14:25:53 -04:00
global_schedule.go Remove unneeded interfaces (#1779) 2021-08-24 18:49:56 -03:00
hostresponse.go /api/_version_/fleet/hosts to return bad request instead of server error when passing invalid mdm_enrollment_status (#11242) 2023-04-19 18:43:15 -03:00
hosts.go Track host DEP assignments in new table (#11875) 2023-05-23 13:01:04 -05:00
hosts_test.go base logic to show/hide the new Migrate to Fleet FD menu (#11679) 2023-05-15 17:00:52 -03:00
installer.go add a new tool to upload installers to blob storage (#6661) 2022-07-14 16:11:52 -03:00
integrations.go Validate team and appconfig payloads, with dry-run and force modes (#7731) 2022-09-19 13:53:44 -04:00
invites.go Add update invite API (#2837) 2021-11-11 17:33:06 -03:00
jobs.go Allow "not_before" timestamp for worker jobs, schedule more quickly (#11512) 2023-05-03 16:25:36 -04:00
labels.go Add label information to host summary response (#5573) 2022-05-10 10:32:55 -05:00
live_query_store.go Remove kolide types and packages from backend (#974) 2021-06-06 15:07:29 -07:00
logging.go Remove kolide types and packages from backend (#974) 2021-06-06 15:07:29 -07:00
mdm.go pre-populate username/fullname during account creation (#11557) 2023-05-18 12:50:00 -03:00
mdm_test.go implement bootstrap packages during DEP enrollment (#11052) 2023-04-07 17:31:02 -03:00
meta.go add attribute to GET /activities endpoint with pagination metadata (#9279) 2023-01-18 12:57:11 +00:00
network_interfaces.go Remove kolide types and packages from backend (#974) 2021-06-06 15:07:29 -07:00
nudge.go Break up MDM docs to be smaller articles for improved readability. (#10538) 2023-03-17 12:34:35 -07:00
operating_systems.go Add new database tables and queries for host operating systems (#6920) 2022-08-09 13:34:41 -05:00
orbit.go add migration support to FD and orbit (#11741) 2023-05-18 14:21:54 -03:00
osquery.go Remove unneeded interfaces (#1779) 2021-08-24 18:49:56 -03:00
packs.go Fix permissions on GitOps user for searching hosts or count targets (#11448) 2023-05-01 12:57:28 -03:00
packs_test.go Fix incorrect integer conversion (#10188) 2023-02-28 18:01:25 -08:00
policies.go Remove attach check on queries and return proper bad request error (#10427) 2023-03-13 11:42:26 -03:00
queries.go Remove attach check on queries and return proper bad request error (#10427) 2023-03-13 11:42:26 -03:00
queries_test.go Remove attach check on queries and return proper bad request error (#10427) 2023-03-13 11:42:26 -03:00
query_results.go Remove kolide types and packages from backend (#974) 2021-06-06 15:07:29 -07:00
redis_pool.go Use a redis cluster-friendly store for rate limit (#2577) 2021-10-19 16:24:13 -04:00
scheduled_queries.go Clone AppConfig and ScheduledQuery list by hand to improve CPU usage (#8794) 2022-11-23 12:04:06 -03:00
service.go Track host DEP assignments in new table (#11875) 2023-05-23 13:01:04 -05:00
sessions.go New observer_plus role (#10675) 2023-04-05 15:23:49 -03:00
sessions_test.go Allow setting user roles during JIT provisioning (#10193) 2023-03-01 20:18:40 -03:00
software.go Feature 10196: Add filepath to end-points and third party integrations (#11285) 2023-05-17 16:53:15 -04:00
software_test.go Clean out-of-date NVD results. (#10514) 2023-04-03 13:45:18 -04:00
statistics.go Add orbit version and osquery version usage statistics (#8229) 2022-10-24 11:12:56 -05:00
targets.go Update live query selector logic (OR -> AND) (#9559) 2023-01-30 18:35:56 -03:00
targets_test.go Optimize requests on packs page (#3327) 2021-12-13 21:50:24 -08:00
teams.go Add support for the mdm.macos_setup.macos_setup_assistant key in fleetctl, API (#11296) 2023-04-25 09:36:01 -04:00
teams_test.go New gitops role (#10850) 2023-04-12 16:11:04 -03:00
traits.go Add support for downloading a list of hosts in CSV format (#4596) 2022-03-15 15:14:42 -04:00
translator.go Remove unneeded interfaces (#1779) 2021-08-24 18:49:56 -03:00
user_roles.go Remove unneeded interfaces (#1779) 2021-08-24 18:49:56 -03:00
users.go Add display_name to more results (#8204) 2022-10-14 11:14:18 -03:00
users_test.go Add UUID to Fleet errors and clean up error msgs (#10411) 2023-03-13 13:44:06 -03:00
utils.go Flag when the Apple BM terms have expired (#9091) 2023-01-06 17:44:20 -03:00
vulnerabilities.go Feature 9834: Add published date to vulnerability object (#10434) 2023-03-28 16:11:31 -04:00
windows_updates.go Feature 7076: Ingest installed windows updates (#7138) 2022-08-26 14:55:03 -04:00
windows_updates_tests.go Feature 7076: Ingest installed windows updates (#7138) 2022-08-26 14:55:03 -04:00