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: emit cluster log message on serve() exception #18672

Merged
merged 1 commit into from
Nov 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/mgr/ActivePyModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ class ActivePyModule : public PyModuleRunner
public:
ActivePyModule(const std::string &module_name_,
PyObject *pClass_,
const SafeThreadState &my_ts_)
: PyModuleRunner(module_name_, pClass_, my_ts_)
const SafeThreadState &my_ts_,
LogChannelRef clog_)
: PyModuleRunner(module_name_, pClass_, my_ts_, clog_)
{}

int load(ActivePyModules *py_modules);
Expand Down
2 changes: 1 addition & 1 deletion src/mgr/ActivePyModules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ int ActivePyModules::start_one(std::string const &module_name,

modules[module_name].reset(new ActivePyModule(
module_name, pClass,
pMyThreadState));
pMyThreadState, clog));

int r = modules[module_name]->load(this);
if (r != 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/mgr/PyModuleRegistry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void PyModuleRegistry::standby_start(MonClient *monc)

dout(4) << "Starting modules in standby mode" << dendl;

standby_modules.reset(new StandbyPyModules(monc, mgr_map));
standby_modules.reset(new StandbyPyModules(monc, mgr_map, clog));

std::set<std::string> failed_modules;
for (const auto &i : modules) {
Expand Down
17 changes: 17 additions & 0 deletions src/mgr/PyModuleRunner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ int PyModuleRunner::serve()
if (pValue != NULL) {
Py_DECREF(pValue);
} else {
// This is not a very informative log message because it's an
// unknown/unexpected exception that we can't say much about.

// Peek at the exception for the cluster log, before
// dumping the backtrace to log log next.
PyObject *ptype, *pvalue, *ptraceback;
PyErr_Fetch(&ptype, &pvalue, &ptraceback);
assert(ptype);
assert(pvalue);
PyObject *pvalue_str = PyObject_Str(pvalue);
std::string exc_msg = PyString_AsString(pvalue_str);
Py_DECREF(pvalue_str);
PyErr_Restore(ptype, pvalue, ptraceback);

clog->error() << "Unhandled exception from module '" << module_name
<< "' while running on mgr." << g_conf->name.get_id()
<< ": " << exc_msg;
derr << module_name << ".serve:" << dendl;
derr << handle_pyerror() << dendl;
return -EINVAL;
Expand Down
7 changes: 6 additions & 1 deletion src/mgr/PyModuleRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once

#include "common/Thread.h"
#include "common/LogClient.h"
#include "mgr/Gil.h"

/**
Expand All @@ -36,6 +37,8 @@ class PyModuleRunner
// Populated when we construct our instance of pClass in load()
PyObject *pClassInstance = nullptr;

LogChannelRef clog;

class PyModuleRunnerThread : public Thread
{
PyModuleRunner *mod;
Expand All @@ -55,10 +58,12 @@ class PyModuleRunner
PyModuleRunner(
const std::string &module_name_,
PyObject *pClass_,
const SafeThreadState &pMyThreadState_)
const SafeThreadState &pMyThreadState_,
LogChannelRef clog_)
:
module_name(module_name_),
pClass(pClass_), pMyThreadState(pMyThreadState_),
clog(clog_),
thread(this)
{
assert(pClass != nullptr);
Expand Down
7 changes: 4 additions & 3 deletions src/mgr/StandbyPyModules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
std::string handle_pyerror();


StandbyPyModules::StandbyPyModules(MonClient *monc_, const MgrMap &mgr_map_)
: monc(monc_), load_config_thread(monc, &state)
StandbyPyModules::StandbyPyModules(MonClient *monc_, const MgrMap &mgr_map_,
LogChannelRef clog_)
: monc(monc_), load_config_thread(monc, &state), clog(clog_)
{
state.set_mgr_map(mgr_map_);
}
Expand Down Expand Up @@ -86,7 +87,7 @@ int StandbyPyModules::start_one(std::string const &module_name,
modules[module_name].reset(new StandbyPyModule(
state,
module_name, pClass,
pMyThreadState));
pMyThreadState, clog));

if (modules.size() == 1) {
load_config_thread.create("LoadConfig");
Expand Down
10 changes: 7 additions & 3 deletions src/mgr/StandbyPyModules.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ class StandbyPyModule : public PyModuleRunner
StandbyPyModuleState &state_,
const std::string &module_name_,
PyObject *pClass_,
const SafeThreadState &pMyThreadState_)
const SafeThreadState &pMyThreadState_,
LogChannelRef clog_)
:
PyModuleRunner(module_name_, pClass_, pMyThreadState_),
PyModuleRunner(module_name_, pClass_, pMyThreadState_, clog_),
state(state_)
{
}
Expand Down Expand Up @@ -129,11 +130,14 @@ class StandbyPyModules

LoadConfigThread load_config_thread;

LogChannelRef clog;

public:

StandbyPyModules(
MonClient *monc_,
const MgrMap &mgr_map_);
const MgrMap &mgr_map_,
LogChannelRef clog_);

int start_one(std::string const &module_name,
PyObject *pClass,
Expand Down