Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feature)(LOG) Support to change be vlog level dynamically using http #28785

Merged
merged 5 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions be/src/http/action/adjust_log_level.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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/adjust_log_level.h>

#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 = parse_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
37 changes: 37 additions & 0 deletions be/src/http/action/adjust_log_level.h
Original file line number Diff line number Diff line change
@@ -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 <string>

#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
4 changes: 4 additions & 0 deletions be/src/service/http_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -158,6 +159,9 @@ 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));
Expand Down
Loading