Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jobspec: enforce restrictions on resource range keys #1341

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sam-maloney
Copy link

Problem: restrictions on resource range keys described in flux-framework/rfc#444 are not currently checked/enforced

This PR implements checks in libjobspec to ensure the correct combinations of keys are present and the values are self-consistent.

The initial impetus for this was a range using the exponentiation operator but having a min value of 1 would get stuck in an infinite loop, so I've added a check for that in matcher.cpp which short-circuits similarly to when an exponent or multiplier of 1 is specified. However, with the new checks in jobspec.cpp, hopefully this situation should now never be reached in the first place, and rather fail with a useful error message.

I've separated the checks for consistent values from the checks on the presence of all or none of the max/operator/operand keys into separate commits, in case you'd rather keep the behaviour of using default values.

Problem: in a resource range, if min is 1 when the operator is '^' then
the code gets stuck in an infinite loop

Add a check if exponent base is 1, and return current value if so (same
behaviour as if exponent or multiplication operand is 1)
Problem: certain nonsensical combinations of range keys are currently
not checked for when initializing ranges

Add checks ensuring that specified min/max/operator/operand
combinations are self-consistent
@trws trws self-requested a review February 19, 2025 22:40
Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 59.37500% with 13 lines in your changes missing coverage. Please review.

Project coverage is 75.7%. Comparing base (da6156a) to head (3a46225).

Files with missing lines Patch % Lines
resource/libjobspec/jobspec.cpp 56.6% 13 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##           master   #1341   +/-   ##
======================================
  Coverage    75.7%   75.7%           
======================================
  Files         112     112           
  Lines       16410   16417    +7     
======================================
+ Hits        12426   12436   +10     
+ Misses       3984    3981    -3     
Files with missing lines Coverage Δ
resource/policies/base/matcher.cpp 70.4% <100.0%> (ø)
...rce/policies/base/test/matcher_util_api_test01.cpp 79.0% <100.0%> (+7.9%) ⬆️
resource/libjobspec/jobspec.cpp 85.2% <56.6%> (-1.7%) ⬇️

@sam-maloney
Copy link
Author

force-pushed changes from clang-format; sorry I forgot to run that before the first round!

Problem: recent change to RFC 14 explicitly makes max/operator/operand
co-dependent; i.e., if one is given then all three must be, but this is
not currently checked or enforced

Add checks ensuring that if one of max/operator/operand is specified
then all are, and adjusts the testsuite to match
Problem: newly enforced constraints are not checked by the testsuite

Add new invalid jobspecs to the testsuite to hit the new checks
Problem: because min/max in resource counts are read in as unsinged,
negative values in the jobspec may still pass validation

Change the value checks for min/max to use the input values cast to
signed types to ensure negative inputs are caught
@sam-maloney
Copy link
Author

Pushed some new tests for the new constraint checks to address the Codecov report (and simplified the checks slightly). Also noticed that negative values (particularly for max) could pass validation because of integer overflow after being read into the unsigned variables, so I tweaked the checks on min/max values to hopefully catch that as well.

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.

1 participant