]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: support conditional tracing using lua script 45662/head
authorOmri Zeneva <ozeneva@redhat.com>
Sun, 20 Mar 2022 19:10:34 +0000 (15:10 -0400)
committerOmri Zeneva <ozeneva@redhat.com>
Wed, 11 May 2022 08:10:02 +0000 (11:10 +0300)
before lua script is being executed, we keep the tracer runtime configuration value, and then decides whether to trace or not the request based on the value that maybe changed during lua exeuction, so we can disable/enable tracing for request even if the tracer is in the opposite state at the same time

Signed-off-by: Omri Zeneva <ozeneva@redhat.com>
doc/radosgw/lua-scripting.rst
src/common/tracer.cc
src/common/tracer.h
src/rgw/rgw_common.h
src/rgw/rgw_lua_request.cc
src/rgw/rgw_op.cc
src/rgw/rgw_op.h
src/rgw/rgw_process.cc

index d970455a5205835e7812d4a8a901856917ee6448..daf77ca0be7f9947b96fc5632370675ccab1e24f 100644 (file)
@@ -290,6 +290,10 @@ Request Fields
 +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
 | ``Request.User.Id``                                | string   | triggering user id                                           | no       | no        | no       |
 +----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
+| ``Request.Trace``                                  | table    | info on trace                                                | no       | no        | no       |
++----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
+| ``Request.Trace.Enable``                           | boolean  | tracing is enabled                                           | no       | yes       | no       |
++----------------------------------------------------+----------+--------------------------------------------------------------+----------+-----------+----------+
 
 Request Functions
 --------------------
@@ -424,3 +428,26 @@ Then, do a restart for the radosgw and upload the following script to the `postR
     assert(s:close())
   end
 
+
+- Trace only requests of specific bucket
+
+Tracing is disabled by default, so we should enable tracing for this specific bucket
+
+.. code-block:: lua
+
+  if Request.Bucket.Name == "my-bucket" then
+      Request.Trace.Enable = true
+  end
+
+
+If `tracing is enabled <https://docs.ceph.com/en/latest/jaegertracing/#how-to-enable-tracing-in-ceph/>`_ on the RGW, the value of Request.Trace.Enable is true, so we should disable tracing for all other requests that do not match the bucket name.
+In the `preRequest` context:
+
+.. code-block:: lua
+
+  if Request.Bucket.Name ~= "my-bucket" then
+      Request.Trace.Enable = false
+  end
+
+Note that changing `Request.Trace.Enable` does not change the tracer's state, but disables or enables the tracing for the request only.
+
index f10e0598a93415f973082fe2c84fe4cabd2a44e3..c9891726044c8a57653076a97febdf99e7ca092b 100644 (file)
@@ -42,8 +42,15 @@ jspan Tracer::start_trace(opentelemetry::nostd::string_view trace_name) {
   return noop_tracer->StartSpan(trace_name);
 }
 
