be/src/service/http/action/adjust_log_level.cpp
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "service/http/action/adjust_log_level.h" |
19 | | |
20 | | #include <tuple> |
21 | | |
22 | | #include "common/logging.h" |
23 | | #include "service/http/http_channel.h" |
24 | | #include "service/http/http_request.h" |
25 | | #include "util/string_util.h" |
26 | | |
27 | | namespace doris { |
28 | | |
29 | | // **Note**: If the module_name does not exist in the vlog modules, vlog |
30 | | // would create corresponding module for it. |
31 | 0 | Result<std::tuple<std::string, int, int>> handle_request(HttpRequest* req) { |
32 | 0 | auto parse_param = [&req](std::string param) { |
33 | 0 | const auto& value = req->param(param); |
34 | 0 | if (value.empty()) { |
35 | 0 | auto error_msg = fmt::format("parameter {} not specified in url.", param); |
36 | 0 | throw std::runtime_error(error_msg); |
37 | 0 | } |
38 | 0 | return value; |
39 | 0 | }; |
40 | 0 | const auto& module = parse_param("module"); |
41 | 0 | const auto& level = parse_param("level"); |
42 | 0 | auto result = safe_stoi(level, "level"); |
43 | 0 | if (result.has_value()) { |
44 | 0 | return std::make_tuple(module, google::SetVLOGLevel(module.c_str(), result.value()), |
45 | 0 | result.value()); |
46 | 0 | } else { |
47 | 0 | return unexpected(std::move(result).error()); |
48 | 0 | } |
49 | 0 | } |
50 | | |
51 | 0 | void AdjustLogLevelAction::handle(HttpRequest* req) { |
52 | 0 | try { |
53 | 0 | auto handle_result = handle_request(req); |
54 | 0 | if (handle_result.has_value()) { |
55 | 0 | auto msg = fmt::format( |
56 | 0 | "adjust vlog of {} from {} to {} succeed", std::get<0>(handle_result.value()), |
57 | 0 | std::get<1>(handle_result.value()), std::get<2>(handle_result.value())); |
58 | 0 | LOG(INFO) << msg; |
59 | 0 | HttpChannel::send_reply(req, msg); |
60 | 0 | } else { |
61 | 0 | LOG(WARNING) << "adjust log level failed, error: " << handle_result.error(); |
62 | 0 | HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, |
63 | 0 | handle_result.error().to_string_no_stack()); |
64 | 0 | return; |
65 | 0 | } |
66 | 0 | } catch (const std::exception& e) { |
67 | | LOG(WARNING) << "adjust log level failed, error: " << e.what(); |
68 | 0 | HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, e.what()); |
69 | 0 | return; |
70 | 0 | } |
71 | 0 | } |
72 | | } // namespace doris |