github-actions[bot] commented on code in PR #24502: URL: https://github.com/apache/doris/pull/24502#discussion_r1333833968
########## be/src/http/action/debug_point_action.cpp: ########## @@ -0,0 +1,93 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "http/action/debug_point_action.h" + +#include "common/config.h" +#include "http/http_channel.h" +#include "http/http_status.h" +#include "util/debug_points.h" + +namespace doris { + +void BaseDebugPointAction::handle(HttpRequest* req) { + LOG(INFO) << "accept one request " << req->debug_string(); + Status status; + if (config::enable_debug_points) { + status = _handle(req); + } else { + status = Status::InternalError( + "Disable debug points. please check config::enable_debug_points"); + } + std::string result = status.to_json(); + LOG(INFO) << "handle request result:" << result; + if (status.ok()) { + HttpChannel::send_reply(req, HttpStatus::OK, result); + } else { + HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, result); + } +} + +Status AddDebugPointAction::_handle(HttpRequest* req) { + std::string debug_point = req->param("debug_point"); Review Comment: warning: variable 'debug_point' is not initialized [cppcoreguidelines-init-variables] ```suggestion std::string debug_point = 0 = req->param("debug_point"); ``` ########## be/src/http/action/debug_point_action.cpp: ########## @@ -0,0 +1,93 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "http/action/debug_point_action.h" + +#include "common/config.h" +#include "http/http_channel.h" +#include "http/http_status.h" +#include "util/debug_points.h" + +namespace doris { + +void BaseDebugPointAction::handle(HttpRequest* req) { + LOG(INFO) << "accept one request " << req->debug_string(); + Status status; + if (config::enable_debug_points) { + status = _handle(req); + } else { + status = Status::InternalError( + "Disable debug points. please check config::enable_debug_points"); + } + std::string result = status.to_json(); Review Comment: warning: variable 'result' is not initialized [cppcoreguidelines-init-variables] ```suggestion std::string result = 0 = status.to_json(); ``` ########## be/src/http/action/debug_point_action.cpp: ########## @@ -0,0 +1,93 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "http/action/debug_point_action.h" + +#include "common/config.h" +#include "http/http_channel.h" +#include "http/http_status.h" +#include "util/debug_points.h" + +namespace doris { + +void BaseDebugPointAction::handle(HttpRequest* req) { + LOG(INFO) << "accept one request " << req->debug_string(); + Status status; + if (config::enable_debug_points) { + status = _handle(req); + } else { + status = Status::InternalError( + "Disable debug points. please check config::enable_debug_points"); + } + std::string result = status.to_json(); + LOG(INFO) << "handle request result:" << result; + if (status.ok()) { + HttpChannel::send_reply(req, HttpStatus::OK, result); + } else { + HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, result); + } +} + +Status AddDebugPointAction::_handle(HttpRequest* req) { + std::string debug_point = req->param("debug_point"); + std::string execute = req->param("execute"); + std::string timeout = req->param("timeout"); Review Comment: warning: variable 'timeout' is not initialized [cppcoreguidelines-init-variables] ```suggestion std::string timeout = 0 = req->param("timeout"); ``` ########## be/src/service/http_service.cpp: ########## @@ -232,7 +233,23 @@ Status HttpService::start() { PadRowsetAction* pad_rowset_action = _pool.add(new PadRowsetAction(_env, TPrivilegeHier::GLOBAL, TPrivilegeType::ADMIN)); - _ev_http_server->register_handler(HttpMethod::POST, "api/pad_rowset", pad_rowset_action); + _ev_http_server->register_handler(HttpMethod::POST, "/api/pad_rowset", pad_rowset_action); + + // debug point + AddDebugPointAction* add_debug_point_action = + _pool.add(new AddDebugPointAction(_env, TPrivilegeHier::GLOBAL, TPrivilegeType::ADMIN)); + _ev_http_server->register_handler(HttpMethod::POST, "/api/debug_point/add/{debug_point}", + add_debug_point_action); + + RemoveDebugPointAction* remove_debug_point_action = _pool.add( Review Comment: warning: variable 'remove_debug_point_action' is not initialized [cppcoreguidelines-init-variables] ```suggestion RemoveDebugPointAction* remove_debug_point_action = nullptr = _pool.add( ``` ########## be/src/http/action/debug_point_action.cpp: ########## @@ -0,0 +1,93 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "http/action/debug_point_action.h" + +#include "common/config.h" +#include "http/http_channel.h" +#include "http/http_status.h" +#include "util/debug_points.h" + +namespace doris { + +void BaseDebugPointAction::handle(HttpRequest* req) { + LOG(INFO) << "accept one request " << req->debug_string(); + Status status; + if (config::enable_debug_points) { + status = _handle(req); + } else { + status = Status::InternalError( + "Disable debug points. please check config::enable_debug_points"); + } + std::string result = status.to_json(); + LOG(INFO) << "handle request result:" << result; + if (status.ok()) { + HttpChannel::send_reply(req, HttpStatus::OK, result); + } else { + HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, result); + } +} + +Status AddDebugPointAction::_handle(HttpRequest* req) { + std::string debug_point = req->param("debug_point"); + std::string execute = req->param("execute"); + std::string timeout = req->param("timeout"); + if (debug_point.empty()) { + return Status::InternalError("Empty debug point name"); + } + int execute_limit = -1; + long timeout_second = -1; + try { + if (!execute.empty()) { + execute_limit = std::stoi(execute); + } + } catch (const std::exception& e) { + return Status::InternalError("Invalid execute limit format, execute {}, err {}", execute, + e.what()); + } + try { + if (!timeout.empty()) { + timeout_second = std::stol(timeout); + } + } catch (const std::exception& e) { + return Status::InternalError("Invalid timeout format, timeout {}, err {}", timeout, + e.what()); + } + + DebugPoints::instance()->add(debug_point, execute_limit, timeout_second); + + return Status::OK(); +} + +Status RemoveDebugPointAction::_handle(HttpRequest* req) { + std::string debug_point = req->param("debug_point"); Review Comment: warning: variable 'debug_point' is not initialized [cppcoreguidelines-init-variables] ```suggestion std::string debug_point = 0 = req->param("debug_point"); ``` ########## be/src/service/http_service.cpp: ########## @@ -232,7 +233,23 @@ Status HttpService::start() { PadRowsetAction* pad_rowset_action = _pool.add(new PadRowsetAction(_env, TPrivilegeHier::GLOBAL, TPrivilegeType::ADMIN)); - _ev_http_server->register_handler(HttpMethod::POST, "api/pad_rowset", pad_rowset_action); + _ev_http_server->register_handler(HttpMethod::POST, "/api/pad_rowset", pad_rowset_action); + + // debug point + AddDebugPointAction* add_debug_point_action = Review Comment: warning: variable 'add_debug_point_action' is not initialized [cppcoreguidelines-init-variables] ```suggestion AddDebugPointAction* add_debug_point_action = nullptr = ``` ########## be/src/util/debug_points.h: ########## @@ -0,0 +1,62 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <map> +#include <mutex> +#include <string> + +#include "common/compiler_util.h" +#include "common/config.h" + +#define DBUG_EXECUTE_IF(debug_point, code) \ + if (UNLIKELY(config::enable_debug_points)) { \ + if (DebugPoints::instance()->is_enable(debug_point)) { \ + code \ + } \ + } + +namespace doris { + +struct DebugPoint { + int execute_num = 0; + int execute_limit = -1; + int64_t expire_ms = -1; +}; + +class DebugPoints { +public: + bool is_enable(const std::string& name); + void add(const std::string& name, int execute_limit, int64_t timeout_second); + void remove(const std::string& name); + void clear(); + + static DebugPoints* instance() { + static DebugPoints instance; + return &instance; + } + +private: + DebugPoints() = default; + +private: Review Comment: warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers] ```suggestion ``` <details> <summary>Additional context</summary> **be/src/util/debug_points.h:53:** previously declared here ```cpp private: ^ ``` </details> ########## be/src/http/action/debug_point_action.cpp: ########## @@ -0,0 +1,93 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "http/action/debug_point_action.h" + +#include "common/config.h" +#include "http/http_channel.h" +#include "http/http_status.h" +#include "util/debug_points.h" + +namespace doris { + +void BaseDebugPointAction::handle(HttpRequest* req) { + LOG(INFO) << "accept one request " << req->debug_string(); + Status status; + if (config::enable_debug_points) { + status = _handle(req); + } else { + status = Status::InternalError( + "Disable debug points. please check config::enable_debug_points"); + } + std::string result = status.to_json(); + LOG(INFO) << "handle request result:" << result; + if (status.ok()) { + HttpChannel::send_reply(req, HttpStatus::OK, result); + } else { + HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, result); + } +} + +Status AddDebugPointAction::_handle(HttpRequest* req) { + std::string debug_point = req->param("debug_point"); + std::string execute = req->param("execute"); Review Comment: warning: variable 'execute' is not initialized [cppcoreguidelines-init-variables] ```suggestion std::string execute = 0 = req->param("execute"); ``` ########## be/src/service/http_service.cpp: ########## @@ -232,7 +233,23 @@ Status HttpService::start() { PadRowsetAction* pad_rowset_action = _pool.add(new PadRowsetAction(_env, TPrivilegeHier::GLOBAL, TPrivilegeType::ADMIN)); - _ev_http_server->register_handler(HttpMethod::POST, "api/pad_rowset", pad_rowset_action); + _ev_http_server->register_handler(HttpMethod::POST, "/api/pad_rowset", pad_rowset_action); + + // debug point + AddDebugPointAction* add_debug_point_action = + _pool.add(new AddDebugPointAction(_env, TPrivilegeHier::GLOBAL, TPrivilegeType::ADMIN)); + _ev_http_server->register_handler(HttpMethod::POST, "/api/debug_point/add/{debug_point}", + add_debug_point_action); + + RemoveDebugPointAction* remove_debug_point_action = _pool.add( + new RemoveDebugPointAction(_env, TPrivilegeHier::GLOBAL, TPrivilegeType::ADMIN)); + _ev_http_server->register_handler(HttpMethod::POST, "/api/debug_point/remove/{debug_point}", + remove_debug_point_action); + + ClearDebugPointsAction* clear_debug_points_action = _pool.add( Review Comment: warning: variable 'clear_debug_points_action' is not initialized [cppcoreguidelines-init-variables] ```suggestion ClearDebugPointsAction* clear_debug_points_action = nullptr = _pool.add( ``` ########## be/src/util/debug_points.h: ########## @@ -0,0 +1,62 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once + +#include <map> +#include <mutex> +#include <string> + +#include "common/compiler_util.h" +#include "common/config.h" + +#define DBUG_EXECUTE_IF(debug_point, code) \ Review Comment: warning: macro is not used [clang-diagnostic-unused-macros] ```cpp #define DBUG_EXECUTE_IF(debug_point, code) \ ^ ``` ########## be/src/util/debug_points.cpp: ########## @@ -0,0 +1,79 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "util/debug_points.h" + +#include "common/logging.h" +#include "util/time.h" + +namespace doris { + +bool DebugPoints::is_enable(const std::string& name) { + if (!config::enable_debug_points) { + return false; + } + std::lock_guard<std::mutex> lock(_mutex); + auto it = _debug_points.find(name); + if (it == _debug_points.end()) { + return false; + } + + auto& debug_point = it->second; + if ((debug_point.expire_ms > 0 && MonotonicMillis() >= debug_point.expire_ms) || + (debug_point.execute_limit > 0 && debug_point.execute_num >= debug_point.execute_limit)) { + _debug_points.erase(it); + return false; + } + + debug_point.execute_num++; + + return true; +} + +void DebugPoints::add(const std::string& name, int execute_limit, int64_t timeout_second) { + DebugPoint debug_point; + debug_point.execute_limit = execute_limit; + if (timeout_second > 0) { + debug_point.expire_ms = MonotonicMillis() + timeout_second * MILLIS_PER_SEC; + } + + { + std::lock_guard<std::mutex> lock(_mutex); + _debug_points[name] = debug_point; + } + LOG(INFO) << "add debug point: name=" << name << ", execute=" << execute_limit + << ", timeout=" << timeout_second; +} + +void DebugPoints::remove(const std::string& name) { + bool exists; Review Comment: warning: variable 'exists' is not initialized [cppcoreguidelines-init-variables] ```suggestion bool exists = false; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