+jspan Tracer::start_trace(opentelemetry::nostd::string_view trace_name, bool trace_is_enabled) {
+  if (trace_is_enabled) {
+    return tracer->StartSpan(trace_name);
+  }
+  return noop_tracer->StartSpan(trace_name);
+}
+
 jspan Tracer::add_span(opentelemetry::nostd::string_view span_name, const jspan& parent_span) {
-  if (is_enabled() && parent_span) {
+  if (is_enabled() && parent_span->IsRecording()) {
     const auto parent_ctx = parent_span->GetContext();
     return add_span(span_name, parent_ctx);
   }
index 3d0e28f9b85c7d0b97bfc1c24cdc2f8d2995e367..bd095f310f6184c954a098ecee193eac7d82aaca 100644 (file)
@@ -34,6 +34,11 @@ class Tracer {
   // creates and returns a new span with `trace_name`
   // this span represents a trace, since it has no parent.
   jspan start_trace(opentelemetry::nostd::string_view trace_name);
+
+  // creates and returns a new span with `trace_name`
+  // if false is given to `trace_is_enabled` param, noop span will be returned
+  jspan start_trace(opentelemetry::nostd::string_view trace_name, bool trace_is_enabled);
+
   // creates and returns a new span with `span_name` which parent span is `parent_span'
   jspan add_span(opentelemetry::nostd::string_view span_name, const jspan& parent_span);
   // creates and return a new span with `span_name`
@@ -90,7 +95,7 @@ namespace tracing {
 
 struct Tracer {
   bool is_enabled() const { return false; }
-  jspan start_trace(std::string_view) { return {}; }
+  jspan start_trace(std::string_view, bool enabled = true) { return {}; }
   jspan add_span(std::string_view, const jspan&) { return {}; }
   jspan add_span(std::string_view span_name, const jspan_context& parent_ctx) { return {}; }
   void init(std::string_view service_name) {}
index ddb455f041cf9e5cbe35c91d381aea07607c5666..c75871150030c878969b34b55ecf2a9133949d00 100644 (file)
@@ -1690,6 +1690,7 @@ struct req_state : DoutPrefixProvider {
   std::vector<rgw::IAM::Policy> session_policies;
 
   jspan trace;
+  bool trace_enabled = false;
 
   //Principal tags that come in as part of AssumeRoleWithWebIdentity
   std::vector<std::pair<std::string, std::string>> principal_tags;
index 2e971c329c8752c097a63e7e175efee7884ce539..1efd71f1484d8aa79a06ae2ef355549289014161 100644 (file)
@@ -146,6 +146,37 @@ struct UserMetaTable : public EmptyMetaTable {
   }
 };
 
+struct TraceMetaTable : public EmptyMetaTable {
+  static std::string TableName() {return "Trace";}
+  static std::string Name() {return TableName() + "Meta";}
+
+  static int IndexClosure(lua_State* L) {
+    const auto s = reinterpret_cast<req_state*>(lua_touserdata(L, lua_upvalueindex(1)));
+
+    const char* index = luaL_checkstring(L, 2);
+
+    if (strcasecmp(index, "Enable") == 0) {
+      lua_pushboolean(L, s->trace_enabled);
+    } else {
+      return error_unknown_field(L, index, TableName());
+    }
+    return ONE_RETURNVAL;
+  }
+
+  static int NewIndexClosure(lua_State* L) {
+    const auto s = reinterpret_cast<req_state*>(lua_touserdata(L, lua_upvalueindex(1)));
+
+    const char* index = luaL_checkstring(L, 2);
+
+    if (strcasecmp(index, "Enable") == 0) {
+      s->trace_enabled = lua_toboolean(L, 3);
+    } else {
+      return error_unknown_field(L, index, TableName());
+    }
+    return NO_RETURNVAL;
+  }
+};
+
 struct OwnerMetaTable : public EmptyMetaTable {
   static std::string TableName() {return "Owner";}
   static std::string Name() {return TableName() + "Meta";}
@@ -781,6 +812,8 @@ struct RequestMetaTable : public EmptyMetaTable {
       } else {
         create_metatable<UserMetaTable>(L, false, const_cast<rgw_user*>(&(s->user->get_id())));
       }
+    } else if (strcasecmp(index, "Trace") == 0) {
+        create_metatable<TraceMetaTable>(L, false, s);
     } else {
       return error_unknown_field(L, index, TableName());
     }
index 961d3aec8e0e2a4e91a95548421cfe75656e03d7..37541eef405d0e5237d9df2e98440499ff0915ac 100644 (file)
@@ -6174,6 +6174,7 @@ void RGWInitMultipart::pre_exec()
 
 void RGWInitMultipart::execute(optional_yield y)
 {
+  multipart_trace = tracing::rgw::tracer.start_trace(tracing::rgw::MULTIPART, s->trace_enabled);
   bufferlist aclbl, tracebl;
   rgw::sal::Attrs attrs;
 
index f584d78a718b00ea31e6fd9dcd12ebd36bbeeae0..92827be5a0974289f7850564a658c8be52f8e0b4 100644 (file)
@@ -1841,7 +1841,6 @@ public:
   RGWInitMultipart() {}
 
   void init(rgw::sal::Store* store, struct req_state *s, RGWHandler *h) override {
-    multipart_trace = tracing::rgw::tracer.start_trace(tracing::rgw::MULTIPART);
     RGWOp::init(store, s, h);
     policy.set_ctx(s->cct);
   }
index 77ef102d30c1d3f0afe01256d35737ca2a8a3ee8..a4d44267bfb4e31aee3c74984e557aca57975adb 100644 (file)
@@ -328,6 +328,7 @@ int process_request(rgw::sal::Store* const store,
     goto done;
   }
   {
+    s->trace_enabled = tracing::rgw::tracer.is_enabled();
     std::string script;
     auto rc = rgw::lua::read_script(s, store, s->bucket_tenant, s->yield, rgw::lua::context::preRequest, script);
     if (rc == -ENOENT) {
@@ -383,8 +384,9 @@ int process_request(rgw::sal::Store* const store,
       goto done;
     }
 
+
     const auto trace_name = std::string(op->name()) + " " + s->trans_id;
-    s->trace = tracing::rgw::tracer.start_trace(trace_name);
+    s->trace = tracing::rgw::tracer.start_trace(trace_name, s->trace_enabled);
     s->trace->SetAttribute(tracing::rgw::OP, op->name());
     s->trace->SetAttribute(tracing::rgw::TYPE, tracing::rgw::REQUEST);