Coverage Report

Created: 2026-03-15 01:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/service/http/action/debug_point_action.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/debug_point_action.h"
19
20
#include "common/config.h"
21
#include "service/http/http_channel.h"
22
#include "service/http/http_status.h"
23
#include "util/debug_points.h"
24
#include "util/time.h"
25
26
namespace doris {
27
28
8
void BaseDebugPointAction::handle(HttpRequest* req) {
29
8
    LOG(INFO) << "accept one request " << req->debug_string();
30
8
    Status status;
31
8
    if (config::enable_debug_points) {
32
8
        status = _handle(req);
33
8
    } else {
34
0
        status = Status::InternalError(
35
0
                "Disable debug points. please check config::enable_debug_points");
36
0
    }
37
8
    std::string result = status.to_json();
38
8
    if (status.ok()) {
39
8
        HttpChannel::send_reply(req, HttpStatus::OK, result);
40
8
    } else {
41
0
        HttpChannel::send_reply(req, HttpStatus::INTERNAL_SERVER_ERROR, result);
42
0
    }
43
8
}
44
45
6
Status AddDebugPointAction::_handle(HttpRequest* req) {
46
6
    std::string name = req->param("debug_point");
47
6
    std::string execute = req->param("execute");
48
6
    std::string timeout = req->param("timeout");
49
6
    if (name.empty()) {
50
0
        return Status::InternalError("Empty debug point name");
51
0
    }
52
6
    auto debug_point = std::make_shared<DebugPoint>();
53
6
    try {
54
6
        if (!execute.empty()) {
55
1
            debug_point->execute_limit = std::stol(execute);
56
1
        }
57
6
    } catch (const std::exception& e) {
58
0
        return Status::InternalError("Invalid execute limit format, execute {}, err {}", execute,
59
0
                                     e.what());
60
0
    }
61
6
    try {
62
6
        if (!timeout.empty()) {
63
1
            int64_t timeout_second = std::stol(timeout);
64
1
            if (timeout_second > 0) {
65
1
                debug_point->expire_ms = MonotonicMillis() + timeout_second * MILLIS_PER_SEC;
66
1
            }
67
1
        }
68
6
    } catch (const std::exception& e) {
69
0
        return Status::InternalError("Invalid timeout format, timeout {}, err {}", timeout,
70
0
                                     e.what());
71
0
    }
72
73
6
    debug_point->params = *(req->params());
74
75
6
    DebugPoints::instance()->add(name, debug_point);
76
77
6
    return Status::OK();
78
6
}
79
80
1
Status RemoveDebugPointAction::_handle(HttpRequest* req) {
81
1
    std::string debug_point = req->param("debug_point");
82
1
    if (debug_point.empty()) {
83
0
        return Status::InternalError("Empty debug point name");
84
0
    }
85
86
1
    DebugPoints::instance()->remove(debug_point);
87
88
1
    return Status::OK();
89
1
}
90
91
1
Status ClearDebugPointsAction::_handle(HttpRequest* req) {
92
1
    DebugPoints::instance()->clear();
93
94
1
    return Status::OK();
95
1
}
96
97
} // namespace doris