diff options
author | Makarand Dharmapurikar <makarandd@google.com> | 2017-03-17 11:10:08 -0700 |
---|---|---|
committer | Makarand Dharmapurikar <makarandd@google.com> | 2017-03-17 11:10:08 -0700 |
commit | c2a8a8f5c248516c684136b22181f2db204df7bc (patch) | |
tree | 8e4023678d5e6248c1fc515cd99aaa13edf1e18c /tools/grpcz | |
parent | 8ee0ecba9418cc4799c52117f93a7f772651af32 (diff) |
addressed review feedback
using new grpc_build_system, and cleaned up typos.
Diffstat (limited to 'tools/grpcz')
-rw-r--r-- | tools/grpcz/BUILD | 38 | ||||
-rw-r--r-- | tools/grpcz/any.proto | 139 | ||||
-rw-r--r-- | tools/grpcz/empty.proto | 52 | ||||
-rw-r--r-- | tools/grpcz/grpcz_client.cc | 41 | ||||
-rw-r--r-- | tools/grpcz/monitoring.proto | 6 |
5 files changed, 42 insertions, 234 deletions
diff --git a/tools/grpcz/BUILD b/tools/grpcz/BUILD index 4ae12d5006..5e1faf7064 100644 --- a/tools/grpcz/BUILD +++ b/tools/grpcz/BUILD @@ -31,43 +31,33 @@ licenses(["notice"]) # 3-clause BSD package(default_visibility = ["//visibility:public"]) -load("//:bazel/generate_cc.bzl", "generate_cc") +load("//:bazel/grpc_build_system.bzl", "grpc_proto_library") -proto_library ( - name = "monitoring_proto_local_copy", +grpc_proto_library ( + name = "monitoring_proto", srcs = [ - # TODO (ericgribkoff) : remove the local copies of these protos "monitoring.proto", - "empty.proto", - "any.proto", - "census.proto", ], + deps = [ + ":census_proto", + ], + well_known_protos = "@submodule_protobuf//:well_known_protos", ) -generate_cc( - name = "monitoring_codegen", - srcs = [":monitoring_proto_local_copy"], -) - -generate_cc( - name = "monitoring_grpc_codegen", - srcs = [":monitoring_proto_local_copy"], - plugin = "//:grpc_cpp_plugin", -) - -cc_library( - name = "proto_lib", - srcs = [":monitoring_codegen", ":monitoring_grpc_codegen"], - hdrs = [":monitoring_codegen", ":monitoring_grpc_codegen"], - deps = ["//:grpc++", "//:grpc++_codegen_proto", "//external:protobuf"], +grpc_proto_library ( + name = "census_proto", + srcs = [ + "census.proto", + ], + well_known_protos = "@submodule_protobuf//:well_known_protos", ) cc_binary( name = "grpcz_client", srcs = ["grpcz_client.cc",], deps = [ - "proto_lib", "//external:gflags", + "monitoring_proto", "@mongoose_repo//:mongoose_lib", ], ) diff --git a/tools/grpcz/any.proto b/tools/grpcz/any.proto deleted file mode 100644 index a224a2b596..0000000000 --- a/tools/grpcz/any.proto +++ /dev/null @@ -1,139 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto3"; - -//package google.protobuf; - -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option go_package = "github.com/golang/protobuf/ptypes/any"; -option java_package = "com.google.protobuf"; -option java_outer_classname = "AnyProto"; -option java_multiple_files = true; -option objc_class_prefix = "GPB"; - -// `Any` contains an arbitrary serialized protocol buffer message along with a -// URL that describes the type of the serialized message. -// -// Protobuf library provides support to pack/unpack Any values in the form -// of utility functions or additional generated methods of the Any type. -// -// Example 1: Pack and unpack a message in C++. -// -// Foo foo = ...; -// Any any; -// any.PackFrom(foo); -// ... -// if (any.UnpackTo(&foo)) { -// ... -// } -// -// Example 2: Pack and unpack a message in Java. -// -// Foo foo = ...; -// Any any = Any.pack(foo); -// ... -// if (any.is(Foo.class)) { -// foo = any.unpack(Foo.class); -// } -// -// Example 3: Pack and unpack a message in Python. -// -// foo = Foo(...) -// any = Any() -// any.Pack(foo) -// ... -// if any.Is(Foo.DESCRIPTOR): -// any.Unpack(foo) -// ... -// -// The pack methods provided by protobuf library will by default use -// 'type.googleapis.com/full.type.name' as the type URL and the unpack -// methods only use the fully qualified type name after the last '/' -// in the type URL, for example "foo.bar.com/x/y.z" will yield type -// name "y.z". -// -// -// JSON -// ==== -// The JSON representation of an `Any` value uses the regular -// representation of the deserialized, embedded message, with an -// additional field `@type` which contains the type URL. Example: -// -// package google.profile; -// message Person { -// string first_name = 1; -// string last_name = 2; -// } -// -// { -// "@type": "type.googleapis.com/google.profile.Person", -// "firstName": <string>, -// "lastName": <string> -// } -// -// If the embedded message type is well-known and has a custom JSON -// representation, that representation will be embedded adding a field -// `value` which holds the custom JSON in addition to the `@type` -// field. Example (for message [google.protobuf.Duration][]): -// -// { -// "@type": "type.googleapis.com/google.protobuf.Duration", -// "value": "1.212s" -// } -// -message Any { - // A URL/resource name whose content describes the type of the - // serialized protocol buffer message. - // - // For URLs which use the scheme `http`, `https`, or no scheme, the - // following restrictions and interpretations apply: - // - // * If no scheme is provided, `https` is assumed. - // * The last segment of the URL's path must represent the fully - // qualified name of the type (as in `path/google.protobuf.Duration`). - // The name should be in a canonical form (e.g., leading "." is - // not accepted). - // * An HTTP GET on the URL must yield a [google.protobuf.Type][] - // value in binary format, or produce an error. - // * Applications are allowed to cache lookup results based on the - // URL, or have them precompiled into a binary to avoid any - // lookup. Therefore, binary compatibility needs to be preserved - // on changes to types. (Use versioned type names to manage - // breaking changes.) - // - // Schemes other than `http`, `https` (or the empty scheme) might be - // used with implementation specific semantics. - // - string type_url = 1; - - // Must be a valid serialized protocol buffer of the above specified type. - bytes value = 2; -} diff --git a/tools/grpcz/empty.proto b/tools/grpcz/empty.proto deleted file mode 100644 index 03cacd2330..0000000000 --- a/tools/grpcz/empty.proto +++ /dev/null @@ -1,52 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto3"; - -package google.protobuf; - -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option go_package = "github.com/golang/protobuf/ptypes/empty"; -option java_package = "com.google.protobuf"; -option java_outer_classname = "EmptyProto"; -option java_multiple_files = true; -option objc_class_prefix = "GPB"; -option cc_enable_arenas = true; - -// A generic empty message that you can re-use to avoid defining duplicated -// empty messages in your APIs. A typical example is to use it as the request -// or the response type of an API method. For instance: -// -// service Foo { -// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); -// } -// -// The JSON representation for `Empty` is empty JSON object `{}`. -message Empty {} diff --git a/tools/grpcz/grpcz_client.cc b/tools/grpcz/grpcz_client.cc index afca3b0532..f4611466c5 100644 --- a/tools/grpcz/grpcz_client.cc +++ b/tools/grpcz/grpcz_client.cc @@ -46,11 +46,14 @@ #include "tools/grpcz/census.grpc.pb.h" #include "tools/grpcz/monitoring.grpc.pb.h" -DEFINE_string(server, "127.0.0.1:50052", - "file path (or host:port) where grpcz server is running"); +DEFINE_string( + grpcz_server, "127.0.0.1:8080", + "Unix domain socket path (e.g. unix://tmp/grpcz.sock) or IP address" + "(host:port) where grpcz server is running."); DEFINE_string(http_port, "8000", "Port id for accessing the HTTP server that renders /grpcz page"); -DEFINE_bool(print, false, "only print the output and quit"); +DEFINE_bool(print_to_console, false, + "print the JSON retreived from grpcz server and quit"); using grpc::Channel; using grpc::ClientContext; @@ -68,11 +71,14 @@ table, td, th { border: 1px solid black; } \ static const std::string static_html_footer = "' class='hidden'></div>\ -<h1> GRPCZ FTW </h1> <div id='table'> </div> \ +<h1>GRPCZ Statistics</h1> <div id='table'> </div> \ <script> \ var canonical_stats = JSON.parse(\ document.getElementById('stats').getAttribute('stats')); \ var table = document.createElement('table'); \ + if (canonical_stats['Error Message'] != undefined) { \ + document.getElementById('table').innerHTML = canonical_stats['Error Message']; } \ + else {\ for (var key in canonical_stats) { \ name = canonical_stats[key]['view']['viewName']; \ distribution = canonical_stats[key]['view']['distributionView']; \ @@ -87,6 +93,7 @@ static const std::string static_html_footer = col2.innerHTML = '<pre>' + value + '</pre>'; \ } \ document.getElementById('table').appendChild(table); \ + }\ </script> </body> </html>"; class GrpczClient { @@ -106,11 +113,9 @@ class GrpczClient { return json_str; } else { static const std::string error_message_json = - "{\"grpcz Access Error\"\ - :{\"view\":{\"viewName\":\"grpcz Access Error\",\ - \"intervalView\":\"Server not running?\"}}}"; - std::cout << status.error_code() << ":= " << status.error_message() - << std::endl; + "{\"Error Message\":\"" + status.error_message() + "\"}"; + gpr_log(GPR_DEBUG, "%d: %s", status.error_code(), + status.error_message().c_str()); return error_message_json; } } @@ -131,7 +136,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) { static void grpcz_handler(struct mg_connection *nc, int ev, void *ev_data) { (void)ev; (void)ev_data; - gpr_log(GPR_INFO, "fetching grpcz stats from %s", FLAGS_server.c_str()); + gpr_log(GPR_INFO, "fetching grpcz stats from %s", FLAGS_grpcz_server.c_str()); std::string json_str = g_grpcz_client->GetStatsAsJson(); std::string rendered_html = static_html_header + json_str + static_html_footer; @@ -143,10 +148,13 @@ int main(int argc, char **argv) { gflags::ParseCommandLineFlags(&argc, &argv, true); // Create a client - g_grpcz_client.reset(new GrpczClient( - grpc::CreateChannel(FLAGS_server, grpc::InsecureChannelCredentials()))); - if (FLAGS_print) { - g_grpcz_client->GetStatsAsJson(); + g_grpcz_client.reset(new GrpczClient(grpc::CreateChannel( + FLAGS_grpcz_server, grpc::InsecureChannelCredentials()))); + if (FLAGS_print_to_console) { + // using GPR_ERROR since this is the default verbosity. _DEBUG or _INFO + // won't print unless GRPC_VERBOSITY env var is set appropriately, which + // might confuse users of this utility. + gpr_log(GPR_ERROR, "%s\n", g_grpcz_client->GetStatsAsJson().c_str()); return 0; } @@ -160,14 +168,15 @@ int main(int argc, char **argv) { if (nc == NULL) { gpr_log(GPR_ERROR, "Failed to create listener on port %s\n", FLAGS_http_port.c_str()); - return -11; + return -1; } mg_register_http_endpoint(nc, "/grpcz", grpcz_handler); mg_set_protocol_http_websocket(nc); // Poll in a loop and serve /grpcz pages for (;;) { - mg_mgr_poll(&mgr, 100); + static const int k_sleep_millis = 100; + mg_mgr_poll(&mgr, k_sleep_millis); } mg_mgr_free(&mgr); return 0; diff --git a/tools/grpcz/monitoring.proto b/tools/grpcz/monitoring.proto index ec3dfe9f74..4d09aeb6f3 100644 --- a/tools/grpcz/monitoring.proto +++ b/tools/grpcz/monitoring.proto @@ -34,8 +34,8 @@ syntax = "proto3"; // TODO(ericgribkoff) Figure out how to manage the external Census proto // dependency. import "tools/grpcz/census.proto"; -import "tools/grpcz/empty.proto"; -import "tools/grpcz/any.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/any.proto"; package grpc.instrumentation.v1alpha; @@ -126,6 +126,6 @@ message MonitoringDataGroup { // The wrapper for custom monitoring data. message CustomMonitoringData { // can be any application specific monitoring data - Any contents = 1; + google.protobuf.Any contents = 1; } |