From 9fbbf6ea47a109f4ecb56120fb40054d1b2c7a22 Mon Sep 17 00:00:00 2001 From: kchheda3 Date: Fri, 24 Jan 2025 09:43:41 -0500 Subject: [PATCH] rgw/lua: Fix healthchecks requests to not goto backend storage. Signed-off-by: kchheda3 (cherry picked from commit 39b4d38a3d06f6022f08cf8ca5fc7f5e5ae8a1e3) --- PendingReleaseNotes | 2 ++ src/rgw/rgw_process.cc | 58 +++++++++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/PendingReleaseNotes b/PendingReleaseNotes index 05750c2760507..57e496cde9c15 100644 --- a/PendingReleaseNotes +++ b/PendingReleaseNotes @@ -1,5 +1,7 @@ >=20.0.0 +* RGW: Lua scripts will not run against health checks. + * RBD: All Python APIs that produce timestamps now return "aware" `datetime` objects instead of "naive" ones (i.e. those including time zone information instead of those not including it). All timestamps remain to be in UTC but diff --git a/src/rgw/rgw_process.cc b/src/rgw/rgw_process.cc index c1c16a88d9763..8c3f3b726e058 100644 --- a/src/rgw/rgw_process.cc +++ b/src/rgw/rgw_process.cc @@ -306,6 +306,7 @@ int process_request(const RGWProcessEnv& penv, bool should_log = false; RGWREST* rest = penv.rest; RGWRESTMgr *mgr; + bool is_health_request = false; RGWHandler_REST *handler = rest->get_handler(driver, s, *penv.auth_registry, frontend_prefix, @@ -326,18 +327,27 @@ int process_request(const RGWProcessEnv& penv, abort_early(s, NULL, -ERR_METHOD_NOT_ALLOWED, handler, yield); goto done; } + is_health_request = (op->get_type() == RGW_OP_GET_HEALTH_CHECK); { s->trace_enabled = tracing::rgw::tracer.is_enabled(); - std::string script; - auto rc = rgw::lua::read_script(s, penv.lua.manager.get(), s->bucket_tenant, s->yield, rgw::lua::context::preRequest, script); - if (rc == -ENOENT) { - // no script, nothing to do - } else if (rc < 0) { - ldpp_dout(op, 5) << "WARNING: failed to read pre request script. error: " << rc << dendl; - } else { - rc = rgw::lua::request::execute(driver, rest, penv.olog.get(), s, op, script); - if (rc < 0) { - ldpp_dout(op, 5) << "WARNING: failed to execute pre request script. error: " << rc << dendl; + if (!is_health_request) { + std::string script; + auto rc = rgw::lua::read_script(s, penv.lua.manager.get(), + s->bucket_tenant, s->yield, + rgw::lua::context::preRequest, script); + if (rc == -ENOENT) { + // no script, nothing to do + } else if (rc < 0) { + ldpp_dout(op, 5) << + "WARNING: failed to execute pre request script. " + "error: " << rc << dendl; + } else { + rc = rgw::lua::request::execute(driver, rest, penv.olog.get(), s, op, script); + if (rc < 0) { + ldpp_dout(op, 5) << + "WARNING: failed to execute pre request script. " + "error: " << rc << dendl; + } } } } @@ -418,16 +428,24 @@ done: s->trace->SetAttribute(tracing::rgw::OBJECT_NAME, s->object->get_name()); } } - std::string script; - auto rc = rgw::lua::read_script(s, penv.lua.manager.get(), s->bucket_tenant, s->yield, rgw::lua::context::postRequest, script); - if (rc == -ENOENT) { - // no script, nothing to do - } else if (rc < 0) { - ldpp_dout(op, 5) << "WARNING: failed to read post request script. error: " << rc << dendl; - } else { - rc = rgw::lua::request::execute(driver, rest, penv.olog.get(), s, op, script); - if (rc < 0) { - ldpp_dout(op, 5) << "WARNING: failed to execute post request script. error: " << rc << dendl; + if (!is_health_request) { + std::string script; + auto rc = rgw::lua::read_script(s, penv.lua.manager.get(), + s->bucket_tenant, s->yield, + rgw::lua::context::postRequest, script); + if (rc == -ENOENT) { + // no script, nothing to do + } else if (rc < 0) { + ldpp_dout(op, 5) << + "WARNING: failed to read post request script. " + "error: " << rc << dendl; + } else { + rc = rgw::lua::request::execute(driver, rest, penv.olog.get(), s, op, script); + if (rc < 0) { + ldpp_dout(op, 5) << + "WARNING: failed to execute post request script. " + "error: " << rc << dendl; + } } } } -- 2.39.5