Skip to content

feat(core): optimize alert retrieval and add alert-based filtering#12

Merged
rnovatorov merged 3 commits into
mainfrom
rnovatorov/alerts-counters
Apr 15, 2026
Merged

feat(core): optimize alert retrieval and add alert-based filtering#12
rnovatorov merged 3 commits into
mainfrom
rnovatorov/alerts-counters

Conversation

@rnovatorov
Copy link
Copy Markdown
Member

This PR optimizes how active alerts are retrieved from the Enapter API and introduces a new filtering capability to the search_devices tool. We transitioned from manual, telemetry-based alert fetching to using SDK-level expansion, significantly reducing API latency and complexity.

This version introduces the 'expand_raised_alert_names' parameter in device
list and get calls, enabling efficient retrieval of active alerts without
separate telemetry queries.
Transition from manual telemetry-based alert fetching to SDK-level
expansion to reduce API calls and improve performance. This change
ensures 'active_alerts' is always a list in the FULL view for better
consumer predictability, and introduces 'active_alerts_total' to allow
monitoring alert status in BASIC views.
Allow filtering devices by the presence or absence of active alerts.
This provides a more efficient way to identify devices requiring
attention or to monitor healthy devices.
@rnovatorov
Copy link
Copy Markdown
Member Author

@copilot, can you review the changes?

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

@copilot, can you review the changes?

Reviewed the three commits. The changes look correct overall. A few observations:

enapter_data_mapper.pyraised_alert_names is always mapped to a list[str] (never None), so DeviceDTO.active_alerts is effectively always non-None after mapping. The | None type on the field now only serves as documentation of "not expanded yet". The defensive assert device_dto.active_alerts is not None guards in _search_devices_basic / _search_devices_full are therefore always satisfied, which is harmless but worth knowing.

device_search_query.py — the assert device_dto.active_alerts is not None before filtering is consistent with how the rest of application_server.py uses asserts. No concerns here.

Test cleanup — the two MockEnapterAPI(…, telemetry={…}) calls in the test_search_sites_* tests (lines ~155 and ~234) still carry alert-shaped telemetry dicts that are never consumed; those were pre-existing and unrelated to this PR.

Performanceexpand_active_alerts=True is now unconditionally requested in both basic and full views, which is correct since active_alerts_total is now a required field in the response. CI is green.

Nothing blocking. The approach is clean and correct.

@rnovatorov rnovatorov merged commit ed4d617 into main Apr 15, 2026
4 checks passed
@rnovatorov rnovatorov deleted the rnovatorov/alerts-counters branch April 15, 2026 16:14
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.

2 participants