Skip to content
Snippets Groups Projects
Commit 00bbb412 authored by David G. Quintas's avatar David G. Quintas Committed by GitHub
Browse files

Merge pull request #8548 from dgquintas/lb-tokens-length

Made LB token dynamic size <= 50 bytes
parents 5998461c d14458f5
No related branches found
No related tags found
No related merge requests found
...@@ -407,10 +407,12 @@ static grpc_lb_addresses *process_serverlist( ...@@ -407,10 +407,12 @@ static grpc_lb_addresses *process_serverlist(
/* lb token processing */ /* lb token processing */
void *user_data; void *user_data;
if (server->has_load_balance_token) { if (server->has_load_balance_token) {
const size_t lb_token_size = const size_t lb_token_max_length =
GPR_ARRAY_SIZE(server->load_balance_token) - 1; GPR_ARRAY_SIZE(server->load_balance_token);
const size_t lb_token_length =
strnlen(server->load_balance_token, lb_token_max_length);
grpc_mdstr *lb_token_mdstr = grpc_mdstr_from_buffer( grpc_mdstr *lb_token_mdstr = grpc_mdstr_from_buffer(
(uint8_t *)server->load_balance_token, lb_token_size); (uint8_t *)server->load_balance_token, lb_token_length);
user_data = grpc_mdelem_from_metadata_strings(GRPC_MDSTR_LB_TOKEN, user_data = grpc_mdelem_from_metadata_strings(GRPC_MDSTR_LB_TOKEN,
lb_token_mdstr); lb_token_mdstr);
} else { } else {
......
...@@ -77,7 +77,7 @@ typedef struct _grpc_lb_v1_Server { ...@@ -77,7 +77,7 @@ typedef struct _grpc_lb_v1_Server {
bool has_port; bool has_port;
int32_t port; int32_t port;
bool has_load_balance_token; bool has_load_balance_token;
char load_balance_token[65]; char load_balance_token[50];
bool has_drop_request; bool has_drop_request;
bool drop_request; bool drop_request;
/* @@protoc_insertion_point(struct:grpc_lb_v1_Server) */ /* @@protoc_insertion_point(struct:grpc_lb_v1_Server) */
...@@ -172,7 +172,7 @@ extern const pb_field_t grpc_lb_v1_Server_fields[5]; ...@@ -172,7 +172,7 @@ extern const pb_field_t grpc_lb_v1_Server_fields[5];
#define grpc_lb_v1_LoadBalanceResponse_size (98 + grpc_lb_v1_ServerList_size) #define grpc_lb_v1_LoadBalanceResponse_size (98 + grpc_lb_v1_ServerList_size)
#define grpc_lb_v1_InitialLoadBalanceResponse_size 90 #define grpc_lb_v1_InitialLoadBalanceResponse_size 90
/* grpc_lb_v1_ServerList_size depends on runtime parameters */ /* grpc_lb_v1_ServerList_size depends on runtime parameters */
#define grpc_lb_v1_Server_size 98 #define grpc_lb_v1_Server_size 83
/* Message IDs (where set with "msgid" option) */ /* Message IDs (where set with "msgid" option) */
#ifdef PB_MSGID #ifdef PB_MSGID
......
grpc.lb.v1.InitialLoadBalanceRequest.name max_size:128 grpc.lb.v1.InitialLoadBalanceRequest.name max_size:128
grpc.lb.v1.InitialLoadBalanceResponse.client_config max_size:64
grpc.lb.v1.InitialLoadBalanceResponse.load_balancer_delegate max_size:64 grpc.lb.v1.InitialLoadBalanceResponse.load_balancer_delegate max_size:64
grpc.lb.v1.Server.ip_address max_size:16 grpc.lb.v1.Server.ip_address max_size:16
grpc.lb.v1.Server.load_balance_token max_size:65 grpc.lb.v1.Server.load_balance_token max_size:50
load_balancer.proto no_unions:true load_balancer.proto no_unions:true
...@@ -63,7 +63,8 @@ message LoadBalanceRequest { ...@@ -63,7 +63,8 @@ message LoadBalanceRequest {
} }
message InitialLoadBalanceRequest { message InitialLoadBalanceRequest {
// Name of load balanced service (IE, service.grpc.gslb.google.com) // Name of load balanced service (IE, service.grpc.gslb.google.com). Its
// length should be less than 256 bytes.
string name = 1; string name = 1;
} }
...@@ -95,7 +96,8 @@ message InitialLoadBalanceResponse { ...@@ -95,7 +96,8 @@ message InitialLoadBalanceResponse {
// This is an application layer redirect that indicates the client should use // This is an application layer redirect that indicates the client should use
// the specified server for load balancing. When this field is non-empty in // the specified server for load balancing. When this field is non-empty in
// the response, the client should open a separate connection to the // the response, the client should open a separate connection to the
// load_balancer_delegate and call the BalanceLoad method. // load_balancer_delegate and call the BalanceLoad method. Its length should
// be less than 64 bytes.
string load_balancer_delegate = 1; string load_balancer_delegate = 1;
// This interval defines how often the client should send the client stats // This interval defines how often the client should send the client stats
...@@ -130,6 +132,8 @@ message Server { ...@@ -130,6 +132,8 @@ message Server {
// frontend requests for that pick must include the token in its initial // frontend requests for that pick must include the token in its initial
// metadata. The token is used by the backend to verify the request and to // metadata. The token is used by the backend to verify the request and to
// allow the backend to report load to the gRPC LB system. // allow the backend to report load to the gRPC LB system.
//
// Its length is variable but less than 50 bytes.
string load_balance_token = 3; string load_balance_token = 3;
// Indicates whether this particular request should be dropped by the client // Indicates whether this particular request should be dropped by the client
......
...@@ -144,7 +144,6 @@ static gpr_slice build_response_payload_slice( ...@@ -144,7 +144,6 @@ static gpr_slice build_response_payload_slice(
// disfunctional implementation of std::to_string in gcc 4.4, which doesn't // disfunctional implementation of std::to_string in gcc 4.4, which doesn't
// have a version for int but does have one for long long int. // have a version for int but does have one for long long int.
string token_data = "token" + std::to_string((long long int)ports[i]); string token_data = "token" + std::to_string((long long int)ports[i]);
token_data.resize(64, '-');
server->set_load_balance_token(token_data); server->set_load_balance_token(token_data);
} }
const grpc::string &enc_resp = response.SerializeAsString(); const grpc::string &enc_resp = response.SerializeAsString();
...@@ -333,7 +332,6 @@ static void start_backend_server(server_fixture *sf) { ...@@ -333,7 +332,6 @@ static void start_backend_server(server_fixture *sf) {
// disfunctional implementation of std::to_string in gcc 4.4, which doesn't // disfunctional implementation of std::to_string in gcc 4.4, which doesn't
// have a version for int but does have one for long long int. // have a version for int but does have one for long long int.
string expected_token = "token" + std::to_string((long long int)sf->port); string expected_token = "token" + std::to_string((long long int)sf->port);
expected_token.resize(64, '-');
GPR_ASSERT(contains_metadata(&request_metadata_recv, "lb-token", GPR_ASSERT(contains_metadata(&request_metadata_recv, "lb-token",
expected_token.c_str())); expected_token.c_str()));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment