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

SAP: Introduce external scheduler filter #502

Open
wants to merge 1 commit into
base: stable/xena-m3
Choose a base branch
from

Conversation

auhlig
Copy link
Member

@auhlig auhlig commented Jul 9, 2024

SAP: Introduce an external scheduler filter

This allows us to rely on an external http service to do the filtering,
on a potentially more complex rule-set.
Instead of filtering each host one-by-one, we want to filter them in
a single requests and therefor override the BaseFilter.filter_all

@auhlig auhlig requested a review from fwiesel July 9, 2024 13:45
Copy link

@joker-at-work joker-at-work left a comment

Choose a reason for hiding this comment

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

implement using BaseFilter

I think it should be documented (at least in the commit message), why we do not use the usual approach of BaseHostFilter.

nova/scheduler/filters/external_scheduler_filter.py Outdated Show resolved Hide resolved
nova/scheduler/filters/external_scheduler_filter.py Outdated Show resolved Hide resolved
nova/scheduler/filters/external_scheduler_filter.py Outdated Show resolved Hide resolved
@auhlig auhlig force-pushed the feat/external-scheduler-filter branch from 0ee9d1d to 8fc7c36 Compare July 11, 2024 10:01
Copy link
Member

@fwiesel fwiesel left a comment

Choose a reason for hiding this comment

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

Could you also rewrite the history to a single commit please?

@auhlig auhlig force-pushed the feat/external-scheduler-filter branch from c897817 to bedc095 Compare July 11, 2024 11:23
@fwiesel
Copy link
Member

fwiesel commented Jul 11, 2024

Sorry for the piece-meal: Could you also please prefix the commit title with "SAP: "?

@auhlig auhlig force-pushed the feat/external-scheduler-filter branch from bedc095 to 0ea42f9 Compare July 11, 2024 11:29
@fwiesel
Copy link
Member

fwiesel commented Jul 11, 2024

And maybe a slightly more elaborate commit-message as @joker-at-work already asked for. I'd suggest:

SAP: Introduce an external scheduler filter

This allows us to rely on an external http service to do the filtering,
on a potentially more complex rule-set.
Instead of filtering each host one-by-one, we want to filter them in
a single requests and therefor override the `BaseFilter.filter_all`

@auhlig auhlig force-pushed the feat/external-scheduler-filter branch 3 times, most recently from a94f213 to ec91341 Compare July 11, 2024 13:12
@auhlig auhlig changed the title Introduce external scheduler filter SAP: Introduce external scheduler filter Jul 11, 2024
@auhlig auhlig force-pushed the feat/external-scheduler-filter branch 2 times, most recently from 43eaccc to b52d5c7 Compare July 11, 2024 14:18
})

try:
spec_dict = vars(spec_obj)
Copy link
Member

@fwiesel fwiesel Jul 11, 2024

Choose a reason for hiding this comment

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

Maybe better: spec_obj.obj_to_primitive()

Copy link
Member Author

@auhlig auhlig Jul 11, 2024

Choose a reason for hiding this comment

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

Thanks!
I did it explicitly now for vcpus, memory.
Deriving this from the object results in some bad json which might make it easier here, but harder on the receiver.

Copy link
Member

Choose a reason for hiding this comment

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

The problem is, now you have only a subset of the fields, and no version-negotiation.
You can still pick out just the fields you want on the receiver side on from oslo_versionedobjects json.
I agree, it is harder to do that from there, but I am a big fan of working with the tools/libraries as they are intended.

Copy link
Member

Choose a reason for hiding this comment

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

As to the work on the other side: Since zed, there is a class-method to_json_schema, which will
drop you the schema, which in turn could be used to generate the full object.

Here would be one of such tools: https://github.com/omissis/go-jsonschema

I agree, doing all that is a bit much to start with, but using here spec_obj.obj_to_primitive() opens the path for that, and the usage of other serializers (protobuf?). Parsing "manually" the admittedly ugly json for that is in my mind a small price to pay for that.

Copy link
Member

Choose a reason for hiding this comment

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

Not that I will block this change because of that.

This allows us to rely on an external http service to do the filtering,
on a potentially more complex rule-set.
Instead of filtering each host one-by-one, we want to filter them in
a single requests and therefor override the `BaseFilter.filter_all`
@auhlig auhlig force-pushed the feat/external-scheduler-filter branch from b52d5c7 to 0b35204 Compare July 11, 2024 16:07
Copy link
Member

@fwiesel fwiesel left a comment

Choose a reason for hiding this comment

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

Personally, I still would prefer the oslo_versionedobject serialization, but I am okay with this change.

@auhlig
Copy link
Member Author

auhlig commented Jul 25, 2024

Personally, I still would prefer the oslo_versionedobject serialization, but I am okay with this change.

I tried that. However, the nested python structures aren't serialized correctly. Thus I implemented the current solution.

@@ -947,6 +947,13 @@
Related options:

* ``[DEFAULT] bigvm_mb``
"""),

# External scheduler filter.

Choose a reason for hiding this comment

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

afaics, this comment doesn't contain any content. What's the intent?


import nova.conf
from nova.scheduler import filters
from oslo_log import log as logging

Choose a reason for hiding this comment

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

oslo_log not being part of this project (Nova) should go to another import block (the one where requests is)

except requests.RequestException as e:
# Log an error if the request fails
LOG.error("Failed to query the external API: %s", e)
return filter_obj_list

Choose a reason for hiding this comment

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

I think this does nothing. I tried with this code:

def a():
  try:
      for i in range(7):
        if i == 3:
          raise Exception
        yield i
  except Exception:
    return list(range(7))

breakpoint()
$ python3 /tmp/bla.py 
--Return--
> /tmp/bla.py(10)<module>()->None
-> breakpoint()
(Pdb) p a()
<generator object a at 0x7e701c04d4d0>
(Pdb) p list(a())
[0, 1, 2]

Since a function containing yield, not matter if it's called or not, is a Generator, it doesn't have a proper return-value - afaik.

Any return is broken, also the first one allowing to skip the filter:

def a():
  return ["early"]
  try:
      for i in range(7):
        if i == 3:
          raise Exception
        yield i
  except Exception:
    return list(range(7))

breakpoint()
$ python3 /tmp/bla.py 
--Return--
> /tmp/bla.py(11)<module>()->None
-> breakpoint()
(Pdb) p list(a())
[]
(Pdb) 

Am I holding it wrong? Shouldn't the test for "the filter returns everything if it's disabled" have found this?

Choose a reason for hiding this comment

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

Since you have all the hosts in a list already and are not reading from the request anymore, you might as well return a list instead of yielding, i.e. return [obj for obj in filter_obj_list if obj.host in valid_hosts]

yield obj

except requests.RequestException as e:
# Log an error if the request fails

Choose a reason for hiding this comment

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

I think this comment doesn't add anything helpful as the next line starts with LOG.error and thus easily conveys the same information.

CONF = nova.conf.CONF


class ExternalSchedulerFilterTestCase(test.NoDBTestCase):

Choose a reason for hiding this comment

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

This is missing at least 3 tests:
a) we're disabled
b) we're enabled, but the api is unreachable (mock_post.side_effect = requests.RequestException() or something)
c) we're enabled, the api returns an empty reply
d) we're enabled, the api returns some error code (500? 503?) (is this this same as b? we could make sure we catch a broad-enough exception from requests)

),
)

f = external_scheduler_filter.ExternalSchedulerFilter()

Choose a reason for hiding this comment

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

Other test classes, mainly because they run multiple tests, instantiate their filter in __init__() already.

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