feat(bug-finding): warn users if resource config conflicts with machi…#159
feat(bug-finding): warn users if resource config conflicts with machi…#159
Conversation
azchin
left a comment
There was a problem hiding this comment.
Thanks for the PR and sorry for the late response! I have a few requests detailed below. We also use a few linters and formatters in our CI workflow, so I recommend running them manually before pushing.
oss_crs/src/utils.py
Outdated
| except(OSError): | ||
| pass | ||
|
|
||
| memeinfo = Path("/proc/meminfo") |
There was a problem hiding this comment.
meminfo typo (caught by ruff)
oss_crs/src/crs_compose.py
Outdated
| machine_cpu_count = os.cpu_count() | ||
| machine_memory = get_host_memory() | ||
|
|
||
| if machine_cpu_count is None or machine_memory == 0: |
There was a problem hiding this comment.
(C1) Let's get machine_memory to return None on failure
oss_crs/src/utils.py
Outdated
| except subprocess.CalledProcessError as e: | ||
| raise RuntimeError(f"Error removing {path} with Docker: {e}") | ||
|
|
||
| def get_host_memory() -> int: |
There was a problem hiding this comment.
Return val as int | None, see (C1)
oss_crs/src/utils.py
Outdated
| for line in meminfo.read_text().splitlines(): | ||
| if line.startswith("MemTotal:"): | ||
| return int(line.split()[1])*1024 | ||
| return 0 |
oss_crs/src/crs_compose.py
Outdated
| except ValueError as e: | ||
| log_warning(f"Failed to parse memory for {name}: {e}") | ||
|
|
||
| cpu_check = max_cpus_required <= machine_cpu_count |
There was a problem hiding this comment.
I think this is an off-by-one, since os.cpu_count() returns number of CPUs but cpuset is indexed by zero, so we'd get range of 0-3 on 4-core machine. max([0, 1, 2, 3]) == 3 < 4
max_cpus_required < machine_cpu_count would be the correct check. But please check/test for this edge case dynamically.
There was a problem hiding this comment.
You're absolutely right ^^'... I will also add dynamic testing.
…ne resources Signed-off-by: tkqdldk <samia.20.bouchaal@gmail.com>
c274218 to
867fac0
Compare
… memory output Signed-off-by: tkqdldk <samia.20.bouchaal@gmail.com>
Signed-off-by: tkqdldk <samia.20.bouchaal@gmail.com>
867fac0 to
c55125d
Compare
|
Hm I'm not seeing the error messages implemented in your PR in my output. The build does indeed abort, but that's because of Docker's error handling and happens after I can take a deeper look at what we're missing after the weekend, if needed. |
Hi, sorry for the late response, so the validation only runs before run currently, as I understood that would be the only need. I'll extend the check to build-target so the warning shows here too. |
Closes #49
Description
Adds resources check and a warning when the compose file resource configurations (max CPU and total memory) exceed machine resources. The check runs in "Validate Configuration for Running" phase, before Docker attempts to start containers.
The function emits a warning but does not stop the execution.
Changes
get_host_total_memory()inutils.py_validate_machine_resources()incrs_compose.py__validate_before_runValidation
All existing tests pass.
P.S. : Can't assign a reviewer directly, cc @azchin for review