fleet icon indicating copy to clipboard operation
fleet copied to clipboard

Improve host search by end user email address

Open marko-lisica opened this issue 2 years ago • 11 comments

Goal

User story
As a IT admin searching hosts,
I want any search query to surface results from human-host mapping information
so that I don't need to type a valid email address to find relevant hosts.

Changes

Product

  • [x] UI changes: Figma
    • UI changes are also implemented in this draft PR. If approved/merged, all remaining work is backend.
  • [x] CLI (fleetctl) usage changes: No changes
  • [X] YAML changes: No changes
  • [X] REST API changes: PR
  • [X] Fleet's agent (fleetd) changes: No changes
  • [X] Fleet server configuration changes: No changes
  • [X] Exposed, public API endpoint changes: No changes
  • [X] fleetdm.com changes: No changes
  • [X] GitOps mode UI changes: No changes
  • [X] GitOps generation changes: No changes
  • [X] Activity changes: No changes
  • [X] Permissions changes: No changes
  • [X] Changes to paid features or tiers: Fleet Free
  • [X] My device and fleetdm.com/better changes: No changes
  • [X] Usage statistics: No changes
  • [X] Other reference documentation changes: No changes
  • [X] First draft of test plan added
  • [ ] Once shipped, requester has been notified
  • [ ] Once shipped, dogfooding issue has been filed

Engineering

  • [x] Test plan is finalized
  • [X] Contributor API changes: No changes.
  • [X] Feature guide changes: No changes.
  • [X] Load testing: Yes. See below.
  • [X] Load testing/osquery-perf improvements: osquery-perf already has support for Google profiles, but given we don't have capabilities to set IdP username in osquery-perf we will need a DB script to populate hosts with IdP e-mails.
  • [X] This is a premium only feature: No.

Backend changes

  1. Update GET /api/latest/fleet/hosts, GET /api/latest/fleet/hosts/count, and GET /api/latest/fleet/hosts/report with the change to always look for e-mail in hosts.
  2. Script (or DB script) to populate IdP e-mails for hosts on an environment. To be used in load tests.

QA

Risk assessment

  • Requires load testing: Yes
  • Risk level: Low

Test plan

Setup

  • Make sure to populate hosts with Google chrome profile e-mails only.
  • Make sure to populate hosts with IdP e-mail only.
  • Make sure to populate hosts with both IdP and Google chrome profile e-mails.
  • Make sure to have hosts without any e-mail association.

Tests

  • In UI: Test that typing the first part of a known end user email (before the @) surfaces the host with that end user.
  • Test querying an incomplete email (no @) in all updated API endpoints:
    • List hosts (check returned list is accurate)
    • Count hosts (check host count reported in UI)
    • Get hosts report in CSV (check exported report matches UI)

Load test

Make sure to use script created by developer to populate IdP records for all hosts in the load test environment. UI to filter hosts by e-mail should be as responsive as before the change.

Below is the SQL used by @nulmete to populate hosts and associated emails below. NOTE: this error was raised when running the first INSERT query that inserts 10k hosts:

SQL Error [3636] [HY000]: Recursive query aborted after 1001 iterations. Try increasing @@cte_max_recursion_depth to a larger value.

To fix that, I ran:

SET cte_max_recursion_depth = 10000;
-- Seed 10k hosts for performance testing email search.
-- Distribution (by osquery_host_id suffix):
--   1-2500:    Chrome profile email only
--   2501-5000: IdP email only
--   5001-7500: Both Chrome profile and IdP emails
--   7501-10000: No email association

-- Generate 10k hosts using a recursive CTE
INSERT INTO hosts (osquery_host_id, node_key, hostname, uuid, platform, detail_updated_at, label_updated_at, policy_updated_at)
WITH RECURSIVE seq AS (
  SELECT 1 AS n
  UNION ALL
  SELECT n + 1 FROM seq WHERE n < 10000
)
SELECT
  CONCAT('perf-osq-', n),
  CONCAT('perf-nk-', n),
  CONCAT('perf-host-', n),
  CONCAT('perf-uuid-', n),
  'darwin',
  NOW(),
  '2000-01-01 00:00:00',
  '2000-01-01 00:00:00'
FROM seq;

-- Populate display names so that hosts are visible in the UI.
INSERT INTO host_display_names (host_id, display_name)
SELECT id, hostname
FROM hosts
WHERE osquery_host_id LIKE 'perf-osq-%';

-- 1-2500: Chrome profile email only
INSERT INTO host_emails (host_id, email, source)
SELECT id, CONCAT('chrome-', id, '@example.com'), 'google_chrome_profiles'
FROM hosts
WHERE osquery_host_id LIKE 'perf-osq-%'
  AND CAST(SUBSTRING(osquery_host_id, 10) AS UNSIGNED) BETWEEN 1 AND 2500;

