Skip to content

Feature/ciac 15710/decrease rasterize memory usage#43729

Draft
MosheEichler wants to merge 4 commits intomasterfrom
Feature/CIAC-15710/Decrease-Rasterize-Memory-Usage
Draft

Feature/ciac 15710/decrease rasterize memory usage#43729
MosheEichler wants to merge 4 commits intomasterfrom
Feature/CIAC-15710/Decrease-Rasterize-Memory-Usage

Conversation

@MosheEichler
Copy link
Copy Markdown
Contributor

Status

  • In Progress
  • Ready
  • In Hold - (Reason for hold)

Related Issues

https://jira-dc.paloaltonetworks.com/browse/CIAC-15710

Description

Added memory-aware execution to Rasterize CIAC-15710. Chrome concurrency is automatically scaled down based on available container memory.
A runtime watchdog captures a partial screenshot and exits gracefully if memory drops below a configurable threshold, preventing OOM crashes on heavy websites.

Must have

  • Tests
  • Documentation

@MosheEichler MosheEichler requested a review from DeanArbel March 29, 2026 14:51
@MosheEichler MosheEichler self-assigned this Mar 29, 2026
@MosheEichler MosheEichler added the ready-for-ai-review The PR is ready for reviewing the PR with the AI Reviewer. label Mar 29, 2026
@content-bot
Copy link
Copy Markdown
Contributor

🤖 AI-Powered Code Review Available

You can leverage AI-powered code review to assist with this PR!

Available Commands:

  • @marketplace-ai-reviewer start review - Initiate a full AI code review
  • @marketplace-ai-reviewer re-review - Incremental review for new commits

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 29, 2026

@content-bot
Copy link
Copy Markdown
Contributor

⚠️ The PR is missing the ready-for-pipeline-running label. Please add the label when the PR is ready in order to proceed.

@marketplace-ai-reviewer marketplace-ai-reviewer removed the ready-for-ai-review The PR is ready for reviewing the PR with the AI Reviewer. label Mar 29, 2026
@marketplace-ai-reviewer
Copy link
Copy Markdown
Contributor

🤖 Analysis started. Please wait for results...

@content-bot
Copy link
Copy Markdown
Contributor

Validate summary
The following errors were thrown as a part of this pr: .
If the AG100 validation in the pre-commit GitHub Action fails, the pull request cannot be force-merged.

Verdict: PR can be force merged from validate perspective? ✅

@marketplace-ai-reviewer
Copy link
Copy Markdown
Contributor

🤖 AI Review Disclaimer

This review was generated by an AI-powered tool and may contain inaccuracies. Please be advised, and we extend our sincere apologies for any inconvenience this may cause.

Copy link
Copy Markdown
Contributor

@marketplace-ai-reviewer marketplace-ai-reviewer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this rasterize update! I've reviewed the code and have a few suggestions to refine the memory handling and align with our best practices.

Mainly, please update the cgroup memory calculation to return -1 instead of 0 when files are missing (updating the related tests and docstrings to match), and use max_chromes for the ratio calculation to prevent exceeding defaults. Also, make sure to swap demisto.results() for return_results() and clear the memory log lines after flushing to prevent duplicate logs.

Let me know if you have any questions!

@DeanArbel please review and approve the results generated by the AI Reviewer by responding 👍 on this comment.

data=content.encode("utf-8"),
file_type=entryTypes["entryInfoFile"],
)
demisto.results(result)
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.

Please use return_results() instead of demisto.results().


except (FileNotFoundError, ValueError, PermissionError) as e:
_mem_log("DEBUG", f"get_container_available_memory_bytes: Could not read cgroup v2 memory.max: {e}")
return 0
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.

get_container_available_memory_bytes should return -1 instead of 0 when cgroup v2 files are not found.

max_chromes = min(safe_count, default_chromes)
max_tabs = min(safe_count, default_tabs)
# Scale rasterizations proportionally: keep the same ratio as the original defaults.
ratio = safe_count / max(default_chromes, 1)
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.

The ratio calculation should use max_chromes instead of safe_count to prevent exceeding configured defaults.

Only called when there is at least one log line to write.
"""
with _memory_log_lock:
lines = list(_memory_log_lines)
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.

Consider clearing _memory_log_lines after copying it to prevent duplicate logs if _flush_memory_log is ever called multiple times.

from rasterize import get_container_available_memory_bytes

mocker.patch("builtins.open", side_effect=FileNotFoundError("no cgroup"))
result = get_container_available_memory_bytes()
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.

Update this test to expect -1 instead of 0.


def test_zero_available_bytes_returns_minimum(self):
"""
Given: 0 bytes available (cgroup files unreadable)
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.

Update the docstring to reflect that 0 bytes available means the container is at its memory limit, not that the files are unreadable.

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