Skip to content

Commit eca60bd

Browse files
committed
fix health checker plugin config parse
1 parent df4b545 commit eca60bd

File tree

4 files changed

+42
-41
lines changed

4 files changed

+42
-41
lines changed

polaris/plugin/health_checker/health_checker.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ static const char kChainPluginListDefault[] = "tcp";
3939
static const char kCheckerIntervalKey[] = "interval";
4040
static const uint64_t kDetectorIntervalDefault = 10 * 1000; // 探活默认时间间隔10s
4141

42-
static const char kHttpRequestPathKey[] = "path";
43-
static const char kHttpRequestPathDefault[] = "";
44-
45-
static const char kTcpSendPackageKey[] = "send";
46-
static const char kTcpSendPackageDefault[] = "";
47-
static const char kTcpReceivePackageKey[] = "receive";
48-
static const char kTcpReceivePackageDefault[] = "";
49-
50-
static const char kUdpSendPackageKey[] = "send";
51-
static const char kUdpSendPackageDefault[] = "";
52-
static const char kUdpReceivePackageKey[] = "receive";
53-
static const char kUdpReceivePackageDefault[] = "";
54-
5542
static const char kTimeoutKey[] = "timeout"; // 超时时间毫秒
5643
static const uint64_t kTimeoutDefault = 500; // 默认500ms
5744
} // namespace HealthCheckerConfig

polaris/plugin/health_checker/http_detector.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ HttpHealthChecker::HttpHealthChecker() { timeout_ms_ = 0; }
3131
HttpHealthChecker::~HttpHealthChecker() {}
3232

3333
ReturnCode HttpHealthChecker::Init(Config* config, Context* /*context*/) {
34-
request_path_ = config->GetStringOrDefault(HealthCheckerConfig::kHttpRequestPathKey,
35-
HealthCheckerConfig::kHttpRequestPathDefault);
34+
static const char kHttpRequestPathKey[] = "path";
35+
static const char kHttpRequestPathDefault[] = "";
36+
37+
request_path_ = config->GetStringOrDefault(kHttpRequestPathKey, kHttpRequestPathDefault);
3638
if (request_path_.empty() || request_path_[0] != '/') {
37-
POLARIS_LOG(LOG_ERROR, "health checker[%s] config %s invalid", kPluginHttpHealthChecker,
38-
HealthCheckerConfig::kHttpRequestPathKey);
39+
POLARIS_LOG(LOG_ERROR, "outlier detector[%s] config %s invalid", kPluginHttpHealthChecker,
40+
kHttpRequestPathKey);
3941
return kReturnInvalidConfig;
4042
}
41-
timeout_ms_ = config->GetIntOrDefault(HealthCheckerConfig::kTimeoutKey,
42-
HealthCheckerConfig::kTimeoutDefault);
43+
timeout_ms_ = config->GetMsOrDefault(HealthCheckerConfig::kTimeoutKey,
44+
HealthCheckerConfig::kTimeoutDefault);
45+
4346
return kReturnOk;
4447
}
4548

polaris/plugin/health_checker/tcp_detector.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,27 @@ TcpHealthChecker::TcpHealthChecker() { timeout_ms_ = 0; }
2929
TcpHealthChecker::~TcpHealthChecker() {}
3030

3131
ReturnCode TcpHealthChecker::Init(Config* config, Context* /*context*/) {
32-
std::string send_package = config->GetStringOrDefault(
33-
HealthCheckerConfig::kTcpSendPackageKey, HealthCheckerConfig::kTcpSendPackageDefault);
32+
static const char kTcpSendPackageKey[] = "send";
33+
static const char kTcpSendPackageDefault[] = "";
34+
static const char kTcpReceivePackageKey[] = "receive";
35+
static const char kTcpReceivePackageDefault[] = "";
36+
37+
std::string send_package = config->GetStringOrDefault(kTcpSendPackageKey, kTcpSendPackageDefault);
3438
if (!send_package.empty() && !Utils::HexStringToBytes(send_package, &send_package_)) {
35-
POLARIS_LOG(LOG_ERROR, "health checker[%s] config %s hexstring to bytes failed",
36-
kPluginTcpHealthChecker, HealthCheckerConfig::kTcpSendPackageKey);
39+
POLARIS_LOG(LOG_ERROR, "outlier detector[%s] config %s hexstring to bytes failed",
40+
kPluginTcpHealthChecker, kTcpSendPackageKey);
3741
return kReturnInvalidConfig;
3842
}
39-
std::string receive_package = config->GetStringOrDefault(
40-
HealthCheckerConfig::kTcpReceivePackageKey, HealthCheckerConfig::kTcpReceivePackageDefault);
43+
std::string receive_package =
44+
config->GetStringOrDefault(kTcpReceivePackageKey, kTcpReceivePackageDefault);
4145
if (!receive_package.empty() && !Utils::HexStringToBytes(receive_package, &receive_package_)) {
42-
POLARIS_LOG(LOG_ERROR, "health checker[%s] config %s hexstring to bytes failed",
43-
kPluginTcpHealthChecker, HealthCheckerConfig::kTcpReceivePackageKey);
46+
POLARIS_LOG(LOG_ERROR, "outlier detector[%s] config %s hexstring to bytes failed",
47+
kPluginTcpHealthChecker, kTcpReceivePackageKey);
4448
return kReturnInvalidConfig;
4549
}
46-
timeout_ms_ = config->GetIntOrDefault(HealthCheckerConfig::kTimeoutKey,
47-
HealthCheckerConfig::kTimeoutDefault);
50+
51+
timeout_ms_ = config->GetMsOrDefault(HealthCheckerConfig::kTimeoutKey,
52+
HealthCheckerConfig::kTimeoutDefault);
4853
return kReturnOk;
4954
}
5055

