]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: add lua counters
authorYuval Lifshitz <ylifshit@redhat.com>
Wed, 4 May 2022 04:58:49 +0000 (07:58 +0300)
committerYuval Lifshitz <ylifshit@redhat.com>
Sun, 8 May 2022 11:11:13 +0000 (14:11 +0300)
Signed-off-by: Yuval Lifshitz <ylifshit@redhat.com>
src/rgw/rgw_lua_background.cc
src/rgw/rgw_lua_request.cc
src/rgw/rgw_lua_utils.h
src/rgw/rgw_perf_counters.cc
src/rgw/rgw_perf_counters.h

index 56000edff2395bbfe01674862a3b0f2407f72fe0..33b0982b1d698e76b4d74afc920cd7e10c307843 100644 (file)
@@ -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 <lua.hpp>
 
@@ -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));
index 1904337128cdb836af4628cb8dfcf791690fa984..08dfe44abd7b16a90c1d99a3601296a7c6f20595 100644 (file)
@@ -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;
 }
 
 }
index fb3cb5dcc62982c7a0416cca7c0f4e04277d1fc0..4d1e7510d10fd0d4175f4fe13b098e0b9223c587 100644 (file)
@@ -7,6 +7,7 @@
 #include <lua.hpp>
 
 #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;}
 };
 
index 3336c4855e044afb3ba2ec0b39327c102cf5072c..fd058ab00a9f226eb44ecaabbb0303ee62301047 100644 (file)
@@ -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;
index a3c10d9a947d2671233e882a715245ffe44226d0..7596959859b5b8389fcb35e2ae577fc17a56cad2 100644 (file)
@@ -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,
 };