Accept max message size JSON values as either strings or numbers.

pull/9477/head
Mark D. Roth 8 years ago
parent 1291fd4b2f
commit 40b4c786f0
  1. 10
      doc/service_config.md
  2. 8
      src/core/lib/channel/message_size_filter.c
  3. 64
      test/core/end2end/tests/max_message_length.c

@ -95,10 +95,7 @@ The service config is a JSON string of the following form:
# will not be sent and the client will see an error. # will not be sent and the client will see an error.
# Note that 0 is a valid value, meaning that the request message must # Note that 0 is a valid value, meaning that the request message must
# be empty. # be empty.
# 'maxRequestMessageBytes': number,
# The format of the value is that of the 'uint64' type defined here:
# https://developers.google.com/protocol-buffers/docs/proto3#json
'maxRequestMessageBytes': string,
# The maximum allowed payload size for an individual response or object # The maximum allowed payload size for an individual response or object
# in a stream (server->client) in bytes. The size which is measured is # in a stream (server->client) in bytes. The size which is measured is
@ -114,10 +111,7 @@ The service config is a JSON string of the following form:
# will not be sent, and the client will see an error. # will not be sent, and the client will see an error.
# Note that 0 is a valid value, meaning that the response message must # Note that 0 is a valid value, meaning that the response message must
# be empty. # be empty.
# 'maxResponseMessageBytes': number
# The format of the value is that of the 'uint64' type defined here:
# https://developers.google.com/protocol-buffers/docs/proto3#json
'maxResponseMessageBytes': string
} }
] ]
} }

