From: Yuval Lifshitz Date: Wed, 4 May 2022 04:58:49 +0000 (+0300) Subject: rgw: add lua counters X-Git-Tag: v18.0.0~742^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f5223c0bca6241e1ecb9a0cdf67c412feb218926;p=ceph.git rgw: add lua counters Signed-off-by: Yuval Lifshitz --- diff --git a/src/rgw/rgw_lua_background.cc b/src/rgw/rgw_lua_background.cc index 56000edff239..33b0982b1d69 100644 --- a/src/rgw/rgw_lua_background.cc +++ b/src/rgw/rgw_lua_background.cc @@ -1,6 +1,7 @@ #include "rgw_lua_background.h" #include "rgw_lua.h" #include "rgw_lua_utils.h" +#include "rgw_perf_counters.h" #include "include/ceph_assert.h" #include @@ -51,14 +52,20 @@ void Background::run() { } else if (rc < 0) { ldpp_dout(dpp, 1) << "WARNING: failed to read background script. error " << rc << dendl; } else { + auto failed = false; try { //execute the background lua script if (luaL_dostring(L, rgw_script.c_str()) != LUA_OK) { const std::string err(lua_tostring(L, -1)); ldpp_dout(dpp, 1) << "Lua ERROR: " << err << dendl; + failed = true; } } catch (const std::exception& e) { - ldpp_dout(dpp, 1) << "Lua ERROR: " << e.what() << dendl; + ldpp_dout(dpp, 1) << "Lua ERROR: " << e.what() << dendl; + failed = true; + } + if (perfcounter) { + perfcounter->inc((failed ? l_rgw_lua_script_fail : l_rgw_lua_script_ok), 1); } } std::this_thread::sleep_for(std::chrono::seconds(execute_interval)); diff --git a/src/rgw/rgw_lua_request.cc b/src/rgw/rgw_lua_request.cc index 1904337128cd..08dfe44abd7b 100644 --- a/src/rgw/rgw_lua_request.cc +++ b/src/rgw/rgw_lua_request.cc @@ -12,6 +12,7 @@ #include "rgw_acl.h" #include "rgw_sal_rados.h" #include "rgw_lua_background.h" +#include "rgw_perf_counters.h" #define dout_subsys ceph_subsys_rgw @@ -750,19 +751,23 @@ int execute( ceph_assert(lua_istable(L, -1)); } + int rc = 0; try { // execute the lua script if (luaL_dostring(L, script.c_str()) != LUA_OK) { const std::string err(lua_tostring(L, -1)); ldpp_dout(s, 1) << "Lua ERROR: " << err << dendl; - return -1; + rc = -1; } } catch (const std::runtime_error& e) { ldpp_dout(s, 1) << "Lua ERROR: " << e.what() << dendl; - return -1; + rc = -1; + } + if (perfcounter) { + perfcounter->inc((rc == -1 ? l_rgw_lua_script_fail : l_rgw_lua_script_ok), 1); } - return 0; + return rc; } } diff --git a/src/rgw/rgw_lua_utils.h b/src/rgw/rgw_lua_utils.h index fb3cb5dcc629..4d1e7510d10f 100644 --- a/src/rgw/rgw_lua_utils.h +++ b/src/rgw/rgw_lua_utils.h @@ -7,6 +7,7 @@ #include #include "include/common_fwd.h" +#include "rgw_perf_counters.h" namespace rgw::lua { @@ -38,8 +39,17 @@ void stack_dump(lua_State* L); class lua_state_guard { lua_State* l; public: - lua_state_guard(lua_State* _l) : l(_l) {} - ~lua_state_guard() {lua_close(l);} + lua_state_guard(lua_State* _l) : l(_l) { + if (perfcounter) { + perfcounter->inc(l_rgw_lua_current_vms, 1); + } + } + ~lua_state_guard() { + lua_close(l); + if (perfcounter) { + perfcounter->dec(l_rgw_lua_current_vms, 1); + } + } void reset(lua_State* _l=nullptr) {l = _l;} }; diff --git a/src/rgw/rgw_perf_counters.cc b/src/rgw/rgw_perf_counters.cc index 3336c4855e04..fd058ab00a9f 100644 --- a/src/rgw/rgw_perf_counters.cc +++ b/src/rgw/rgw_perf_counters.cc @@ -60,6 +60,10 @@ int rgw_perf_start(CephContext *cct) plb.add_u64(l_rgw_pubsub_push_pending, "pubsub_push_pending", "Pubsub events pending reply from endpoint"); plb.add_u64_counter(l_rgw_pubsub_missing_conf, "pubsub_missing_conf", "Pubsub events could not be handled because of missing configuration"); + plb.add_u64_counter(l_rgw_lua_script_ok, "lua_script_ok", "Successfull executions of lua scripts"); + plb.add_u64_counter(l_rgw_lua_script_fail, "lua_script_fail", "Failed executions of lua scripts"); + plb.add_u64(l_rgw_lua_current_vms, "lua_current_vms", "Number of Lua VMs currently being executed"); + perfcounter = plb.create_perf_counters(); cct->get_perfcounters_collection()->add(perfcounter); return 0; diff --git a/src/rgw/rgw_perf_counters.h b/src/rgw/rgw_perf_counters.h index a3c10d9a947d..7596959859b5 100644 --- a/src/rgw/rgw_perf_counters.h +++ b/src/rgw/rgw_perf_counters.h @@ -50,6 +50,10 @@ enum { l_rgw_pubsub_push_pending, l_rgw_pubsub_missing_conf, + l_rgw_lua_current_vms, + l_rgw_lua_script_ok, + l_rgw_lua_script_fail, + l_rgw_last, };