Skip to content

feat: implement host baseline learning (Task 12) - #9

Merged
itenev merged 2 commits into
mainfrom
feat/host-baseline-learning
Jun 7, 2026
Merged

feat: implement host baseline learning (Task 12)#9
itenev merged 2 commits into
mainfrom
feat/host-baseline-learning

Conversation

@itenev

@itenev itenev commented Jun 7, 2026

Copy link
Copy Markdown
Owner
Summary
Implements host baseline learning (Task 12) by computing p50/p95 percentiles from Prometheus historical data and storing them in the SQLite database. This provides Hermes with statistical context for evaluating whether current metric values are anomalous for a specific host.

Type of Change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [x] Documentation update

Pre-Review Findings and Resolutions
<!-- Hermes pre-review checklist. Fill this out before requesting human review. -->
- [x] Linting/formatting (ruff check --fix && ruff format) applied before pre-review.
- [x] Any runbook loading/YAML changes include an end-to-end test loading the physical file. (N/A for this PR)
- [x] Design contracts verified (single-writer boundary maintained via SQLite ON CONFLICT upsert, no new violations introduced).
- Findings flagged by Hermes: 
  - Initial implementation incorrectly used "value" (singular) instead of "values" (plural) when parsing the Prometheus /api/v1/query_range matrix response, which would have silently returned empty lists in production.
- Resolutions applied:
  - Changed key to "values" and added try/except for ValueError/TypeError during float parsing.
  - Added test_query_prometheus_range_parses_matrix_response to catch this specific regression by feeding a realistic Prometheus JSON response structure through the parser.

Testing
- [x] All existing tests pass (pytest -v --cov=agentic_node_ops --cov=webhook_receiver — 136 tests passed, 89% coverage)
- [x] New tests added for new functionality (tests/test_baselines.py includes 7 tests covering percentile math and realistic Prometheus matrix response parsing)
- [x] Manual verification steps (if applicable): N/A (fully covered by unit tests using mocked Prometheus range responses and temporary in-memory SQLite databases)

Checklist
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation (docs/hermes-implementation-plan.md)
- [x] My changes generate no new warnings or errors

loki-hermes-agent[bot] added 2 commits June 7, 2026 23:06
- Add upsert_host_baseline to database.py for atomic insert/update
- Create baselines.py with Prometheus range query poller and percentile math
- Add 6 tests covering percentile calculation and DB integration
- Update hermes-implementation-plan.md to mark Task 12 complete
- Change 'value' to 'values' to correctly parse matrix response data
- Add try/except for ValueError/TypeError when parsing floats
- Add test_query_prometheus_range_parses_matrix_response to catch this regression
- Coverage increased from 88% to 89%
@itenev
itenev merged commit 214a78e into main Jun 7, 2026
2 checks passed
@itenev
itenev deleted the feat/host-baseline-learning branch June 7, 2026 20:18
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.

1 participant