-- 2501-5000: IdP email only
INSERT INTO host_emails (host_id, email, source)
SELECT id, CONCAT('idp-', id, '@example.com'), 'mdm_idp_accounts'
FROM hosts
WHERE osquery_host_id LIKE 'perf-osq-%'
  AND CAST(SUBSTRING(osquery_host_id, 10) AS UNSIGNED) BETWEEN 2501 AND 5000;

-- 5001-7500: Both Chrome profile and IdP emails
INSERT INTO host_emails (host_id, email, source)
SELECT id, CONCAT('chrome-', id, '@example.com'), 'google_chrome_profiles'
FROM hosts
WHERE osquery_host_id LIKE 'perf-osq-%'
  AND CAST(SUBSTRING(osquery_host_id, 10) AS UNSIGNED) BETWEEN 5001 AND 7500;

INSERT INTO host_emails (host_id, email, source)
SELECT id, CONCAT('idp-', id, '@example.com'), 'mdm_idp_accounts'
FROM hosts
WHERE osquery_host_id LIKE 'perf-osq-%'
  AND CAST(SUBSTRING(osquery_host_id, 10) AS UNSIGNED) BETWEEN 5001 AND 7500;

-- 7501-10000: no emails (nothing to insert)

-- Cleanup:
-- DELETE FROM host_emails WHERE host_id IN (SELECT id FROM hosts WHERE osquery_host_id LIKE 'perf-osq-%');
-- DELETE FROM host_display_names WHERE host_id IN (SELECT id FROM hosts WHERE osquery_host_id LIKE 'perf-osq-%');
-- DELETE FROM hosts WHERE osquery_host_id LIKE 'perf-osq-%';

Confirmation

  1. [x] Engineer: Added comment to user story confirming successful completion of test plan.
  2. [x] QA: Added comment to user story confirming successful completion of test plan.

marko-lisica avatar Dec 19 '23 16:12 marko-lisica

Heads up @marko-lisica this request was discussed during feature fest last week and didn't make it into the current design sprint.

noahtalerman avatar Jan 10 '24 14:01 noahtalerman

Hey @pintomi1989 heads up, this story was prioritized during feature fest.

Aiming to ship an improvement in the next 6 weeks.

noahtalerman avatar Mar 08 '24 15:03 noahtalerman

Hey team! Please add your planning poker estimate with Zenhub @dantecatalfamo @ghernandez345 @gillespi314 @jahzielv @mna @roperzh

georgekarrv avatar Mar 13 '24 16:03 georgekarrv

FYI @rachaelshaw brought another story into the current sprint. I think this one will be quick to design. Let me know if the design sprint is getting too big.

noahtalerman avatar Oct 17 '25 21:10 noahtalerman

FYI @rachaelshaw just chatted w/ Sharon and we decided to push this out of 4.78! I unassigned you and removed this story from the drafting board.

noahtalerman avatar Oct 21 '25 18:10 noahtalerman

Updating the description to use the latest story template, so adding the original engineering notes here (they should still be relevant):

  • Requires changing how we detect if a search could be an email address, which was done for performance reasons to avoid joining with host_emails unless necessary.
  • We should plan load testing the new search to see if the impact is acceptable at scale for non-email searches.
  • We have a special-case in place to do an additional search when non-ASCII is used (to account for unicode chars equivalence, IIRC it was mostly for things like apostrophes), but now we would do it even if it includes the email search (since we wouldn't detect the search as being "email-like")
  • This also affects ListHosts, CountHosts, ListHostsInLabel and CountHostsInLabel (which I think is required so that the exact same criteria can be used for those). To keep in mind when load testing performance.

cc @lucasmrod @sharon-fdm (for when this is ready to spec)

rachaelshaw avatar Jan 29 '26 22:01 rachaelshaw

  • [x] UI changes: Figma
    • UI changes are also implemented in this draft PR. If approved/merged, all remaining work is backend.

FYI @rachaelshaw looks like the Figma (and draft PR too?) are missing updating the column name in the Edit columns modal:

Image

noahtalerman avatar Feb 02 '26 17:02 noahtalerman

looks like the Figma (and draft PR too?) are missing updating the column name in the Edit columns modal

It's in the Figma, but I've run into an occasional bug where certain elements visible in the Figma desktop app don't show up in the web view, so might be seeing that again. (PR should have all changes though; the Figma "designs" are just screenshots from the branch I edited.)

rachaelshaw avatar Feb 02 '26 18:02 rachaelshaw

Poker planning

lucasmrod avatar Feb 17 '26 13:02 lucasmrod

Completed test plan on main branch

nulmete avatar Feb 24 '26 15:02 nulmete

Searching hosts, ease blooms, Emails guide through cloud rooms, Queries find, no gloom.

fleet-release avatar Apr 07 '26 20:04 fleet-release