Implements extra ETS cache for DevAddr range lookups#326
Merged
Conversation
performance issues when the devaddr_ranges ETS table grows large.
Changes:
- Added cache ETS table (hpr_devaddr_cache_ets) storing {DevAddr, {RouteIDs, Timestamp}}
- Modified lookup/1 to check cache before expensive ETS select operations
- Implemented TTL-based expiration (default 12 hours, configurable via devaddr_cache_ttl_ms)
- Added cache invalidation on route updates (insert, delete, replace operations)
- Added Prometheus metrics: devaddr_cache_hit_counter and devaddr_cache_miss_counter
- Added CLI commands: "hpr config cache clear" and "hpr config cache stats"
- Added comprehensive unit tests (8 tests covering cache behavior)
48437ac to
0e05928
Compare
Adds three new CLI commands to manage all routes for a given OUI: - config oui activate <oui> - Activate all routes for an OUI - config oui deactivate <oui> - Deactivate all routes for an OUI - config oui refresh <oui> - Refresh all routes for an OUI from API Also refactors activate/deactivate logic into a common set_routes_active/2 helper function used by both route-level and OUI-level commands, reducing code duplication and ensuring consistent behavior. The refresh command fetches all routes from the Config Service API using get_api_routes_for_oui/1 to ensure completeness, then spawns a background process to refresh each route with detailed logging.
Extended the `set_routes_active` helper function to automatically manage route data during activation and deactivation: When deactivating routes: - Remove all Session Key Filters (SKFs) for the route - Remove all DevAddr ranges for the route - Remove all EUI pairs for the route - Keep the route record itself for potential reactivation When activating routes: - Automatically refresh the route to fetch SKFs, DevAddr ranges, and EUI pairs from the IoT Config Service This ensures routes are in a clean, consistent state when toggled and eliminates orphaned data that could cause routing issues. Changes: - Update `set_routes_active/2` to call delete/refresh functions based on activation state - Export test functions from hpr_cli_config for CT suite testing - Add 4 new CT tests verifying single route and OUI-level activation/deactivation - Fix race condition in hpr_packet_router_service eunit test (add timer:sleep before meck assertion) - Add hpr_metrics mocking to test setup functions to prevent undefined function errors - Add .coverdata to gitignore
michaeldjeffrey
approved these changes
Mar 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements a fast in-memory cache for DevAddr range lookups to address performance issues when the devaddr_ranges ETS table grows large.
Changes: