Skip to content

fix: truncate large test result samples to prevent oversized alert payloads (#2044)#2302

Open
zerafachris wants to merge 1 commit into
elementary-data:masterfrom
zerafachris:fix/truncate-large-alert-samples
Open

fix: truncate large test result samples to prevent oversized alert payloads (#2044)#2302
zerafachris wants to merge 1 commit into
elementary-data:masterfrom
zerafachris:fix/truncate-large-alert-samples

Conversation

@zerafachris

@zerafachris zerafachris commented Jul 17, 2026

Copy link
Copy Markdown

Fixes #2044

Test result samples rendered in an alert are converted into a table block with no upper bound on row count. When a failing/warning test has many rows (e.g. 25+ rows across several columns), the resulting alert payload can exceed size limits enforced by downstream integrations such as Microsoft Teams, causing edr monitor to crash before any alert is sent.

This adds a maximum_rows_in_alert_samples config option to MessageBuilderConfig (default 25, mirroring the existing maximum_columns_in_alert_samples knob) and truncates the rendered sample to that limit in _get_result_blocks, appending a note indicating how many rows were omitted.

Added tests/unit/alerts/alert_messages/test_result_blocks_row_truncation.py:

  • A 37-row sample with maximum_rows_in_alert_samples=10 is truncated to 10 rows with a "Showing 10 of 37 rows (27 omitted...)" note. Before this change: assert len(table_block.rows) == 10 fails (assert 37 == 10). After: passes.
  • A 3-row sample under the limit renders unchanged, with no truncation note (regression guard).

Full unit suite (pytest tests/unit): 453 passed. black/isort/flake8/mypy all clean on the touched files and across the package.

Prepared with AI assistance (Claude, agent: claude-sonnet-5), reviewed for correctness before submission.

Summary by CodeRabbit

  • New Features

    • Alert result tables now limit displayed rows to 25 by default.
    • Added configuration to customize the maximum number of rows shown.
    • Truncated tables include a note showing displayed and omitted row counts.
  • Bug Fixes

    • Prevented large alert result samples from displaying unnecessarily many rows.
  • Tests

    • Added coverage for both truncated and fully displayed result samples.

…yloads (elementary-data#2044)

Test result samples rendered as an alert table had no upper bound on
row count. Alerts with many failed/warning rows (e.g. 25+ rows with
several columns) could grow large enough to be rejected by downstream
integrations such as Microsoft Teams, causing edr monitor to crash
before sending any alert.

Cap the rendered sample at MessageBuilderConfig.maximum_rows_in_alert_samples
(default 25, mirroring the existing maximum_columns_in_alert_samples
knob) and append a note indicating how many rows were omitted when
truncation occurs.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

👋 @zerafachris
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in this pull request.

@zerafachris
zerafachris requested a deployment to elementary_test_env July 17, 2026 17:02 — with GitHub Actions Waiting
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2bd02c56-ee31-4765-aaa8-81480836e7a0

📥 Commits

Reviewing files that changed from the base of the PR and between 594b89d and d81b2d6.

📒 Files selected for processing (2)
  • elementary/monitor/alerts/alert_messages/builder.py
  • tests/unit/alerts/alert_messages/test_result_blocks_row_truncation.py

📝 Walkthrough

Walkthrough

Changes

The alert message builder adds a configurable maximum of 25 rendered result-sample rows, truncates larger tables, and reports shown and omitted counts. Unit tests cover both truncated and untruncated samples.

Alert sample truncation

Layer / File(s) Summary
Configure and render row limits
elementary/monitor/alerts/alert_messages/builder.py
MessageBuilderConfig adds maximum_rows_in_alert_samples, and result sample tables apply the limit and append truncation details when rows are omitted.
Validate truncation behavior
tests/unit/alerts/alert_messages/test_result_blocks_row_truncation.py
Tests verify that large samples are limited to the configured row count while smaller samples retain all rows without an omission note.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: truncating large test result samples to avoid oversized alert payloads.
Linked Issues check ✅ Passed The PR reduces oversized alert payloads by truncating test samples, adding an omission note, and keeping small samples unchanged.
Out of Scope Changes check ✅ Passed The changes stay focused on alert sample truncation and matching tests, with no unrelated functionality added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

[bug] prevent too big payload in edr monitor that will be rejected by Teams

1 participant