aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2018-12-11 10:27:11 -0800
committerGravatar ncteisen <ncteisen@gmail.com>2018-12-11 10:27:11 -0800
commita6ed43b41fec1201c3d239ee2910aac65cba9d90 (patch)
tree37bf1bd901964b887d5dfd954a89285ac3036e45
parent7b1fc0faa23b2cc1807450498b8c69afb079c2d2 (diff)
reviewer feedback
-rw-r--r--src/core/lib/channel/channelz.cc20
-rw-r--r--src/proto/grpc/channelz/channelz.proto2
2 files changed, 7 insertions, 15 deletions
diff --git a/src/core/lib/channel/channelz.cc b/src/core/lib/channel/channelz.cc
index 3fcfa2a412..10d5e1b581 100644
--- a/src/core/lib/channel/channelz.cc
+++ b/src/core/lib/channel/channelz.cc
@@ -205,28 +205,20 @@ ServerNode::~ServerNode() {}
char* ServerNode::RenderServerSockets(intptr_t start_socket_id,
intptr_t max_results) {
- // if user does not set max_results, we choose 500.
- int pagination_limit = max_results == 0 ? 500 : max_results;
+ // if user does not set max_results, we choose 1000.
+ size_t pagination_limit = max_results == 0 ? 500 : max_results;
grpc_json* top_level_json = grpc_json_create(GRPC_JSON_OBJECT);
grpc_json* json = top_level_json;
grpc_json* json_iterator = nullptr;
ChildSocketsList socket_refs;
grpc_server_populate_server_sockets(server_, &socket_refs, start_socket_id);
- int sockets_added = 0;
- bool reached_pagination_limit = false;
+ // declared early so it can be used outside of the loop.
+ size_t i = 0;
if (!socket_refs.empty()) {
// create list of socket refs
grpc_json* array_parent = grpc_json_create_child(
nullptr, json, "socketRef", nullptr, GRPC_JSON_ARRAY, false);
- for (size_t i = 0; i < socket_refs.size(); ++i) {
- // check if we are over pagination limit to determine if we need to set
- // the "end" element. If we don't go through this block, we know that
- // when the loop terminates, we have <= to pagination_limit.
- if (sockets_added == pagination_limit) {
- reached_pagination_limit = true;
- break;
- }
- sockets_added++;
+ for (i = 0; i < GPR_MIN(socket_refs.size(), pagination_limit); ++i) {
grpc_json* socket_ref_json =
grpc_json_create_child(json_iterator, array_parent, nullptr, nullptr,
GRPC_JSON_OBJECT, false);
@@ -236,7 +228,7 @@ char* ServerNode::RenderServerSockets(intptr_t start_socket_id,
socket_refs[i]->remote(), GRPC_JSON_STRING, false);
}
}
- if (!reached_pagination_limit) {
+ if (i == socket_refs.size()) {
json_iterator = grpc_json_create_child(nullptr, json, "end", nullptr,
GRPC_JSON_TRUE, false);
}
diff --git a/src/proto/grpc/channelz/channelz.proto b/src/proto/grpc/channelz/channelz.proto
index 9d73f37554..20de23f7fa 100644
--- a/src/proto/grpc/channelz/channelz.proto
+++ b/src/proto/grpc/channelz/channelz.proto
@@ -561,4 +561,4 @@ message GetSocketResponse {
// The Socket that corresponds to the requested socket_id. This field
// should be set.
Socket socket = 1;
-} \ No newline at end of file
+}