From 269e605d1d138e4721fff6198e18352573cdc4d8 Mon Sep 17 00:00:00 2001 From: ByteYue Date: Thu, 21 Dec 2023 15:00:15 +0800 Subject: [PATCH 1/5] support change be log level using http --- be/src/http/action/adjust_log_level.cpp | 56 +++++++++++++++++++++++++ be/src/http/action/adjust_log_level.h | 37 ++++++++++++++++ be/src/service/http_service.cpp | 5 +++ 3 files changed, 98 insertions(+) create mode 100644 be/src/http/action/adjust_log_level.cpp create mode 100644 be/src/http/action/adjust_log_level.h diff --git a/be/src/http/action/adjust_log_level.cpp b/be/src/http/action/adjust_log_level.cpp new file mode 100644 index 00000000000000..517463807b0a4f --- /dev/null +++ b/be/src/http/action/adjust_log_level.cpp @@ -0,0 +1,56 @@ +// 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 +#include + +#include "common/logging.h" +#include "common/status.h" +#include "http/http_channel.h" +#include "http/http_request.h" + +namespace doris { + +// **Note**: If the module_name does not exist in the vlog modules, vlog +// would create corresponding module for it. +int handle_request(HttpRequest* req) { + auto parse_param = [&req](std::string param) { + const auto& value = req->param(param); + if (value.empty()) { + auto error_msg = fmt::format("parameter {} not specified in url.", param); + throw std::runtime_error(error_msg); + } + return value; + }; + const auto& module = parse_param("module"); + const auto& level = req->param("level"); + int new_level = std::stoi(level); + return google::SetVLOGLevel(module.c_str(), new_level); +} + +void AdjustLogLevelAction::handle(HttpRequest* req) { + try { + auto old_level = handle_request(req); + auto msg = fmt::format("adjust log level success, origin level is {}", old_level); + HttpChannel::send_reply(req, msg); + } catch (const std::exception& e) { + HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, e.what()); + LOG(WARNING) << "adjust log level failed, error: " << e.what(); + return; + } +} +} // namespace doris \ No newline at end of file diff --git a/be/src/http/action/adjust_log_level.h b/be/src/http/action/adjust_log_level.h new file mode 100644 index 00000000000000..606d6129a261bd --- /dev/null +++ b/be/src/http/action/adjust_log_level.h @@ -0,0 +1,37 @@ +// 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 + +#include "common/status.h" +#include "http/http_handler.h" + +namespace doris { + +class HttpRequest; + +class AdjustLogLevelAction : public HttpHandler { +public: + AdjustLogLevelAction() = default; + + ~AdjustLogLevelAction() override = default; + + void handle(HttpRequest* req) override; +}; +} // namespace doris diff --git a/be/src/service/http_service.cpp b/be/src/service/http_service.cpp index 1423f82225fae6..af268b97cc4770 100644 --- a/be/src/service/http_service.cpp +++ b/be/src/service/http_service.cpp @@ -26,6 +26,7 @@ #include "common/config.h" #include "common/status.h" +#include "http/action/adjust_log_level.h" #include "http/action/check_rpc_channel_action.h" #include "http/action/check_tablet_segment_action.h" #include "http/action/checksum_action.h" @@ -158,6 +159,10 @@ Status HttpService::start() { _ev_http_server->register_handler(HttpMethod::HEAD, "/api/_binlog/_download", download_binlog_action); + AdjustLogLevelAction* adjust_log_level_action = _pool.add(new AdjustLogLevelAction()); + _ev_http_server->register_handler(HttpMethod::POST, "api/_glog/_adjust", + adjust_log_level_action); + // Register BE version action VersionAction* version_action = _pool.add(new VersionAction(_env, TPrivilegeHier::GLOBAL, TPrivilegeType::NONE)); From bea436e8745fa2d5b335be8e40e09222956d36fc Mon Sep 17 00:00:00 2001 From: ByteYue Date: Mon, 25 Dec 2023 15:10:57 +0800 Subject: [PATCH 2/5] do check --- be/src/http/action/adjust_log_level.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/be/src/http/action/adjust_log_level.cpp b/be/src/http/action/adjust_log_level.cpp index 517463807b0a4f..c3ec62462c0a36 100644 --- a/be/src/http/action/adjust_log_level.cpp +++ b/be/src/http/action/adjust_log_level.cpp @@ -37,7 +37,7 @@ int handle_request(HttpRequest* req) { return value; }; const auto& module = parse_param("module"); - const auto& level = req->param("level"); + const auto& level = parse_param("level"); int new_level = std::stoi(level); return google::SetVLOGLevel(module.c_str(), new_level); } From 55c46573a9bc119d9fbcd28fe9fe16c140188f41 Mon Sep 17 00:00:00 2001 From: ByteYue Date: Mon, 25 Dec 2023 16:33:11 +0800 Subject: [PATCH 3/5] remove useless header --- be/src/http/action/adjust_log_level.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/be/src/http/action/adjust_log_level.cpp b/be/src/http/action/adjust_log_level.cpp index c3ec62462c0a36..687639a9b58dea 100644 --- a/be/src/http/action/adjust_log_level.cpp +++ b/be/src/http/action/adjust_log_level.cpp @@ -15,7 +15,6 @@ // specific language governing permissions and limitations // under the License. -#include #include #include "common/logging.h" From 9d7f128392904176f5961cbb81c5135b42187eee Mon Sep 17 00:00:00 2001 From: AlexYue Date: Thu, 28 Dec 2023 15:22:00 +0800 Subject: [PATCH 4/5] update the url path --- be/src/service/http_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/be/src/service/http_service.cpp b/be/src/service/http_service.cpp index af268b97cc4770..e1bb8359750a58 100644 --- a/be/src/service/http_service.cpp +++ b/be/src/service/http_service.cpp @@ -160,7 +160,7 @@ Status HttpService::start() { download_binlog_action); AdjustLogLevelAction* adjust_log_level_action = _pool.add(new AdjustLogLevelAction()); - _ev_http_server->register_handler(HttpMethod::POST, "api/_glog/_adjust", + _ev_http_server->register_handler(HttpMethod::POST, "api/glog/adjust", adjust_log_level_action); // Register BE version action From d03bca0534e953607daf558c6296bb1c54e69ce2 Mon Sep 17 00:00:00 2001 From: ByteYue Date: Tue, 2 Jan 2024 13:51:40 +0800 Subject: [PATCH 5/5] format --- be/src/service/http_service.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/be/src/service/http_service.cpp b/be/src/service/http_service.cpp index e1bb8359750a58..6c961959aec634 100644 --- a/be/src/service/http_service.cpp +++ b/be/src/service/http_service.cpp @@ -160,8 +160,7 @@ Status HttpService::start() { download_binlog_action); AdjustLogLevelAction* adjust_log_level_action = _pool.add(new AdjustLogLevelAction()); - _ev_http_server->register_handler(HttpMethod::POST, "api/glog/adjust", - adjust_log_level_action); + _ev_http_server->register_handler(HttpMethod::POST, "api/glog/adjust", adjust_log_level_action); // Register BE version action VersionAction* version_action =