@ -68,12 +68,16 @@ static void* message_size_limits_create_from_json(const grpc_json* json) {
if (field->key == NULL) continue; if (field->key == NULL) continue;
if (strcmp(field->key, "maxRequestMessageBytes") == 0) { if (strcmp(field->key, "maxRequestMessageBytes") == 0) {
if (max_request_message_bytes >= 0) return NULL; // Duplicate. if (max_request_message_bytes >= 0) return NULL; // Duplicate.
if (field->type != GRPC_JSON_STRING) return NULL; if (field->type != GRPC_JSON_STRING && field->type != GRPC_JSON_NUMBER) {
return NULL;
}
max_request_message_bytes = gpr_parse_nonnegative_int(field->value); max_request_message_bytes = gpr_parse_nonnegative_int(field->value);
if (max_request_message_bytes == -1) return NULL; if (max_request_message_bytes == -1) return NULL;
} else if (strcmp(field->key, "maxResponseMessageBytes") == 0) { } else if (strcmp(field->key, "maxResponseMessageBytes") == 0) {
if (max_response_message_bytes >= 0) return NULL; // Duplicate. if (max_response_message_bytes >= 0) return NULL; // Duplicate.
if (field->type != GRPC_JSON_STRING) return NULL; if (field->type != GRPC_JSON_STRING && field->type != GRPC_JSON_NUMBER) {
return NULL;
}
max_response_message_bytes = gpr_parse_nonnegative_int(field->value); max_response_message_bytes = gpr_parse_nonnegative_int(field->value);
if (max_response_message_bytes == -1) return NULL; if (max_response_message_bytes == -1) return NULL;
} }

@ -108,9 +108,12 @@ static void end_test(grpc_end2end_test_fixture *f) {
// recv limit on server. // recv limit on server.
static void test_max_message_length_on_request(grpc_end2end_test_config config, static void test_max_message_length_on_request(grpc_end2end_test_config config,
bool send_limit, bool send_limit,
bool use_service_config) { bool use_service_config,
gpr_log(GPR_INFO, "testing request with send_limit=%d use_service_config=%d", bool use_string_json_value) {
send_limit, use_service_config); gpr_log(GPR_INFO,
"testing request with send_limit=%d use_service_config=%d "
"use_string_json_value=%d",
send_limit, use_service_config, use_string_json_value);
grpc_end2end_test_fixture f; grpc_end2end_test_fixture f;
grpc_call *c = NULL; grpc_call *c = NULL;
@ -142,13 +145,22 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config,
arg.type = GRPC_ARG_STRING; arg.type = GRPC_ARG_STRING;
arg.key = GRPC_ARG_SERVICE_CONFIG; arg.key = GRPC_ARG_SERVICE_CONFIG;
arg.value.string = arg.value.string =
"{\n" use_string_json_value
? "{\n"
" \"methodConfig\": [ {\n" " \"methodConfig\": [ {\n"
" \"name\": [\n" " \"name\": [\n"
" { \"service\": \"service\", \"method\": \"method\" }\n" " { \"service\": \"service\", \"method\": \"method\" }\n"
" ],\n" " ],\n"
" \"maxRequestMessageBytes\": \"5\"\n" " \"maxRequestMessageBytes\": \"5\"\n"
" } ]\n" " } ]\n"
"}"
: "{\n"
" \"methodConfig\": [ {\n"
" \"name\": [\n"
" { \"service\": \"service\", \"method\": \"method\" }\n"
" ],\n"
" \"maxRequestMessageBytes\": 5\n"
" } ]\n"
"}"; "}";
client_args = grpc_channel_args_copy_and_add(NULL, &arg, 1); client_args = grpc_channel_args_copy_and_add(NULL, &arg, 1);
} else { } else {
@ -286,9 +298,12 @@ done:
// recv limit on client. // recv limit on client.
static void test_max_message_length_on_response(grpc_end2end_test_config config, static void test_max_message_length_on_response(grpc_end2end_test_config config,
bool send_limit, bool send_limit,
bool use_service_config) { bool use_service_config,
gpr_log(GPR_INFO, "testing response with send_limit=%d use_service_config=%d", bool use_string_json_value) {
send_limit, use_service_config); gpr_log(GPR_INFO,
"testing response with send_limit=%d use_service_config=%d "
"use_string_json_value=%d",
send_limit, use_service_config, use_string_json_value);
grpc_end2end_test_fixture f; grpc_end2end_test_fixture f;
grpc_call *c = NULL; grpc_call *c = NULL;
@ -320,13 +335,22 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config,
arg.type = GRPC_ARG_STRING; arg.type = GRPC_ARG_STRING;
arg.key = GRPC_ARG_SERVICE_CONFIG; arg.key = GRPC_ARG_SERVICE_CONFIG;
arg.value.string = arg.value.string =
"{\n" use_string_json_value
? "{\n"
" \"methodConfig\": [ {\n" " \"methodConfig\": [ {\n"
" \"name\": [\n" " \"name\": [\n"
" { \"service\": \"service\", \"method\": \"method\" }\n" " { \"service\": \"service\", \"method\": \"method\" }\n"
" ],\n" " ],\n"
" \"maxResponseMessageBytes\": \"5\"\n" " \"maxResponseMessageBytes\": \"5\"\n"
" } ]\n" " } ]\n"
"}"
: "{\n"
" \"methodConfig\": [ {\n"
" \"name\": [\n"
" { \"service\": \"service\", \"method\": \"method\" }\n"
" ],\n"
" \"maxResponseMessageBytes\": 5\n"
" } ]\n"
"}"; "}";
client_args = grpc_channel_args_copy_and_add(NULL, &arg, 1); client_args = grpc_channel_args_copy_and_add(NULL, &arg, 1);
} else { } else {
@ -462,17 +486,29 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config,
void max_message_length(grpc_end2end_test_config config) { void max_message_length(grpc_end2end_test_config config) {
test_max_message_length_on_request(config, false /* send_limit */, test_max_message_length_on_request(config, false /* send_limit */,
false /* use_service_config */); false /* use_service_config */,
false /* use_string_json_value */);
test_max_message_length_on_request(config, true /* send_limit */, test_max_message_length_on_request(config, true /* send_limit */,
false /* use_service_config */); false /* use_service_config */,
false /* use_string_json_value */);
test_max_message_length_on_response(config, false /* send_limit */, test_max_message_length_on_response(config, false /* send_limit */,
false /* use_service_config */); false /* use_service_config */,
false /* use_string_json_value */);
test_max_message_length_on_response(config, true /* send_limit */, test_max_message_length_on_response(config, true /* send_limit */,
false /* use_service_config */); false /* use_service_config */,
false /* use_string_json_value */);
test_max_message_length_on_request(config, true /* send_limit */,
true /* use_service_config */,
false /* use_string_json_value */);
test_max_message_length_on_request(config, true /* send_limit */, test_max_message_length_on_request(config, true /* send_limit */,
true /* use_service_config */); true /* use_service_config */,
true /* use_string_json_value */);
test_max_message_length_on_response(config, false /* send_limit */,
true /* use_service_config */,
false /* use_string_json_value */);
test_max_message_length_on_response(config, false /* send_limit */, test_max_message_length_on_response(config, false /* send_limit */,
true /* use_service_config */); true /* use_service_config */,
true /* use_string_json_value */);
} }
void max_message_length_pre_init(void) {} void max_message_length_pre_init(void) {}

Loading…
Cancel
Save