Skip to content

Improve host search by end user email address#40197

Merged
nulmete merged 3 commits intomainfrom
nu/host-search-always-search-email
Feb 24, 2026
Merged

Improve host search by end user email address#40197
nulmete merged 3 commits intomainfrom
nu/host-search-always-search-email

Conversation

@nulmete
Copy link
Copy Markdown
Member

@nulmete nulmete commented Feb 20, 2026

Related issue: Resolves #15744

Checklist for submitter

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

Testing

Manually inserted 10k hosts and random emails associated to them. Response times were always below 200ms locally.
We already have covering indexes so we don't need a migration.

Screen.Recording.2026-02-23.at.1.41.02.PM.mov

SQL used:

-- Seed 10k hosts for performance testing email search.
-- Requires: SET cte_max_recursion_depth = 10000;
--
-- 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-%';

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.37%. Comparing base (b0cc888) to head (04a9774).
⚠️ Report is 61 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #40197      +/-   ##
==========================================
+ Coverage   66.28%   66.37%   +0.08%     
==========================================
  Files        2459     2456       -3     
  Lines      196811   196765      -46     
  Branches     8714     8681      -33     
==========================================
+ Hits       130451   130596     +145     
+ Misses      54542    54345     -197     
- Partials    11818    11824       +6     
Flag Coverage Δ
backend 68.14% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nulmete nulmete marked this pull request as ready for review February 23, 2026 16:49
@nulmete nulmete requested a review from a team as a code owner February 23, 2026 16:49
Copy link
Copy Markdown
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Make sure to document that this needs to be load tested by QA.

@nulmete nulmete merged commit 1547357 into main Feb 24, 2026
45 checks passed
@nulmete nulmete deleted the nu/host-search-always-search-email branch February 24, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve host search by end user email address

2 participants