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

policy: refactor options to allow custom #1268

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wihobbs
Copy link
Member

@wihobbs wihobbs commented Aug 13, 2024

Problem: the current fluxion policy matching factory doesn't allow for customizable policies.

Add a custom option and refactor existing policies to behave similarly. Add unit testing for the string parsing convenience functions.

Outstanding to-do:

  • add an option in the scheduler config to actually pass a custom string in, and probably some validation too

@wihobbs
Copy link
Member Author

wihobbs commented Aug 13, 2024

And I know the testing and the code should be in separate commits... sigh (will fix)

@wihobbs wihobbs force-pushed the new-policy-refactor branch from f7f1df3 to cd87d59 Compare August 13, 2024 01:09
Copy link
Member

@cmoussa1 cmoussa1 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 opening this @wihobbs! I have just some preliminary questions/comments on a first pass. Apologies in advance that I'm not very familiar with the sched code at all so I could definitely be misunderstanding how this works. :-)

resource/policies/dfu_match_policy_factory.cpp Outdated Show resolved Hide resolved
resource_type_t node_rt ("node");
std::shared_ptr<dfu_match_cb_t> create_match_cb (const std::string &policy_requested)
{
std::string policy = policies.find (policy_requested)->second;
Copy link
Member

Choose a reason for hiding this comment

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

Should this .find () call have any sort of error checking after the lookup of policy_requested? Maybe this is always guaranteed to find something successfully. If not, maybe you can check the contents of policy before moving on.

if (policy == "")
    // return an error?
    // set matcher to something default?
    // sorry that idk what the right behavior should be here

Copy link
Member Author

Choose a reason for hiding this comment

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

Mmm good catch. It should call known_match_policy first to see if the policy exists.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, actually, known_match_policy is called when the config is validated in resource/modules/resource_match_opts.cpp so it's already been validated before it gets here.

This will need additional work to support custom.

Copy link
Member

Choose a reason for hiding this comment

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

In that case, a comment making note that it is already validated by the time it gets to that lookup might be helpful here!


if (option_exists ("stop_on_k_matches", policy)) {
ptr->set_stop_on_k_matches (parse_int_match_options ("stop_on_k_matches", policy));
}
Copy link
Member

Choose a reason for hiding this comment

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

Does this if-else branch need an else statement? Excuse my ignorance on this - I'm not sure if the addition of custom policies allows for something other than low or high

Copy link
Member Author

Choose a reason for hiding this comment

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

AFAIK low and high are the only options, unless locality or variation are chosen.

@wihobbs wihobbs force-pushed the new-policy-refactor branch 2 times, most recently from 5f03ae3 to ba80f7b Compare August 13, 2024 16:31
Copy link
Member

@jameshcorbett jameshcorbett left a comment

Choose a reason for hiding this comment

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

Just did a quick look-through, it looks reasonable to me. I think the commits could be broken up better though (as you noted already)

bool known_match_policy (const std::string &policy);

const std::map<std::string, std::string> policies =
Copy link
Member

Choose a reason for hiding this comment

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

I'll do a deeper look over this, but first thing this should be split. Put the declaration here with extern and the definition in the cpp file so this variable doesn't end up getting defined in all includers.

Copy link
Member

Choose a reason for hiding this comment

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

To be fair, that's what the old code did, but it shouldn't 😬

@garlick
Copy link
Member

garlick commented Aug 20, 2024

PR title seems truncated?

@wihobbs
Copy link
Member Author

wihobbs commented Aug 20, 2024

Well, custom is a new type of policy that this PR is enabling. Or will enable eventually. Maybe "resource: refactor policy options to allow a user-defined policy" is more descriptive?

Note that this is still WIP and needs some config work and testing for the custom options. Happy to incorporate any feedback on the initial draft (and thanks to those who have already reviewed!), but it's going to stay in draft state until the code can:

  • accept a custom string with policy options
  • reject certain strings that are requesting invalid custom options, such as set_stop_on_k_matches=-100 and such
  • test some custom options and make sure they behave as expected
  • break out the commit history in a better way

@wihobbs
Copy link
Member Author

wihobbs commented Sep 5, 2024

Per discussion with Tom:

  • To handle custom policies, "don't validate, parse" -- parse the input on a delimiter first and then verify that each key is valid, give an error message if it isn't, possibly demote this to a warning based on a config option
  • Fluxion should issue a fatal warning if a policy named is not valid -- don't fall back on first (might already be done?)
  • set_stop_on_k_matches probably only takes a value of 1, however, we should test this
  • we should also think about having "node_centric" have a score factor of 10000, maybe we don't want to allow users to configure this, but maybe that number doesn't cover all our bases

@wihobbs wihobbs force-pushed the new-policy-refactor branch from ba80f7b to 2d176c4 Compare November 15, 2024 17:25
@wihobbs wihobbs force-pushed the new-policy-refactor branch 2 times, most recently from 9304412 to 147eebf Compare December 23, 2024 17:48
Problem: the current fluxion policy matching factory
doesn't allow for customizable policies.

Add a custom option and refactor existing policies to
behave similarly. Add unit testing for the string parsing
convenience functions.
Problem: the expansion of fluxion's dfu_match_policy_factory to
include custom policies opens the door for more creative policy
options, but doesn't test them.

Add a shell test, starting from a previous test of node-exclusivity
but substituting the short policy keys (i.e. "hinodex") for longer,
"custom" policy strings.
@wihobbs wihobbs force-pushed the new-policy-refactor branch from 147eebf to 3484d1c Compare December 23, 2024 18:07
Copy link

codecov bot commented Dec 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.1%. Comparing base (3fb0b4e) to head (3484d1c).

Additional details and impacted files
@@            Coverage Diff            @@
##           master   #1268      +/-   ##
=========================================
- Coverage    75.2%   62.1%   -13.2%     
=========================================
  Files         111      51      -60     
  Lines       15986    6191    -9795     
=========================================
- Hits        12029    3845    -8184     
+ Misses       3957    2346    -1611     

see 84 files with indirect coverage changes

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.

5 participants