Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions polaris/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,8 @@ ReturnCode ContextImpl::InitGlobalConfig(Config* config, Context* context) {
}

// Init stat reporter
plugin_config.Reset(config->GetSubConfig("statReporter"));
delete plugin_config.Release();
plugin_config.Set(config->GetSubConfig("statReporter"));
plugin = NULL;
std::string plugin_name = plugin_config->GetStringOrDefault("name", kPluginDefaultStatReporter);
PluginManager::Instance().GetPlugin(plugin_name, kPluginStatReporter, plugin);
Expand All @@ -622,7 +623,8 @@ ReturnCode ContextImpl::InitGlobalConfig(Config* config, Context* context) {
}

// Init alert reporter
plugin_config.Reset(config->GetSubConfig("alertReporter"));
delete plugin_config.Release();
plugin_config.Set(config->GetSubConfig("alertReporter"));
plugin = NULL;
plugin_name = plugin_config->GetStringOrDefault("name", kPluginDefaultAlertReporter);
PluginManager::Instance().GetPlugin(plugin_name, kPluginAlertReporter, plugin);
Expand All @@ -639,7 +641,8 @@ ReturnCode ContextImpl::InitGlobalConfig(Config* config, Context* context) {
}

// Init server metric
plugin_config.Reset(config->GetSubConfig("serverMetric"));
delete plugin_config.Release();
plugin_config.Set(config->GetSubConfig("serverMetric"));
plugin = NULL;
plugin_name = plugin_config->GetStringOrDefault("name", "");
if (!plugin_name.empty()) {
Expand Down
13 changes: 0 additions & 13 deletions polaris/plugin/health_checker/health_checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@ static const char kChainPluginListDefault[] = "tcp";
static const char kCheckerIntervalKey[] = "interval";
static const uint64_t kDetectorIntervalDefault = 10 * 1000; // 探活默认时间间隔10s

static const char kHttpRequestPathKey[] = "path";
static const char kHttpRequestPathDefault[] = "";

static const char kTcpSendPackageKey[] = "send";
static const char kTcpSendPackageDefault[] = "";
static const char kTcpReceivePackageKey[] = "receive";
static const char kTcpReceivePackageDefault[] = "";

static const char kUdpSendPackageKey[] = "send";
static const char kUdpSendPackageDefault[] = "";
static const char kUdpReceivePackageKey[] = "receive";
static const char kUdpReceivePackageDefault[] = "";

static const char kTimeoutKey[] = "timeout"; // 超时时间毫秒
static const uint64_t kTimeoutDefault = 500; // 默认500ms
} // namespace HealthCheckerConfig
Expand Down
15 changes: 9 additions & 6 deletions polaris/plugin/health_checker/http_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ HttpHealthChecker::HttpHealthChecker() { timeout_ms_ = 0; }
HttpHealthChecker::~HttpHealthChecker() {}

ReturnCode HttpHealthChecker::Init(Config* config, Context* /*context*/) {
request_path_ = config->GetStringOrDefault(HealthCheckerConfig::kHttpRequestPathKey,
HealthCheckerConfig::kHttpRequestPathDefault);
static const char kHttpRequestPathKey[] = "path";
static const char kHttpRequestPathDefault[] = "";

request_path_ = config->GetStringOrDefault(kHttpRequestPathKey, kHttpRequestPathDefault);
if (request_path_.empty() || request_path_[0] != '/') {
POLARIS_LOG(LOG_ERROR, "health checker[%s] config %s invalid", kPluginHttpHealthChecker,
HealthCheckerConfig::kHttpRequestPathKey);
POLARIS_LOG(LOG_ERROR, "outlier detector[%s] config %s invalid", kPluginHttpHealthChecker,
kHttpRequestPathKey);
return kReturnInvalidConfig;
}
timeout_ms_ = config->GetIntOrDefault(HealthCheckerConfig::kTimeoutKey,
HealthCheckerConfig::kTimeoutDefault);
timeout_ms_ = config->GetMsOrDefault(HealthCheckerConfig::kTimeoutKey,
HealthCheckerConfig::kTimeoutDefault);

return kReturnOk;
}

Expand Down
25 changes: 15 additions & 10 deletions polaris/plugin/health_checker/tcp_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,27 @@ TcpHealthChecker::TcpHealthChecker() { timeout_ms_ = 0; }
TcpHealthChecker::~TcpHealthChecker() {}

