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

mgr: python interface rework + enable modules to run in standby mode #16651

Merged
merged 32 commits into from Nov 1, 2017

Conversation

jcsp
Copy link
Contributor

@jcsp jcsp commented Jul 28, 2017

  • Update documentation + release notes for "mgr services" command.
  • Add mechanism for python modules to serve in standby mode

@jcsp jcsp added the mgr label Jul 28, 2017
@jcsp jcsp force-pushed the wip-mgr-module-interface branch 2 times, most recently from 5644228 to 927920b Compare October 4, 2017 13:52
@jcsp jcsp changed the title [DNM] mgr module interface improvements mgr: python interface rework + enable modules to run in standby mode Oct 4, 2017
@ceph ceph deleted a comment from amitkumar50 Oct 4, 2017
@ceph ceph deleted a comment from amitkumar50 Oct 4, 2017
@wido
Copy link
Member

wido commented Oct 5, 2017

Do we already want to include the "can_run()" method here? Like we discussed on the Ceph day. Meaning that we check if a module is able to run before we attempt it.

@jcsp
Copy link
Contributor Author

jcsp commented Oct 5, 2017

@wido definitely want it, but this PR is already huge so let's do it separately afterwards

@ceph-jenkins
Copy link
Collaborator

OK - docs built

@wido
Copy link
Member

wido commented Oct 9, 2017

@jcsp: Understood! Was scanning through the code and didn't see it. Just wanted to double-check I didn't miss anything.

@tchaikov tchaikov self-requested a review October 9, 2017 08:16
@jcsp jcsp force-pushed the wip-mgr-module-interface branch 5 times, most recently from 6e5dd29 to 86f0766 Compare October 20, 2017 12:08
@ceph-jenkins
Copy link
Collaborator

make check succeeded

@ceph ceph deleted a comment from amitkumar50 Oct 26, 2017


typedef struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, no need to typedef a struct in C++.

// Load python code
for (const auto& module_name : mgr_map.modules) {
dout(1) << "Loading python module '" << module_name << "'" << dendl;
auto mod = std::unique_ptr<PyModule>(new PyModule(module_name));
Copy link
Contributor

Choose a reason for hiding this comment

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

could use make_unique()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -184,6 +184,14 @@ def notify(self, notify_type, notify_val):
self.log_buffer.appendleft(notify_val)
elif notify_type == "pg_summary":
self.update_pool_stats()

#pg_summary = self.get("pg_summary")
Copy link
Contributor

Choose a reason for hiding this comment

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

this change is not related to the noop stub of os._exit(). can we drop it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops! done.


PyModuleRunnerThread thread;

std::string const &get_name() { return module_name; }
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, make this method const.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

serve_threads[i.first].reset(thread);
}
int r = modules[module_name]->load(this);
if (r != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

shall we remove the module failed to load from modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the moment I suggest we keep them there -- later we might want to add a mechanism for reporting to the MgrMonitor about the list of modules that we tried and failed to load, so they need remembering somewhere.

@@ -134,7 +134,19 @@ int ActivePyModule::load_commands()
// Don't need a Gil here -- this is called from ActivePyModule::load(),
// which already has one.
PyObject *command_list = PyObject_GetAttrString(pClassInstance, "COMMANDS");
assert(command_list != nullptr);
if (command_list == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. I kind of disagree with the guidelines on this one, I like being explicit that I'm checking a pointer rather than evaluating a class instance for truthiness. I don't remember if the google C++ guide takes a position on this.

Py_INCREF(&BaseMgrModuleType);
PyModule_AddObject(ceph_module, "BaseMgrModule",
(PyObject *)&BaseMgrModuleType);
auto load_class = [ceph_module](std::string name, PyTypeObject *type)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, could just pass const char* instead of a std::string

Py_InitModule("ceph_crushmap", CRUSHMapMethods);
*/

auto load_class = [ceph_module](std::string name, PyTypeObject *type)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, pass const char* instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@tchaikov
Copy link
Contributor

@jcsp, could we split the mds related changes into separated PR(s)?

John Spray and others added 22 commits November 1, 2017 08:20
Separate out the *loading* of modules from
the *running* of modules.

This is a precursor to enabling modules to run
in standby mode.

Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: John Spray <john.spray@redhat.com>
Modules can implement a second, separate class
that has access to very little state about the
system and can't implement commands.

They have just enough information to redirect
or forward incoming requests/traffic to the
active instance of the module on the active mgr.

This enables module authors to create modules
that end users can access via any (running) mgr node
at any time, rather than having to first work out
which mgr node is active.

Signed-off-by: John Spray <john.spray@redhat.com>
...they still don't have access to any config though.

Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: John Spray <john.spray@redhat.com>
These would throw an exception when passed
a status code.

Signed-off-by: John Spray <john.spray@redhat.com>
...by using PyModuleRunner class from ActivePyModule too.

Signed-off-by: John Spray <john.spray@redhat.com>
Was passing a reference to a local stringstream into
Thread::create, not realising that it was taking a char*
reference instead of a copy.  Result was garbage (or usually,
all threads having the name of the last one created)

Signed-off-by: John Spray <john.spray@redhat.com>
Was calling way too early, which did a
Py_Finalize before the modules had been
joined.

Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: Sage Weil <sage@redhat.com>
Implement real python classes from the C side,
rather than exposing only module methods.

Signed-off-by: John Spray <john.spray@redhat.com>
A bunch of the previous commits were done
before this class existed, so updating in
one go instead of trying to edit history
in fine detail.

Signed-off-by: John Spray <john.spray@redhat.com>
This was doing a Py_DECREF outside of the Gil.

Fixes: http://tracker.ceph.com/issues/21593
Signed-off-by: John Spray <john.spray@redhat.com>
These didn't need to keep the GIL to go and do their
pure C++ parts, and by keeping it they could deadlock
while trying to take ActiveMgrModules::lock.

Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: John Spray <john.spray@redhat.com>
Some extra coverage of the dashboard, including its standby
redirect mode and the publishing of URIs.

Also invoking the command_spam mode of the selftest module.

Signed-off-by: John Spray <john.spray@redhat.com>
This was still using Kraken era settings

Signed-off-by: John Spray <john.spray@redhat.com>
Signed-off-by: John Spray <john.spray@redhat.com>
...including the new "mgr services" command.

Signed-off-by: John Spray <john.spray@redhat.com>
Otherwise, when someone wants to see what's possible
to do with `mgr module enable` they have to trawl
through the whole mgr map dump.

Signed-off-by: John Spray <john.spray@redhat.com>
@ceph-jenkins
Copy link
Collaborator

all commits in this PR are signed

@ceph-jenkins
Copy link
Collaborator

submodules for project are unmodified

@liewegas liewegas merged commit 2912364 into ceph:master Nov 1, 2017
@ceph-jenkins
Copy link
Collaborator

OK - docs built

@jcsp jcsp deleted the wip-mgr-module-interface branch November 1, 2017 12:54
@ceph-jenkins
Copy link
Collaborator

make check succeeded

1 similar comment
@ceph-jenkins
Copy link
Collaborator

make check succeeded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants