|
|
@ -32,6 +32,7 @@ |
|
|
|
#include "absl/status/status.h" |
|
|
|
#include "absl/status/status.h" |
|
|
|
#include "absl/status/statusor.h" |
|
|
|
#include "absl/status/statusor.h" |
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
#include "absl/strings/str_cat.h" |
|
|
|
|
|
|
|
#include "absl/strings/str_join.h" |
|
|
|
#include "absl/strings/string_view.h" |
|
|
|
#include "absl/strings/string_view.h" |
|
|
|
#include "absl/types/optional.h" |
|
|
|
#include "absl/types/optional.h" |
|
|
|
#include "absl/types/variant.h" |
|
|
|
#include "absl/types/variant.h" |
|
|
@ -137,7 +138,7 @@ CircuitBreakerCallCounterMap::CallCounter::~CallCounter() { |
|
|
|
// LB policy
|
|
|
|
// LB policy
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
constexpr char kXdsClusterImpl[] = "xds_cluster_impl_experimental"; |
|
|
|
constexpr absl::string_view kXdsClusterImpl = "xds_cluster_impl_experimental"; |
|
|
|
|
|
|
|
|
|
|
|
// Config for xDS Cluster Impl LB policy.
|
|
|
|
// Config for xDS Cluster Impl LB policy.
|
|
|
|
class XdsClusterImplLbConfig : public LoadBalancingPolicy::Config { |
|
|
|
class XdsClusterImplLbConfig : public LoadBalancingPolicy::Config { |
|
|
@ -155,7 +156,7 @@ class XdsClusterImplLbConfig : public LoadBalancingPolicy::Config { |
|
|
|
max_concurrent_requests_(max_concurrent_requests), |
|
|
|
max_concurrent_requests_(max_concurrent_requests), |
|
|
|
drop_config_(std::move(drop_config)) {} |
|
|
|
drop_config_(std::move(drop_config)) {} |
|
|
|
|
|
|
|
|
|
|
|
const char* name() const override { return kXdsClusterImpl; } |
|
|
|
absl::string_view name() const override { return kXdsClusterImpl; } |
|
|
|
|
|
|
|
|
|
|
|
RefCountedPtr<LoadBalancingPolicy::Config> child_policy() const { |
|
|
|
RefCountedPtr<LoadBalancingPolicy::Config> child_policy() const { |
|
|
|
return child_policy_; |
|
|
|
return child_policy_; |
|
|
@ -185,7 +186,7 @@ class XdsClusterImplLb : public LoadBalancingPolicy { |
|
|
|
public: |
|
|
|
public: |
|
|
|
XdsClusterImplLb(RefCountedPtr<XdsClient> xds_client, Args args); |
|
|
|
XdsClusterImplLb(RefCountedPtr<XdsClient> xds_client, Args args); |
|
|
|
|
|
|
|
|
|
|
|
const char* name() const override { return kXdsClusterImpl; } |
|
|
|
absl::string_view name() const override { return kXdsClusterImpl; } |
|
|
|
|
|
|
|
|
|
|
|
void UpdateLocked(UpdateArgs args) override; |
|
|
|
void UpdateLocked(UpdateArgs args) override; |
|
|
|
void ExitIdleLocked() override; |
|
|
|
void ExitIdleLocked() override; |
|
|
@ -703,48 +704,41 @@ class XdsClusterImplLbFactory : public LoadBalancingPolicyFactory { |
|
|
|
std::move(args)); |
|
|
|
std::move(args)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const char* name() const override { return kXdsClusterImpl; } |
|
|
|
absl::string_view name() const override { return kXdsClusterImpl; } |
|
|
|
|
|
|
|
|
|
|
|
RefCountedPtr<LoadBalancingPolicy::Config> ParseLoadBalancingConfig( |
|
|
|
absl::StatusOr<RefCountedPtr<LoadBalancingPolicy::Config>> |
|
|
|
const Json& json, grpc_error_handle* error) const override { |
|
|
|
ParseLoadBalancingConfig(const Json& json) const override { |
|
|
|
GPR_DEBUG_ASSERT(error != nullptr && GRPC_ERROR_IS_NONE(*error)); |
|
|
|
|
|
|
|
if (json.type() == Json::Type::JSON_NULL) { |
|
|
|
if (json.type() == Json::Type::JSON_NULL) { |
|
|
|
// This policy was configured in the deprecated loadBalancingPolicy
|
|
|
|
// This policy was configured in the deprecated loadBalancingPolicy
|
|
|
|
// field or in the client API.
|
|
|
|
// field or in the client API.
|
|
|
|
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
return absl::InvalidArgumentError( |
|
|
|
"field:loadBalancingPolicy error:xds_cluster_impl policy requires " |
|
|
|
"field:loadBalancingPolicy error:xds_cluster_impl policy requires " |
|
|
|
"configuration. Please use loadBalancingConfig field of service " |
|
|
|
"configuration. Please use loadBalancingConfig field of service " |
|
|
|
"config instead."); |
|
|
|
"config instead."); |
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
std::vector<grpc_error_handle> error_list; |
|
|
|
std::vector<std::string> errors; |
|
|
|
// Child policy.
|
|
|
|
// Child policy.
|
|
|
|
RefCountedPtr<LoadBalancingPolicy::Config> child_policy; |
|
|
|
RefCountedPtr<LoadBalancingPolicy::Config> child_policy; |
|
|
|
auto it = json.object_value().find("childPolicy"); |
|
|
|
auto it = json.object_value().find("childPolicy"); |
|
|
|
if (it == json.object_value().end()) { |
|
|
|
if (it == json.object_value().end()) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
errors.emplace_back("field:childPolicy error:required field missing"); |
|
|
|
"field:childPolicy error:required field missing")); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
grpc_error_handle parse_error = GRPC_ERROR_NONE; |
|
|
|
auto config = |
|
|
|
child_policy = LoadBalancingPolicyRegistry::ParseLoadBalancingConfig( |
|
|
|
LoadBalancingPolicyRegistry::ParseLoadBalancingConfig(it->second); |
|
|
|
it->second, &parse_error); |
|
|
|
if (!config.ok()) { |
|
|
|
if (child_policy == nullptr) { |
|
|
|
errors.emplace_back(absl::StrCat("field:childPolicy error:", |
|
|
|
GPR_DEBUG_ASSERT(!GRPC_ERROR_IS_NONE(parse_error)); |
|
|
|
config.status().message())); |
|
|
|
std::vector<grpc_error_handle> child_errors; |
|
|
|
} else { |
|
|
|
child_errors.push_back(parse_error); |
|
|
|
child_policy = std::move(*config); |
|
|
|
error_list.push_back( |
|
|
|
|
|
|
|
GRPC_ERROR_CREATE_FROM_VECTOR("field:childPolicy", &child_errors)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Cluster name.
|
|
|
|
// Cluster name.
|
|
|
|
std::string cluster_name; |
|
|
|
std::string cluster_name; |
|
|
|
it = json.object_value().find("clusterName"); |
|
|
|
it = json.object_value().find("clusterName"); |
|
|
|
if (it == json.object_value().end()) { |
|
|
|
if (it == json.object_value().end()) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
errors.emplace_back("field:clusterName error:required field missing"); |
|
|
|
"field:clusterName error:required field missing")); |
|
|
|
|
|
|
|
} else if (it->second.type() != Json::Type::STRING) { |
|
|
|
} else if (it->second.type() != Json::Type::STRING) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
errors.emplace_back("field:clusterName error:type should be string"); |
|
|
|
"field:clusterName error:type should be string")); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
cluster_name = it->second.string_value(); |
|
|
|
cluster_name = it->second.string_value(); |
|
|
|
} |
|
|
|
} |
|
|
@ -753,8 +747,7 @@ class XdsClusterImplLbFactory : public LoadBalancingPolicyFactory { |
|
|
|
it = json.object_value().find("edsServiceName"); |
|
|
|
it = json.object_value().find("edsServiceName"); |
|
|
|
if (it != json.object_value().end()) { |
|
|
|
if (it != json.object_value().end()) { |
|
|
|
if (it->second.type() != Json::Type::STRING) { |
|
|
|
if (it->second.type() != Json::Type::STRING) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
errors.emplace_back("field:edsServiceName error:type should be string"); |
|
|
|
"field:edsServiceName error:type should be string")); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
eds_service_name = it->second.string_value(); |
|
|
|
eds_service_name = it->second.string_value(); |
|
|
|
} |
|
|
|
} |
|
|
@ -764,16 +757,17 @@ class XdsClusterImplLbFactory : public LoadBalancingPolicyFactory { |
|
|
|
it = json.object_value().find("lrsLoadReportingServer"); |
|
|
|
it = json.object_value().find("lrsLoadReportingServer"); |
|
|
|
if (it != json.object_value().end()) { |
|
|
|
if (it != json.object_value().end()) { |
|
|
|
if (it->second.type() != Json::Type::OBJECT) { |
|
|
|
if (it->second.type() != Json::Type::OBJECT) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
errors.emplace_back( |
|
|
|
"field:lrsLoadReportingServer error:type should be object")); |
|
|
|
"field:lrsLoadReportingServer error:type should be object"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
grpc_error_handle parser_error; |
|
|
|
grpc_error_handle parser_error; |
|
|
|
lrs_load_reporting_server = XdsBootstrap::XdsServer::Parse( |
|
|
|
lrs_load_reporting_server = XdsBootstrap::XdsServer::Parse( |
|
|
|
it->second.object_value(), &parser_error); |
|
|
|
it->second.object_value(), &parser_error); |
|
|
|
if (!GRPC_ERROR_IS_NONE(parser_error)) { |
|
|
|
if (!GRPC_ERROR_IS_NONE(parser_error)) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_CPP_STRING( |
|
|
|
errors.emplace_back( |
|
|
|
absl::StrCat("errors parsing lrs_load_reporting_server"))); |
|
|
|
absl::StrCat("error parsing lrs_load_reporting_server: ", |
|
|
|
error_list.push_back(parser_error); |
|
|
|
grpc_error_std_string(parser_error))); |
|
|
|
|
|
|
|
GRPC_ERROR_UNREF(parser_error); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -782,8 +776,8 @@ class XdsClusterImplLbFactory : public LoadBalancingPolicyFactory { |
|
|
|
it = json.object_value().find("maxConcurrentRequests"); |
|
|
|
it = json.object_value().find("maxConcurrentRequests"); |
|
|
|
if (it != json.object_value().end()) { |
|
|
|
if (it != json.object_value().end()) { |
|
|
|
if (it->second.type() != Json::Type::NUMBER) { |
|
|
|
if (it->second.type() != Json::Type::NUMBER) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
errors.emplace_back( |
|
|
|
"field:max_concurrent_requests error:must be of type number")); |
|
|
|
"field:max_concurrent_requests error:must be of type number"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
max_concurrent_requests = |
|
|
|
max_concurrent_requests = |
|
|
|
gpr_parse_nonnegative_int(it->second.string_value().c_str()); |
|
|
|
gpr_parse_nonnegative_int(it->second.string_value().c_str()); |
|
|
@ -793,20 +787,15 @@ class XdsClusterImplLbFactory : public LoadBalancingPolicyFactory { |
|
|
|
auto drop_config = MakeRefCounted<XdsEndpointResource::DropConfig>(); |
|
|
|
auto drop_config = MakeRefCounted<XdsEndpointResource::DropConfig>(); |
|
|
|
it = json.object_value().find("dropCategories"); |
|
|
|
it = json.object_value().find("dropCategories"); |
|
|
|
if (it == json.object_value().end()) { |
|
|
|
if (it == json.object_value().end()) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
errors.emplace_back("field:dropCategories error:required field missing"); |
|
|
|
"field:dropCategories error:required field missing")); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
std::vector<grpc_error_handle> child_errors = |
|
|
|
absl::Status status = ParseDropCategories(it->second, drop_config.get()); |
|
|
|
ParseDropCategories(it->second, drop_config.get()); |
|
|
|
if (!status.ok()) errors.emplace_back(status.message()); |
|
|
|
if (!child_errors.empty()) { |
|
|
|
|
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_VECTOR( |
|
|
|
|
|
|
|
"field:dropCategories", &child_errors)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (!error_list.empty()) { |
|
|
|
if (!errors.empty()) { |
|
|
|
*error = GRPC_ERROR_CREATE_FROM_VECTOR( |
|
|
|
return absl::InvalidArgumentError(absl::StrCat( |
|
|
|
"xds_cluster_impl_experimental LB policy config", &error_list); |
|
|
|
"errors parseing xds_cluster_impl_experimental LB policy config: [", |
|
|
|
return nullptr; |
|
|
|
absl::StrJoin(errors, "; "), "]")); |
|
|
|
} |
|
|
|
} |
|
|
|
return MakeRefCounted<XdsClusterImplLbConfig>( |
|
|
|
return MakeRefCounted<XdsClusterImplLbConfig>( |
|
|
|
std::move(child_policy), std::move(cluster_name), |
|
|
|
std::move(child_policy), std::move(cluster_name), |
|
|
@ -815,65 +804,59 @@ class XdsClusterImplLbFactory : public LoadBalancingPolicyFactory { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
static std::vector<grpc_error_handle> ParseDropCategories( |
|
|
|
static absl::Status ParseDropCategories( |
|
|
|
const Json& json, XdsEndpointResource::DropConfig* drop_config) { |
|
|
|
const Json& json, XdsEndpointResource::DropConfig* drop_config) { |
|
|
|
std::vector<grpc_error_handle> error_list; |
|
|
|
|
|
|
|
if (json.type() != Json::Type::ARRAY) { |
|
|
|
if (json.type() != Json::Type::ARRAY) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
return absl::InvalidArgumentError("dropCategories field is not an array"); |
|
|
|
"dropCategories field is not an array")); |
|
|
|
|
|
|
|
return error_list; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
std::vector<std::string> errors; |
|
|
|
for (size_t i = 0; i < json.array_value().size(); ++i) { |
|
|
|
for (size_t i = 0; i < json.array_value().size(); ++i) { |
|
|
|
const Json& entry = json.array_value()[i]; |
|
|
|
const Json& entry = json.array_value()[i]; |
|
|
|
std::vector<grpc_error_handle> child_errors = |
|
|
|
absl::Status status = ParseDropCategory(entry, drop_config); |
|
|
|
ParseDropCategory(entry, drop_config); |
|
|
|
if (!status.ok()) { |
|
|
|
if (!child_errors.empty()) { |
|
|
|
errors.emplace_back( |
|
|
|
grpc_error_handle error = GRPC_ERROR_CREATE_FROM_CPP_STRING( |
|
|
|
absl::StrCat("error parsing index ", i, ": ", status.message())); |
|
|
|
absl::StrCat("errors parsing index ", i)); |
|
|
|
|
|
|
|
for (size_t i = 0; i < child_errors.size(); ++i) { |
|
|
|
|
|
|
|
error = grpc_error_add_child(error, child_errors[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
error_list.push_back(error); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return error_list; |
|
|
|
if (!errors.empty()) { |
|
|
|
|
|
|
|
return absl::InvalidArgumentError( |
|
|
|
|
|
|
|
absl::StrCat("errors parsing dropCategories field: [", |
|
|
|
|
|
|
|
absl::StrJoin(errors, "; "), "]")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return absl::OkStatus(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static std::vector<grpc_error_handle> ParseDropCategory( |
|
|
|
static absl::Status ParseDropCategory( |
|
|
|
const Json& json, XdsEndpointResource::DropConfig* drop_config) { |
|
|
|
const Json& json, XdsEndpointResource::DropConfig* drop_config) { |
|
|
|
std::vector<grpc_error_handle> error_list; |
|
|
|
|
|
|
|
if (json.type() != Json::Type::OBJECT) { |
|
|
|
if (json.type() != Json::Type::OBJECT) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
return absl::InvalidArgumentError( |
|
|
|
"dropCategories entry is not an object")); |
|
|
|
"dropCategories entry is not an object"); |
|
|
|
return error_list; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
std::vector<std::string> errors; |
|
|
|
std::string category; |
|
|
|
std::string category; |
|
|
|
auto it = json.object_value().find("category"); |
|
|
|
auto it = json.object_value().find("category"); |
|
|
|
if (it == json.object_value().end()) { |
|
|
|
if (it == json.object_value().end()) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
errors.emplace_back("\"category\" field not present"); |
|
|
|
"\"category\" field not present")); |
|
|
|
|
|
|
|
} else if (it->second.type() != Json::Type::STRING) { |
|
|
|
} else if (it->second.type() != Json::Type::STRING) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
errors.emplace_back("\"category\" field is not a string"); |
|
|
|
"\"category\" field is not a string")); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
category = it->second.string_value(); |
|
|
|
category = it->second.string_value(); |
|
|
|
} |
|
|
|
} |
|
|
|
uint32_t requests_per_million = 0; |
|
|
|
uint32_t requests_per_million = 0; |
|
|
|
it = json.object_value().find("requests_per_million"); |
|
|
|
it = json.object_value().find("requests_per_million"); |
|
|
|
if (it == json.object_value().end()) { |
|
|
|
if (it == json.object_value().end()) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
errors.emplace_back("\"requests_per_million\" field is not present"); |
|
|
|
"\"requests_per_million\" field is not present")); |
|
|
|
|
|
|
|
} else if (it->second.type() != Json::Type::NUMBER) { |
|
|
|
} else if (it->second.type() != Json::Type::NUMBER) { |
|
|
|
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING( |
|
|
|
errors.emplace_back("\"requests_per_million\" field is not a number"); |
|
|
|
"\"requests_per_million\" field is not a number")); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
requests_per_million = |
|
|
|
requests_per_million = |
|
|
|
gpr_parse_nonnegative_int(it->second.string_value().c_str()); |
|
|
|
gpr_parse_nonnegative_int(it->second.string_value().c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
if (error_list.empty()) { |
|
|
|
if (!errors.empty()) { |
|
|
|
drop_config->AddCategory(std::move(category), requests_per_million); |
|
|
|
return absl::InvalidArgumentError(absl::StrJoin(errors, "; ")); |
|
|
|
} |
|
|
|
} |
|
|
|
return error_list; |
|
|
|
drop_config->AddCategory(std::move(category), requests_per_million); |
|
|
|
|
|
|
|
return absl::OkStatus(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|