ReturnCode TcpHealthChecker::Init(Config* config, Context* /*context*/) {
std::string send_package = config->GetStringOrDefault(
HealthCheckerConfig::kTcpSendPackageKey, HealthCheckerConfig::kTcpSendPackageDefault);
static const char kTcpSendPackageKey[] = "send";
static const char kTcpSendPackageDefault[] = "";
static const char kTcpReceivePackageKey[] = "receive";
static const char kTcpReceivePackageDefault[] = "";

std::string send_package = config->GetStringOrDefault(kTcpSendPackageKey, kTcpSendPackageDefault);
if (!send_package.empty() && !Utils::HexStringToBytes(send_package, &send_package_)) {
POLARIS_LOG(LOG_ERROR, "health checker[%s] config %s hexstring to bytes failed",
kPluginTcpHealthChecker, HealthCheckerConfig::kTcpSendPackageKey);
POLARIS_LOG(LOG_ERROR, "outlier detector[%s] config %s hexstring to bytes failed",
kPluginTcpHealthChecker, kTcpSendPackageKey);
return kReturnInvalidConfig;
}
std::string receive_package = config->GetStringOrDefault(
HealthCheckerConfig::kTcpReceivePackageKey, HealthCheckerConfig::kTcpReceivePackageDefault);
std::string receive_package =
config->GetStringOrDefault(kTcpReceivePackageKey, kTcpReceivePackageDefault);
if (!receive_package.empty() && !Utils::HexStringToBytes(receive_package, &receive_package_)) {
POLARIS_LOG(LOG_ERROR, "health checker[%s] config %s hexstring to bytes failed",
kPluginTcpHealthChecker, HealthCheckerConfig::kTcpReceivePackageKey);
POLARIS_LOG(LOG_ERROR, "outlier detector[%s] config %s hexstring to bytes failed",
kPluginTcpHealthChecker, kTcpReceivePackageKey);
return kReturnInvalidConfig;
}
timeout_ms_ = config->GetIntOrDefault(HealthCheckerConfig::kTimeoutKey,
HealthCheckerConfig::kTimeoutDefault);

timeout_ms_ = config->GetMsOrDefault(HealthCheckerConfig::kTimeoutKey,
HealthCheckerConfig::kTimeoutDefault);
return kReturnOk;
}

Expand Down
30 changes: 18 additions & 12 deletions polaris/plugin/health_checker/udp_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,33 @@ UdpHealthChecker::UdpHealthChecker() { timeout_ms_ = 0; }
UdpHealthChecker::~UdpHealthChecker() {}

ReturnCode UdpHealthChecker::Init(Config* config, Context* /*context*/) {
std::string send_package = config->GetStringOrDefault(
HealthCheckerConfig::kUdpSendPackageKey, HealthCheckerConfig::kUdpSendPackageDefault);
static const char kUdpSendPackageKey[] = "send";
static const char kUdpSendPackageDefault[] = "";
static const char kUdpReceivePackageKey[] = "receive";
static const char kUdpReceivePackageDefault[] = "";

std::string send_package = config->GetStringOrDefault(kUdpSendPackageKey, kUdpSendPackageDefault);
if (send_package.empty()) {
POLARIS_LOG(LOG_ERROR, "health checker[%s] config %s should not be empty",
kPluginUdpHealthChecker, HealthCheckerConfig::kUdpSendPackageKey);
POLARIS_LOG(LOG_ERROR, "outlier detector[%s] config %s should not be empty",
kPluginUdpHealthChecker, kUdpSendPackageKey);
return kReturnInvalidConfig;
}
if (!Utils::HexStringToBytes(send_package, &send_package_)) {
POLARIS_LOG(LOG_ERROR, "health checker[%s] config %s hexstring to bytes failed",
kPluginUdpHealthChecker, HealthCheckerConfig::kUdpSendPackageKey);
POLARIS_LOG(LOG_ERROR, "outlier detector[%s] config %s hexstring to bytes failed",
kPluginUdpHealthChecker, kUdpSendPackageKey);
return kReturnInvalidConfig;
}
std::string receive_package = config->GetStringOrDefault(
HealthCheckerConfig::kUdpReceivePackageKey, HealthCheckerConfig::kUdpReceivePackageDefault);
std::string receive_package =
config->GetStringOrDefault(kUdpReceivePackageKey, kUdpReceivePackageDefault);
if (!receive_package.empty()) {
if (!Utils::HexStringToBytes(receive_package, &receive_package_)) {
POLARIS_LOG(LOG_ERROR, "health checker[%s] config %s hexstring to bytes failed",
kPluginUdpHealthChecker, HealthCheckerConfig::kUdpReceivePackageKey);
POLARIS_LOG(LOG_ERROR, "outlier detector[%s] config %s hexstring to bytes failed",
kPluginUdpHealthChecker, kUdpReceivePackageKey);
return kReturnInvalidConfig;
}
}
timeout_ms_ = config->GetIntOrDefault(HealthCheckerConfig::kTimeoutKey,
HealthCheckerConfig::kTimeoutDefault);
timeout_ms_ = config->GetMsOrDefault(HealthCheckerConfig ::kTimeoutKey,
HealthCheckerConfig::kTimeoutDefault);
return kReturnOk;
}

Expand Down