Skip to content

Quality sweep (SQL queries) - #417

Merged
TheWitness merged 9 commits into
developfrom
quality_sweep_rebased
Oct 16, 2026
Merged

TheWitness merged 9 commits into
developfrom
quality_sweep_rebased

Conversation

@bmfmancini

Copy link
Copy Markdown
Member

This pull request introduces several important enhancements and optimizations to syslog archival, alert processing, and schema management. The main focus is on adding and utilizing a message_digest column (MD5 hash of the message) in archival tables, improving alert rule evaluation for better performance, and supporting schema migrations and compatibility.

Digest column integration and schema migration:

  • All archival and removal operations now write the MD5 digest of the message into a new message_digest column in syslog and syslog_removed tables, ensuring consistent grouping and lookup capabilities. [1] [2] [3] [4] [5] [6]
  • Added syslog_message_digest_ready and syslog_backfill_message_digest helper functions to check for digest column readiness and backfill missing digests in existing rows in batches, supporting zero-downtime schema upgrades.

Alert rule evaluation performance improvements:

  • Alert processing now compiles all rule conditions and evaluates them together in a single scan, greatly reducing the number of table scans required and improving scalability with large rule sets. [1] [2]
  • For threshold-based alerts, consolidated counts are reused to avoid redundant scans, and zero-match cases short-circuit the fetch entirely. [1] [2]

SQL and maintenance logic improvements:

  • Device rule SQL generation now explicitly qualifies staging columns to prevent accidental scope capture and ensure correct filtering during maintenance and mute operations.

Alert rule SQL generation flexibility:

  • syslog_get_alert_sql now supports a condition_only mode, returning only the WHERE clause and parameters for efficient bulk evaluation of multiple rules. [1] [2]

These changes collectively improve syslog archival reliability, alert rule performance, and schema upgrade safety.

- syslog_process_alerts(): compile all rules to condition-only SQL and
  evaluate every rule's count in one consolidated SUM(CASE) scan of
  syslog_incoming (one scan per cycle regardless of rule count); rules
  below threshold or with zero counts skip their record fetches
- syslog_device_rule_sql(): qualify the correlated host column so the
  mute filter was not a tautology (dr.host = dr.host silently matched
  every staged record and suppressed all alerts)
- Add message_digest char(32) to syslog/syslog_removed (fresh installs
  via CREATE, existing via syslog_ensure_message_digest_columns()), backfill
  bounded per poller run via syslog_backfill_message_digest(); archive,
  move, and replication paths write MD5(message) at ingest
- Viewer: grouped queries and nav counts key on the digest with an
  IF(digest = '', MD5(message), digest) exactness fallback, degrading
  to the old message GROUP BY when the column does not exist yet
- Bounded per-render host-name fetch (host_id IN instead of full table)
- tests: MessageDigestGroupingTest source-shape coverage
Copilot AI balanced review requested due to automatic review settings October 16, 2026 15:33

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bmfmancini bmfmancini changed the title Quality sweep rebased Quality sweep (SQL queries) Oct 16, 2026
bmfmancini and others added 6 commits October 16, 2026 11:42
syslog_ensure_table_structures() now calls syslog_ensure_message_digest_
columns(), which lives in the part of includes/schema.php the test
deliberately does not eval, so the harness needs a stub like the other
ensure_* helpers it already keeps out of scope.
CI enforces 100% patch coverage on changed lines.  Commit 5c65781 added
several paths that had no unit tests:

* syslog_backfill_message_digest(): cover the empty-table, missing-column,
  completed-cursor, empty-digest and chunked-walk branches
* syslog_get_alert_sql(..., condition_only=true): cover every switch arm
  and the invalid-JSON filter path
* syslog_process_alerts() Phase 1: cover the consolidation pass and its
  guard for an unsupported rule type
* syslog_replication_accept_central(): cover the message_digest spliced
  parameters when the central schema already has the column
* syslog_message_digest_ready(): cover the cached false path

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* syslog_process_alerts() Phase 2:
  add AlertPhase2BranchesTest driving the level-0 method-1 threshold
  branch (5128/5129), the host-level branch (5156/5160) and the method-0
  zero-count fast path (5170/5171) end-to-end against stub fixtures
* syslog_backfill_message_digest()/syslog_message_digest_ready():
  split the positive and negative cache paths into separate Pest files
  (AlertPhase2Branches uses the same fixture layout as ThresholdEpisode)
  so the static-cache re-read at 5946 is measurable in isolation

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…lTest

CI runs every Pest test in one process, so the static cache inside
syslog_message_digest_ready() is populated by whichever file runs first
in alphabetical order. MessageDigestReadyTest already covers the false
branch in isolation, so removing the truthy assertion here avoids order
flakiness without losing coverage.
@TheWitness
TheWitness merged commit 9d7f26b into develop Oct 16, 2026
6 checks passed
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.

3 participants