Repository navigation
Cap opengrep jobs and fit --max-memory to the pod limit - #50
Merged
Merged
Conversation
Tool pods have no CPU limit, so the job count fell back to the node's core count. Cap that fallback at 4, the pod's CPU request. Derive --max-memory from the container memory limit (70%, at most 5000 MiB).
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 9 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
lolgab
marked this pull request as ready for review
December 3, 2026 09:41
There was a problem hiding this comment.
Pull Request Overview
✅ No blocking issues noticed
No blocking findings were identified.
Codacy also found:
- Complexity increased in
internal/tool/jobs.goandinternal/tool/jobs_test.godue to cgroup parsing and memory fallback branches.
Test suggestions
- Verify explicit OPENGREP_JOBS overrides automatic job selection.
- Verify CPU quota parsing and fallback to a bounded CPU count when no quota exists.
- Verify memory is capped at 5000 MiB for large limits and calculated as 70% for smaller limits.
- Verify unlimited, malformed, or unavailable memory limits use the default.
- Verify command parameters contain the dynamically computed --max-memory and -j values.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify command parameters contain the dynamically computed --max-memory and -j values.
TIP Add review instructions in .codacy/instructions/review.md, or an AGENTS.md, so the reviewer knows your conventions.
TIP How was this review? Give us feedback
lolgab
enabled auto-merge (squash)
December 3, 2026 09:53
DMarinhoCodacy
approved these changes
Dec 3, 2026
This was referenced Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Opengrep pods have no CPU limit (codacy-tools #1262), so
cgroup cpu.maxreadsmaxand the job count falls back toruntime.NumCPU(): every core of the node. Opengrep v2.1.0 runs its jobs as OCaml 5 domains in one process, so memory grows with the job count: each domain has its own 32 MiB minor heap, outside the--max-memoryheap cap, and more files are in memory at once. On a large node that pushes the pod towards its 7Gi limit, where the kernel kills the whole pod and the batch fails, instead of Opengrep failing one file.OPENGREP_JOBS, then the cgroup CPU quota, as before. The last fallback is now the CPU count capped at 4, the pod's CPU request inOpengrep.scala. Opengrep's own default caps at 16, but the wrapper always passes-j, so there was no cap at all.--max-memory: 70% of the container memory limit (memory.max), at most 5000 MiB. At today's 7Gi limit the value stays 5000. If the limit is lowered (e.g. when right-sizing the 2Gi request / 7Gi limit), Opengrep still fails a single file instead of the pod being killed.Not done on purpose: reading the CPU request from
cpu.weight. runc changed its shares-to-weight conversion, so the value can't be trusted across nodes.plugins_test)ToolOutOfMemorycount and per-pod memory peak/p95 vs before