Coverage Report

Created: 2026-03-14 13:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/service/http/action/health_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/health_action.h"
19
20
#include <sstream>
21
#include <string>
22
23
#include "runtime/exec_env.h"
24
#include "service/http/http_channel.h"
25
#include "service/http/http_headers.h"
26
#include "service/http/http_request.h"
27
#include "service/http/http_status.h"
28
29
namespace doris {
30
31
const static std::string HEADER_JSON = "application/json";
32
33
2
void HealthAction::handle(HttpRequest* req) {
34
2
    std::string status;
35
2
    std::string msg;
36
2
    HttpStatus st;
37
    // always return HttpStatus::OK
38
    // because in k8s, we don't want the pod to be removed
39
    // from service during shutdown
40
2
    if (!doris::k_is_server_ready) {
41
2
        status = "Server is not available";
42
2
        msg = "Server is not ready";
43
2
        st = HttpStatus::OK;
44
2
    } else if (doris::k_doris_exit) {
45
0
        status = "Server is not available";
46
0
        msg = "Server is shutting down";
47
0
        st = HttpStatus::OK;
48
0
    } else {
49
0
        status = "OK";
50
0
        msg = "OK";
51
0
        st = HttpStatus::OK;
52
0
    }
53
54
2
    std::stringstream ss;
55
2
    ss << "{";
56
2
    ss << "\"status\": \"" << status << "\",";
57
2
    ss << "\"msg\": \"" << msg << "\"";
58
2
    ss << "}";
59
2
    std::string result = ss.str();
60
61
2
    req->add_output_header(HttpHeaders::CONTENT_TYPE, HEADER_JSON.c_str());
62
2
    HttpChannel::send_reply(req, st, result);
63
2
}
64
65
} // end namespace doris