Skip to content

Redis host cache optimizations - #46458

Merged
getvictor merged 4 commits into
mainfrom
46338-host-cache
Jun 1, 2026
Merged

Redis host cache optimizations#46458
getvictor merged 4 commits into
mainfrom
46338-host-cache

Conversation

@getvictor

@getvictor getvictor commented May 29, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #46338

Changes load tested (osquery load test).
image
image

Checklist for submitter

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

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • Performance Improvements

    • Extended host cache retention period from 60 seconds to 180 seconds to improve overall cache efficiency and hit rates.
    • Optimized host cache invalidation strategy to eliminate unnecessary reverse-index lookups, significantly reducing database reader load and Redis CPU consumption.
  • Tests

    • Added test coverage for host update cache invalidation edge cases to ensure proper behavior.

Review Change Stack

@codecov

codecov Bot commented May 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 66.81%. Comparing base (4b04063) to head (387f9ed).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
server/datastore/mysqlredis/host_cache_writes.go 94.73% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #46458      +/-   ##
==========================================
- Coverage   66.82%   66.81%   -0.02%     
==========================================
  Files        2808     2799       -9     
  Lines      223582   223554      -28     
  Branches    11347    11332      -15     
==========================================
- Hits       149413   149358      -55     
- Misses      60615    60643      +28     
+ Partials    13554    13553       -1     
Flag Coverage Δ
backend 68.55% <95.00%> (+<0.01%) ⬆️

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.

@getvictor getvictor changed the title 46338 host cache Redis host cache optimizations May 29, 2026
@getvictor
getvictor marked this pull request as ready for review May 29, 2026 18:42
@getvictor
getvictor requested a review from a team as a code owner May 29, 2026 18:42
Copilot AI review requested due to automatic review settings May 29, 2026 18:42

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@getvictor

Copy link
Copy Markdown
Member Author

@lucasmrod Additional Redis host cache improvements for review, after recent 4.86 loadtest.

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c9343400-e193-4707-966e-f9917b0f55c7

📥 Commits

Reviewing files that changed from the base of the PR and between 4504b11 and 0c70855.

📒 Files selected for processing (5)
  • changes/46338-host-cache-ttl-and-invalidation
  • server/config/config.go
  • server/datastore/mysqlredis/host_cache.go
  • server/datastore/mysqlredis/host_cache_writes.go
  • server/datastore/mysqlredis/host_cache_writes_test.go

Walkthrough

This PR increases the default Redis host-cache TTL from 60 seconds to 180 seconds, reducing cache repopulation overhead. It also optimizes the UpdateHost invalidation path to delete host-cache entries using direct key construction instead of reverse-index lookups, eliminating redundant GETs to the database. The changes include configuration updates, documentation adjustments, and test coverage for edge cases where either NodeKey or OrbitNodeKey may be absent.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Redis host cache optimizations' accurately describes the main changes: increasing the Redis host cache TTL and optimizing the invalidation logic to reduce database and Redis CPU load.
Description check ✅ Passed The PR description adequately provides the related issue (#46338), load test evidence with screenshots, and confirms completion of key checklist items including test additions and manual QA.
Linked Issues check ✅ Passed The PR implements both proposed fixes from issue #46338: raising default FLEET_REDIS_HOST_CACHE_TTL from 60s to 180s [server/config/config.go] and optimizing invalidation logic to skip reverse-index GETs [server/datastore/mysqlredis/host_cache_writes.go], with supporting test coverage added.
Out of Scope Changes check ✅ Passed All changes directly support the objectives in issue #46338: TTL increase in config, comment updates in host_cache.go reflecting the new values, invalidation logic optimization in host_cache_writes.go, and corresponding test coverage in host_cache_writes_test.go.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 46338-host-cache

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces database reader load and Redis CPU usage for the Redis-backed host-by-node_key/orbit_node_key cache by extending the default TTL window and cutting Redis commands on common invalidation paths.

Changes:

  • Increased the default redis.host_cache_ttl from 60s to 180s (with existing jitter) to reduce cache repopulation frequency.
  • Optimized the UpdateHost/SerialUpdateHost invalidation path to delete known cache keys directly instead of doing reverse-index GETs.
  • Added/expanded automated tests covering the updated invalidation behavior.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/datastore/mysqlredis/host_cache.go Updates TTL/jitter documentation to reflect the new 180s default and expected hit rate.
server/datastore/mysqlredis/host_cache_writes.go Implements direct-key invalidation for host updates to reduce Redis command count.
server/datastore/mysqlredis/host_cache_writes_test.go Adds tests for update-path invalidation variants (osquery-only, sparse host fallback).
server/config/config.go Changes the default config value for redis.host_cache_ttl to 180s.
changes/46338-host-cache-ttl-and-invalidation Release note describing the TTL increase and invalidation optimization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/datastore/mysqlredis/host_cache_writes.go
@getvictor
getvictor merged commit 8a28b83 into main Jun 1, 2026
31 checks passed
@getvictor
getvictor deleted the 46338-host-cache branch June 1, 2026 13:12
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.

Further reduce LoadHostByNodeKey reader load and lower host-cache Redis CPU

3 participants