@@ -31,14 +31,6 @@ namespace brpc {
3131// Declared at socket.cpp
3232extern SocketVarsCollector* g_vars;
3333
34- DEFINE_string (health_check_path, " " , " Http path of health check call."
35- " By default health check succeeds if the server is connectable."
36- " If this flag is set, health check is not completed until a http "
37- " call to the path succeeds within -health_check_timeout_ms(to make "
38- " sure the server functions well)." );
39- DEFINE_int32 (health_check_timeout_ms, 500 , " The timeout for both establishing "
40- " the connection and the http call to -health_check_path over the connection" );
41-
4234class HealthCheckChannel : public brpc ::Channel {
4335public:
4436 HealthCheckChannel () {}
@@ -65,6 +57,7 @@ class OnAppHealthCheckDone : public google::protobuf::Closure {
6557 SocketId id;
6658 int64_t interval_s;
6759 int64_t last_check_time_ms;
60+ HealthCheckOption hc_option;
6861};
6962
7063class HealthCheckManager {
@@ -81,15 +74,16 @@ void HealthCheckManager::StartCheck(SocketId id, int64_t check_interval_s) {
8174 << " was abandoned during health checking" ;
8275 return ;
8376 }
84- LOG (INFO) << " Checking path=" << ptr->remote_side () << FLAGS_health_check_path ;
77+ LOG (INFO) << " Checking path=" << ptr->remote_side () << ptr-> health_check_path () ;
8578 OnAppHealthCheckDone* done = new OnAppHealthCheckDone;
8679 done->id = id;
8780 done->interval_s = check_interval_s;
81+ done->hc_option = ptr->_hc_option ;
8882 brpc::ChannelOptions options;
8983 options.protocol = PROTOCOL_HTTP;
9084 options.max_retry = 0 ;
9185 options.timeout_ms =
92- std::min ((int64_t )FLAGS_health_check_timeout_ms , check_interval_s * 1000 );
86+ std::min ((int64_t )(done-> hc_option . health_check_timeout_ms ) , check_interval_s * 1000 );
9387 if (done->channel .Init (id, &options) != 0 ) {
9488 LOG (WARNING) << " Fail to init health check channel to SocketId=" << id;
9589 ptr->_ninflight_app_health_check .fetch_sub (
@@ -103,7 +97,7 @@ void HealthCheckManager::StartCheck(SocketId id, int64_t check_interval_s) {
10397void * HealthCheckManager::AppCheck (void * arg) {
10498 OnAppHealthCheckDone* done = static_cast <OnAppHealthCheckDone*>(arg);
10599 done->cntl .Reset ();
106- done->cntl .http_request ().uri () = FLAGS_health_check_path ;
100+ done->cntl .http_request ().uri () = done-> hc_option . health_check_path ;
107101 ControllerPrivateAccessor (&done->cntl ).set_health_check_call ();
108102 done->last_check_time_ms = butil::gettimeofday_ms ();
109103 done->channel .CallMethod (NULL , &done->cntl , NULL , NULL , done);
@@ -121,14 +115,14 @@ void OnAppHealthCheckDone::Run() {
121115 }
122116 if (!cntl.Failed () || ptr->Failed ()) {
123117 LOG_IF (INFO, !cntl.Failed ()) << " Succeeded to call "
124- << ptr->remote_side () << FLAGS_health_check_path ;
118+ << ptr->remote_side () << hc_option. health_check_path ;
125119 // if ptr->Failed(), previous SetFailed would trigger next round
126120 // of hc, just return here.
127121 ptr->_ninflight_app_health_check .fetch_sub (
128122 1 , butil::memory_order_relaxed);
129123 return ;
130124 }
131- RPC_VLOG << " Fail to check path=" << FLAGS_health_check_path
125+ RPC_VLOG << " Fail to check path=" << hc_option. health_check_path
132126 << " , " << cntl.ErrorText ();
133127
134128 int64_t sleep_time_ms =
@@ -206,14 +200,14 @@ bool HealthCheckTask::OnTriggeringTask(timespec* next_abstime) {
206200 hc = ptr->CheckHealth ();
207201 }
208202 if (hc == 0 ) {
209- if (!FLAGS_health_check_path .empty ()) {
203+ if (!ptr-> health_check_path () .empty ()) {
210204 ptr->_ninflight_app_health_check .fetch_add (
211205 1 , butil::memory_order_relaxed);
212206 }
213207 // See comments above.
214208 ptr->Revive (2 /* note*/ );
215209 ptr->_hc_count = 0 ;
216- if (!FLAGS_health_check_path .empty ()) {
210+ if (!ptr-> health_check_path () .empty ()) {
217211 HealthCheckManager::StartCheck (_id, ptr->_health_check_interval_s );
218212 }
219213 ptr->AfterHCCompleted ();
0 commit comments