polaris/plugin/health_checker/udp_detector.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,33 @@ UdpHealthChecker::UdpHealthChecker() { timeout_ms_ = 0; }
3131
UdpHealthChecker::~UdpHealthChecker() {}
3232

3333
ReturnCode UdpHealthChecker::Init(Config* config, Context* /*context*/) {
34-
std::string send_package = config->GetStringOrDefault(
35-
HealthCheckerConfig::kUdpSendPackageKey, HealthCheckerConfig::kUdpSendPackageDefault);
34+
static const char kUdpSendPackageKey[] = "send";
35+
static const char kUdpSendPackageDefault[] = "";
36+
static const char kUdpReceivePackageKey[] = "receive";
37+
static const char kUdpReceivePackageDefault[] = "";
38+
39+
std::string send_package = config->GetStringOrDefault(kUdpSendPackageKey, kUdpSendPackageDefault);
3640
if (send_package.empty()) {
37-
POLARIS_LOG(LOG_ERROR, "health checker[%s] config %s should not be empty",
38-
kPluginUdpHealthChecker, HealthCheckerConfig::kUdpSendPackageKey);
41+
POLARIS_LOG(LOG_ERROR, "outlier detector[%s] config %s should not be empty",
42+
kPluginUdpHealthChecker, kUdpSendPackageKey);
3943
return kReturnInvalidConfig;
4044
}
4145
if (!Utils::HexStringToBytes(send_package, &send_package_)) {
42-
POLARIS_LOG(LOG_ERROR, "health checker[%s] config %s hexstring to bytes failed",
43-
kPluginUdpHealthChecker, HealthCheckerConfig::kUdpSendPackageKey);
46+
POLARIS_LOG(LOG_ERROR, "outlier detector[%s] config %s hexstring to bytes failed",
47+
kPluginUdpHealthChecker, kUdpSendPackageKey);
48+
return kReturnInvalidConfig;
4449
}
45-
std::string receive_package = config->GetStringOrDefault(
46-
HealthCheckerConfig::kUdpReceivePackageKey, HealthCheckerConfig::kUdpReceivePackageDefault);
50+
std::string receive_package =
51+
config->GetStringOrDefault(kUdpReceivePackageKey, kUdpReceivePackageDefault);
4752
if (!receive_package.empty()) {
4853
if (!Utils::HexStringToBytes(receive_package, &receive_package_)) {
49-
POLARIS_LOG(LOG_ERROR, "health checker[%s] config %s hexstring to bytes failed",
50-
kPluginUdpHealthChecker, HealthCheckerConfig::kUdpReceivePackageKey);
54+
POLARIS_LOG(LOG_ERROR, "outlier detector[%s] config %s hexstring to bytes failed",
55+
kPluginUdpHealthChecker, kUdpReceivePackageKey);
56+
return kReturnInvalidConfig;
5157
}
5258
}
53-
timeout_ms_ = config->GetIntOrDefault(HealthCheckerConfig::kTimeoutKey,
54-
HealthCheckerConfig::kTimeoutDefault);
59+
timeout_ms_ = config->GetMsOrDefault(HealthCheckerConfig ::kTimeoutKey,
60+
HealthCheckerConfig::kTimeoutDefault);
5561
return kReturnOk;
5662
}
5763

0 commit comments

Comments
 (0)