From e77da44eef9004ca995e82a7c3d33158ed0b13e5 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 29 Jul 2015 10:09:36 -0700 Subject: [PATCH 01/33] Ensure that client generated methods don't conflict with other properties --- src/node/src/client.js | 27 +++++++++++++++------------ src/node/test/surface_test.js | 20 +++++++++++++++++++- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/node/src/client.js b/src/node/src/client.js index f843669bd0f..405e2be693b 100644 --- a/src/node/src/client.js +++ b/src/node/src/client.js @@ -236,7 +236,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) { deadline = Infinity; } var emitter = new EventEmitter(); - var call = new grpc.Call(this.channel, method, deadline); + var call = new grpc.Call(this.$channel, method, deadline); if (metadata === null || metadata === undefined) { metadata = {}; } @@ -246,7 +246,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) { emitter.getPeer = function getPeer() { return call.getPeer(); }; - this.updateMetadata(this.auth_uri, metadata, function(error, metadata) { + this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) { if (error) { call.cancel(); callback(error); @@ -309,12 +309,12 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) { if (deadline === undefined) { deadline = Infinity; } - var call = new grpc.Call(this.channel, method, deadline); + var call = new grpc.Call(this.$channel, method, deadline); if (metadata === null || metadata === undefined) { metadata = {}; } var stream = new ClientWritableStream(call, serialize); - this.updateMetadata(this.auth_uri, metadata, function(error, metadata) { + this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) { if (error) { call.cancel(); callback(error); @@ -383,12 +383,12 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) { if (deadline === undefined) { deadline = Infinity; } - var call = new grpc.Call(this.channel, method, deadline); + var call = new grpc.Call(this.$channel, method, deadline); if (metadata === null || metadata === undefined) { metadata = {}; } var stream = new ClientReadableStream(call, deserialize); - this.updateMetadata(this.auth_uri, metadata, function(error, metadata) { + this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) { if (error) { call.cancel(); stream.emit('error', error); @@ -455,12 +455,12 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) { if (deadline === undefined) { deadline = Infinity; } - var call = new grpc.Call(this.channel, method, deadline); + var call = new grpc.Call(this.$channel, method, deadline); if (metadata === null || metadata === undefined) { metadata = {}; } var stream = new ClientDuplexStream(call, serialize, deserialize); - this.updateMetadata(this.auth_uri, metadata, function(error, metadata) { + this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) { if (error) { call.cancel(); stream.emit('error', error); @@ -545,14 +545,17 @@ exports.makeClientConstructor = function(methods, serviceName) { options = {}; } options['grpc.primary_user_agent'] = 'grpc-node/' + version; - this.channel = new grpc.Channel(address, options); - this.server_address = address.replace(/\/$/, ''); - this.auth_uri = this.server_address + '/' + serviceName; - this.updateMetadata = updateMetadata; + this.$channel = new grpc.Channel(address, options); + this.$server_address = address.replace(/\/$/, ''); + this.$auth_uri = this.$server_address + '/' + serviceName; + this.$updateMetadata = updateMetadata; } _.each(methods, function(attrs, name) { var method_type; + if (_.startsWith(name, '$')) { + throw new Error('Method names cannot start with $'); + } if (attrs.requestStream) { if (attrs.responseStream) { method_type = 'bidi'; diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 98f9b15bfc4..1afdb33089b 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -110,6 +110,24 @@ describe('Server.prototype.addProtoService', function() { }); }); }); +describe('Client constructor building', function() { + var illegal_service_attrs = { + $method : { + path: '/illegal/$method', + requestStream: false, + responseStream: false, + requestSerialize: _.identity, + requestDeserialize: _.identity, + responseSerialize: _.identity, + responseDeserialize: _.identity + } + }; + it('Should reject method names starting with $', function() { + assert.throws(function() { + grpc.makeGenericClientConstructor(illegal_service_attrs); + }, /\$/); + }); +}); describe('Echo service', function() { var server; var client; @@ -344,7 +362,7 @@ describe('Other conditions', function() { server.shutdown(); }); it('channel.getTarget should be available', function() { - assert.strictEqual(typeof client.channel.getTarget(), 'string'); + assert.strictEqual(typeof client.$channel.getTarget(), 'string'); }); describe('Server recieving bad input', function() { var misbehavingClient; From f685ae25b2e6817ccbddc54c8b4612f0d057a042 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Wed, 29 Jul 2015 15:25:57 -0700 Subject: [PATCH 02/33] Missed one --- src/node/interop/interop_client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js index e810e68e450..953cbb16794 100644 --- a/src/node/interop/interop_client.js +++ b/src/node/interop/interop_client.js @@ -292,7 +292,7 @@ function authTest(expected_user, scope, client, done) { if (credential.createScopedRequired() && scope) { credential = credential.createScoped(scope); } - client.updateMetadata = grpc.getGoogleAuthDelegate(credential); + client.$updateMetadata = grpc.getGoogleAuthDelegate(credential); var arg = { response_type: 'COMPRESSABLE', response_size: 314159, @@ -355,7 +355,7 @@ function oauth2Test(expected_user, scope, per_rpc, client, done) { if (per_rpc) { updateMetadata('', {}, makeTestCall); } else { - client.updateMetadata = updateMetadata; + client.$updateMetadata = updateMetadata; makeTestCall(null, {}); } From 4e53265f6470a8736967f9cbc2e0797ad04755ca Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 21 Aug 2015 14:01:47 -0700 Subject: [PATCH 03/33] Changed prefixed Client properties to distinguish private and public properties --- src/node/interop/interop_client.js | 4 ++-- src/node/src/client.js | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js index 9100edf243b..2f8eaea41d5 100644 --- a/src/node/interop/interop_client.js +++ b/src/node/interop/interop_client.js @@ -285,7 +285,7 @@ function authTest(expected_user, scope, client, done) { if (credential.createScopedRequired() && scope) { credential = credential.createScoped(scope); } - client.$updateMetadata = grpc.getGoogleAuthDelegate(credential); + client.$_updateMetadata = grpc.getGoogleAuthDelegate(credential); var arg = { response_type: 'COMPRESSABLE', response_size: 314159, @@ -344,7 +344,7 @@ function oauth2Test(expected_user, scope, per_rpc, client, done) { if (per_rpc) { updateMetadata('', {}, makeTestCall); } else { - client.$updateMetadata = updateMetadata; + client.$_updateMetadata = updateMetadata; makeTestCall(null, {}); } }); diff --git a/src/node/src/client.js b/src/node/src/client.js index f288104e2ba..ddd28e37b80 100644 --- a/src/node/src/client.js +++ b/src/node/src/client.js @@ -32,7 +32,7 @@ */ /** - * Server module + * Client module * @module */ @@ -272,7 +272,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) { emitter.getPeer = function getPeer() { return call.getPeer(); }; - this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) { + this.$_updateMetadata(this.$_auth_uri, metadata, function(error, metadata) { if (error) { call.cancel(); callback(error); @@ -340,7 +340,7 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) { metadata = {}; } var stream = new ClientWritableStream(call, serialize); - this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) { + this.$_updateMetadata(this.$_auth_uri, metadata, function(error, metadata) { if (error) { call.cancel(); callback(error); @@ -410,7 +410,7 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) { metadata = {}; } var stream = new ClientReadableStream(call, deserialize); - this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) { + this.$_updateMetadata(this.$_auth_uri, metadata, function(error, metadata) { if (error) { call.cancel(); stream.emit('error', error); @@ -482,7 +482,7 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) { metadata = {}; } var stream = new ClientDuplexStream(call, serialize, deserialize); - this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) { + this.$_updateMetadata(this.$_auth_uri, metadata, function(error, metadata) { if (error) { call.cancel(); stream.emit('error', error); @@ -572,9 +572,9 @@ exports.makeClientConstructor = function(methods, serviceName) { this.$channel = new grpc.Channel(address, credentials, options); // Remove the optional DNS scheme, trailing port, and trailing backslash address = address.replace(/^(dns:\/{3})?([^:\/]+)(:\d+)?\/?$/, '$2'); - this.$server_address = address; - this.$auth_uri = 'https://' + this.server_address + '/' + serviceName; - this.$updateMetadata = updateMetadata; + this.$_server_address = address; + this.$_auth_uri = 'https://' + this.server_address + '/' + serviceName; + this.$_updateMetadata = updateMetadata; } /** From ade0021289f366d5bc7e5d6fc669217280e4e828 Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Tue, 25 Aug 2015 15:00:26 -0700 Subject: [PATCH 04/33] checkpoint --- include/grpc/census.h | 98 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/include/grpc/census.h b/include/grpc/census.h index a18b997b79b..bc167397b94 100644 --- a/include/grpc/census.h +++ b/include/grpc/census.h @@ -170,6 +170,104 @@ typedef struct { void census_record_stat(census_context *context, census_stat *stats, size_t nstats); +/* Stats Configuration - Census clients can use these functions and structures + to extend and define what stats get recorded for what measurements. */ + +/** Stats types supported by census. */ +typedef enum { + CENSUS_STAT_SCALAR = 0, /* Simple scalar */ + CENSUS_STAT_DISTRIBUTION = 1, /* count, average, variance */ + CENSUS_STAT_HISTOGRAM = 2, /* Histogram. */ + CENSUS_STAT_WINDOW = 3, /* Count over a time window. */ + CENSUS_STAT_NSTATS = 4 /* Total number of stats types. */ +} census_stat_type; + +/* + Each stats type differs in how it is initialized, how it is represented, and + the results it provides. The following structures allow us to use a generic + type for each of those. + + Types referenced (one for each stat type in census_stat_type): +*/ + +typedef struct census_stat_scalar_create_arg census_stat_scalar_create_arg; +typedef struct census_stat_distribution_create_arg + census_stat_distribution_create_arg; +typedef struct census_stat_histogram_create_arg + census_stat_histogram_create_arg; +typedef struct census_stat_window_create_arg census_stat_window_create_arg; + +/** + Type for representing information to construct a new instance of a given + stats type (e.g. histogram bucket boundaries). +*/ +typedef struct { + census_stat_type stat_type; /* The "real" type of the stat. */ + union { + const census_stat_scalar_create_arg *scalar_arg; + const census_stat_distribution_create_arg *distribution_arg; + const census_stat_histogram_create_arg *histogram_arg; + const census_stat_window_create_arg *window_arg; + } +} census_stat_create_arg; + +/** + Type for representing a single stats result. */ +typedef struct { + const census_tag_set *view; /* Unique tags associated with this result. */ + census_stat_type stat_type; + union { + const census_stat_scalar_result *scalar_result; + const census_stat_distribution_result *distribution_result; + const census_stat_histogram_result *histogram_result; + const census_stat_window_result *window_result; + } +} census_stat_result; + +/** + Generic type for representing a stat "object". +*/ +typdef struct { + census_stat_type stat_type; + union { + census_stat_scalar *scalar; + census_stat_distribution *distribution; + census_stat_histogram *histogram; + census_stat_window *window; + } +} census_stat; + +/** + Structure holding function pointers and associated information needed to + manipulate a statstics "object". Every stats type must provide an instance + of this structure. */ +typedef struct { + /* Create a new statistic. The pointer returned can be used in future calls + to clone_stat(), destroy_stat(), record_stat() and get_stats(). */ + (census_stat *) (*create_stat)(const census_stat_create_arg *create_arg); + /* Create a new statistic, using an existing one as base. */ + (census_stat *) (*clone_stat)(const census_stat *stat); + /* destroy a stats object created by {create,clone}_stat(). */ + (void) (*destroy_stat)(census_stat *stat); + /* Record a new value against a given statistics object instance. */ + (void) (*record_stat)(census_stat *stat, double value); + /* Return current state of a stat. The object returned can be freed by + using destroy_stats_result(). */ + (const census_stat_result *) (*get_stat)(const census_stat *stat); + /* destroy a stats result object, as returned from get_stat(). */ + (void) (*destroy_stats_result)(census_stat_result *result); + /* Reset a stats values. */ + (void) (*reset_stat)(census_stat *stat); +} census_stat; + +gpr_int32 census_define_view(const census_tag_set *view); + +gpr_int32 census_define_stat(gpr_int32 metric_id, gpr_int32 view_id, + const census_stat *stat, + const census_stat_create_arg *create_arg); + +census_stat_result *census_get_stat(gpr_int32 stat_id, gpr_int32 *nstats); + #ifdef __cplusplus } #endif From 6723cc8cf751d137745b304594caa8d124619bce Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Tue, 25 Aug 2015 15:03:03 -0700 Subject: [PATCH 05/33] nc --- include/grpc/census.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/grpc/census.h b/include/grpc/census.h index bc167397b94..db3e89685a4 100644 --- a/include/grpc/census.h +++ b/include/grpc/census.h @@ -187,8 +187,8 @@ typedef enum { the results it provides. The following structures allow us to use a generic type for each of those. - Types referenced (one for each stat type in census_stat_type): -*/ + Types referenced (one for each stat type in census_stat_type, by creation + arguments, output blob, and object representation. */ typedef struct census_stat_scalar_create_arg census_stat_scalar_create_arg; typedef struct census_stat_distribution_create_arg From 9a09982e2dd193a91430ba70ed4e446d8d96e363 Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Thu, 27 Aug 2015 13:16:00 -0700 Subject: [PATCH 06/33] view and aggregation API --- BUILD | 9 +- Makefile | 2 - build.json | 5 +- gRPC.podspec | 7 +- include/grpc/census.h | 236 ++++++++++-------- src/core/census/grpc_filter.c | 31 +-- src/core/census/record_stat.c | 38 --- .../census/{rpc_stat_id.h => rpc_metric_id.h} | 27 +- third_party/openssl | 2 +- tools/doxygen/Doxyfile.core.internal | 3 +- tools/run_tests/sources_and_headers.json | 10 +- vsprojects/grpc/grpc.vcxproj | 4 +- vsprojects/grpc/grpc.vcxproj.filters | 5 +- .../grpc_unsecure/grpc_unsecure.vcxproj | 4 +- .../grpc_unsecure.vcxproj.filters | 5 +- 15 files changed, 182 insertions(+), 206 deletions(-) delete mode 100644 src/core/census/record_stat.c rename src/core/census/{rpc_stat_id.h => rpc_metric_id.h} (69%) diff --git a/BUILD b/BUILD index 25b26b7b244..30721952515 100644 --- a/BUILD +++ b/BUILD @@ -246,7 +246,7 @@ cc_library( "src/core/transport/transport.h", "src/core/transport/transport_impl.h", "src/core/census/context.h", - "src/core/census/rpc_stat_id.h", + "src/core/census/rpc_metric_id.h", "src/core/httpcli/httpcli_security_connector.c", "src/core/security/base64.c", "src/core/security/client_auth_filter.c", @@ -386,7 +386,6 @@ cc_library( "src/core/transport/transport_op_string.c", "src/core/census/context.c", "src/core/census/initialize.c", - "src/core/census/record_stat.c", ], hdrs = [ "include/grpc/grpc_security.h", @@ -515,7 +514,7 @@ cc_library( "src/core/transport/transport.h", "src/core/transport/transport_impl.h", "src/core/census/context.h", - "src/core/census/rpc_stat_id.h", + "src/core/census/rpc_metric_id.h", "src/core/surface/init_unsecure.c", "src/core/census/grpc_context.c", "src/core/census/grpc_filter.c", @@ -635,7 +634,6 @@ cc_library( "src/core/transport/transport_op_string.c", "src/core/census/context.c", "src/core/census/initialize.c", - "src/core/census/record_stat.c", ], hdrs = [ "include/grpc/byte_buffer.h", @@ -1144,7 +1142,6 @@ objc_library( "src/core/transport/transport_op_string.c", "src/core/census/context.c", "src/core/census/initialize.c", - "src/core/census/record_stat.c", ], hdrs = [ "include/grpc/grpc_security.h", @@ -1270,7 +1267,7 @@ objc_library( "src/core/transport/transport.h", "src/core/transport/transport_impl.h", "src/core/census/context.h", - "src/core/census/rpc_stat_id.h", + "src/core/census/rpc_metric_id.h", ], includes = [ "include", diff --git a/Makefile b/Makefile index 48ecea98318..620508c19a4 100644 --- a/Makefile +++ b/Makefile @@ -4196,7 +4196,6 @@ LIBGRPC_SRC = \ src/core/transport/transport_op_string.c \ src/core/census/context.c \ src/core/census/initialize.c \ - src/core/census/record_stat.c \ PUBLIC_HEADERS_C += \ include/grpc/grpc_security.h \ @@ -4470,7 +4469,6 @@ LIBGRPC_UNSECURE_SRC = \ src/core/transport/transport_op_string.c \ src/core/census/context.c \ src/core/census/initialize.c \ - src/core/census/record_stat.c \ PUBLIC_HEADERS_C += \ include/grpc/byte_buffer.h \ diff --git a/build.json b/build.json index 54cae415464..02cee31d082 100644 --- a/build.json +++ b/build.json @@ -19,12 +19,11 @@ ], "headers": [ "src/core/census/context.h", - "src/core/census/rpc_stat_id.h" + "src/core/census/rpc_metric_id.h" ], "src": [ "src/core/census/context.c", - "src/core/census/initialize.c", - "src/core/census/record_stat.c" + "src/core/census/initialize.c" ] }, { diff --git a/gRPC.podspec b/gRPC.podspec index f6d09dbaa62..28a4ad45e0d 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -248,7 +248,7 @@ Pod::Spec.new do |s| 'src/core/transport/transport.h', 'src/core/transport/transport_impl.h', 'src/core/census/context.h', - 'src/core/census/rpc_stat_id.h', + 'src/core/census/rpc_metric_id.h', 'grpc/grpc_security.h', 'grpc/byte_buffer.h', 'grpc/byte_buffer_reader.h', @@ -394,8 +394,7 @@ Pod::Spec.new do |s| 'src/core/transport/transport.c', 'src/core/transport/transport_op_string.c', 'src/core/census/context.c', - 'src/core/census/initialize.c', - 'src/core/census/record_stat.c' + 'src/core/census/initialize.c' ss.private_header_files = 'src/core/support/env.h', 'src/core/support/file.h', @@ -520,7 +519,7 @@ Pod::Spec.new do |s| 'src/core/transport/transport.h', 'src/core/transport/transport_impl.h', 'src/core/census/context.h', - 'src/core/census/rpc_stat_id.h' + 'src/core/census/rpc_metric_id.h' ss.header_mappings_dir = '.' diff --git a/include/grpc/census.h b/include/grpc/census.h index db3e89685a4..968f5825a59 100644 --- a/include/grpc/census.h +++ b/include/grpc/census.h @@ -159,114 +159,154 @@ int census_tag_set_next(census_tag_set_iterator *it, census_tag_const *tag); invalidated, and should not be used once close is called. */ void census_tag_set_close(census_tag_set_iterator *it); -/* A census statistic to be recorded comprises two parts: an ID for the - * particular statistic and the value to be recorded against it. */ +/* Core stats collection API's. There following concepts are used: + * Aggregation: A collection of values. Census supports the following + aggregation types: + Scalar - a single scalar value. Typically used for keeping (e.g.) + counts of events. + Distribution - statistical distribution information, used for + recording average, standard deviation etc. + Histogram - a histogram of measurements falling in defined bucket + boundaries. + Window - a count of events that happen in reolling time window. + New aggregation types can be added by the user, if desired (see + census_register_aggregation()). + * Metric: Each measurement is for a single metric. Examples include RPC + latency, CPU seconds consumed, and bytes transmitted. + * View: A view is a tag set, in which the tag values are regular expressions, + combined with an arbitrary number of aggregations and their initialization + parameters. + + Each metric can have an arbitrary number of views by which it will be + broken down. For every measurement recorded, they are broken down by + unique tag combinations, and recorded in each matvhing view/aggregation. +*/ + +/* A single value to be recorded comprises two parts: an ID for the particular + * metric and the value to be recorded against it. */ typedef struct { - int id; + gpr_int32 metric_id; double value; -} census_stat; +} census_value; + +/* Record new usage values against the given context. */ +void census_record_usage(census_context *context, census_value *values, + size_t nvalues); + +/** Structure used to describe an aggregation type. */ +typedef struct { + /* Create a new aggregation. The pointer returned can be used in future calls + to free(), record(), data() and reset(). */ + void *(*create)(const void *create_arg); + /* Destroy an aggregation created by create() */ + void (*free)(void *aggregation); + /* Record a new value against aggregation. */ + void (*record)(void *aggregation, double value); + /* Return current aggregation data. The caller must cast this object into + the correct type for the aggregation result. The object returned can be + freed by using free_data(). */ + const void *(*data)(const void *aggregation); + /* destroy an aggregation result eturned from get_aggregation(). */ + void (*free_data)(const void *data); + /* Reset an aggregation to default (zero) values. */ + void (*reset)(void *aggregation); +} census_aggregation_descriptor; + +/** Register a new aggregation type. + @param descriptor Describes aggregation + @return An identifier that can be used to identify the aggregation in other + census functions. */ +gpr_int32 census_register_aggregation( + const census_aggregation_descriptor *descriptor); + +/* Aggregation Identifiers for built-in census aggregations. */ +#define CENSUS_AGGREGATION_ID_SCALAR ((gpr_int32)0) +#define CENSUS_AGGREGATION_ID_DISTRIBUTION ((gpr_int32)1) +#define CENSUS_AGGREGATION_ID_HISTOGRAM ((gpr_int32)2) +#define CENSUS_AGGREGATION_ID_WINDOW ((gpr_int32)3) + +/** Information needed to instantiate a new aggregation. Used in view + construction via census_define_view(). */ +typedef struct { + gpr_int32 id; /* aggregation ID */ + const void + *create_arg; /* Argument to be used for aggregation initialization. */ +} census_aggregation; -/* Record new stats against the given context. */ -void census_record_stat(census_context *context, census_stat *stats, - size_t nstats); +/** Type representing a single view. */ +typedef struct census_view census_view; -/* Stats Configuration - Census clients can use these functions and structures - to extend and define what stats get recorded for what measurements. */ +/** Create a new view. + @param tags tags that define the view + @param aggregations aggregations to associate with the view + @param naggregations number of aggregations -/** Stats types supported by census. */ -typedef enum { - CENSUS_STAT_SCALAR = 0, /* Simple scalar */ - CENSUS_STAT_DISTRIBUTION = 1, /* count, average, variance */ - CENSUS_STAT_HISTOGRAM = 2, /* Histogram. */ - CENSUS_STAT_WINDOW = 3, /* Count over a time window. */ - CENSUS_STAT_NSTATS = 4 /* Total number of stats types. */ -} census_stat_type; + @return A new census view +*/ +const census_view *census_define_view(const census_tag_set *tags, + const census_aggregation *aggregations, + size_t naggregations); -/* - Each stats type differs in how it is initialized, how it is represented, and - the results it provides. The following structures allow us to use a generic - type for each of those. - - Types referenced (one for each stat type in census_stat_type, by creation - arguments, output blob, and object representation. */ - -typedef struct census_stat_scalar_create_arg census_stat_scalar_create_arg; -typedef struct census_stat_distribution_create_arg - census_stat_distribution_create_arg; -typedef struct census_stat_histogram_create_arg - census_stat_histogram_create_arg; -typedef struct census_stat_window_create_arg census_stat_window_create_arg; - -/** - Type for representing information to construct a new instance of a given - stats type (e.g. histogram bucket boundaries). +/** Number of aggregations associated with view. */ +size_t census_view_naggregations(const census_view *view); + +/** Get tags associated with view. */ +const census_tag_set *census_view_tags(const census_view *view); + +/** Get aggregations associated with a view. */ +const census_aggregation *census_view_aggregrations(const census_view *view); + +/** Associate a given view with a metric. Every metric can have many different + views. + @param metric_id Identifier of metric with which to attah the view + @param view View to attach to the metric + @return A view identifier: can be used to retrieve aggregation data from + the view using census_view_data(). */ +gpr_int64 census_attach_view(gpr_int32 metric_id, const census_view *view); + +/** Holds aggregation data, as it applies to a particular view. This structure + is used as one component of the data returned from census_get_view_data(). */ typedef struct { - census_stat_type stat_type; /* The "real" type of the stat. */ - union { - const census_stat_scalar_create_arg *scalar_arg; - const census_stat_distribution_create_arg *distribution_arg; - const census_stat_histogram_create_arg *histogram_arg; - const census_stat_window_create_arg *window_arg; - } -} census_stat_create_arg; - -/** - Type for representing a single stats result. */ + /** Aggregation index in original view. Use as (e.g.) + census_view_aggregations(view)[index] to get the original + census_aggregation structure. */ + size_t index; + /** Data as returned from the data() function for the relevant + aggregation descriptor. It is the user responsibility to cast this to the + correct type for the aggregation. */ + void *data; +} census_aggregation_data; + +/** Holds all the aggregation data for a particular view instantiation. Forms + part of the data returned by census_get_view_data(). */ typedef struct { - const census_tag_set *view; /* Unique tags associated with this result. */ - census_stat_type stat_type; - union { - const census_stat_scalar_result *scalar_result; - const census_stat_distribution_result *distribution_result; - const census_stat_histogram_result *histogram_result; - const census_stat_window_result *window_result; - } -} census_stat_result; - -/** - Generic type for representing a stat "object". -*/ -typdef struct { - census_stat_type stat_type; - union { - census_stat_scalar *scalar; - census_stat_distribution *distribution; - census_stat_histogram *histogram; - census_stat_window *window; - } -} census_stat; - -/** - Structure holding function pointers and associated information needed to - manipulate a statstics "object". Every stats type must provide an instance - of this structure. */ + const census_tag_set *tags; /* Tags for this set of aggregations */ + size_t naggregations; /* Number of aggregations in data. */ + const census_aggregation_data *data; /* Aggregation data */ +} census_view_aggregation_data; + +/** Census view data as returned by census_get_view_data(). */ typedef struct { - /* Create a new statistic. The pointer returned can be used in future calls - to clone_stat(), destroy_stat(), record_stat() and get_stats(). */ - (census_stat *) (*create_stat)(const census_stat_create_arg *create_arg); - /* Create a new statistic, using an existing one as base. */ - (census_stat *) (*clone_stat)(const census_stat *stat); - /* destroy a stats object created by {create,clone}_stat(). */ - (void) (*destroy_stat)(census_stat *stat); - /* Record a new value against a given statistics object instance. */ - (void) (*record_stat)(census_stat *stat, double value); - /* Return current state of a stat. The object returned can be freed by - using destroy_stats_result(). */ - (const census_stat_result *) (*get_stat)(const census_stat *stat); - /* destroy a stats result object, as returned from get_stat(). */ - (void) (*destroy_stats_result)(census_stat_result *result); - /* Reset a stats values. */ - (void) (*reset_stat)(census_stat *stat); -} census_stat; - -gpr_int32 census_define_view(const census_tag_set *view); - -gpr_int32 census_define_stat(gpr_int32 metric_id, gpr_int32 view_id, - const census_stat *stat, - const census_stat_create_arg *create_arg); - -census_stat_result *census_get_stat(gpr_int32 stat_id, gpr_int32 *nstats); + const census_view *view; /* Original view */ + size_t n_tag_sets; /* Number of unique tag sets that matched view. */ + const census_view_aggregation_data *data; /* n_tag_sets entries */ +} census_view_data; + +/** Get data from aggregations associated with a view. + @param view_id View identifier returned from census_attach_view + @param aggregation_indices Indexes of aggregations (relative to original view) + for which to return current data. This parameter is ignored if + nindices == 0. + @param nindices. Number of entries in aggregation_indices. If this is set to + 0, then all aggregations for the current view are returned. +*/ +const census_view_data *census_get_view_data(gpr_int64 view_id, + size_t *aggregation_indices, + size_t nindices); + +/** Reset all view data to zero for the specified view id. */ +void census_reset_view_data(gpr_int64 view_id); #ifdef __cplusplus } diff --git a/src/core/census/grpc_filter.c b/src/core/census/grpc_filter.c index fbedb35661f..45b5656e3c2 100644 --- a/src/core/census/grpc_filter.c +++ b/src/core/census/grpc_filter.c @@ -37,7 +37,6 @@ #include #include "include/grpc/census.h" -#include "src/core/census/rpc_stat_id.h" #include "src/core/channel/channel_stack.h" #include "src/core/channel/noop_filter.h" #include "src/core/statistics/census_interface.h" @@ -173,25 +172,15 @@ static void destroy_channel_elem(grpc_channel_element* elem) { } const grpc_channel_filter grpc_client_census_filter = { - client_start_transport_op, - grpc_channel_next_op, - sizeof(call_data), - client_init_call_elem, - client_destroy_call_elem, - sizeof(channel_data), - init_channel_elem, - destroy_channel_elem, - grpc_call_next_get_peer, - "census-client"}; + client_start_transport_op, grpc_channel_next_op, + sizeof(call_data), client_init_call_elem, + client_destroy_call_elem, sizeof(channel_data), + init_channel_elem, destroy_channel_elem, + grpc_call_next_get_peer, "census-client"}; const grpc_channel_filter grpc_server_census_filter = { - server_start_transport_op, - grpc_channel_next_op, - sizeof(call_data), - server_init_call_elem, - server_destroy_call_elem, - sizeof(channel_data), - init_channel_elem, - destroy_channel_elem, - grpc_call_next_get_peer, - "census-server"}; + server_start_transport_op, grpc_channel_next_op, + sizeof(call_data), server_init_call_elem, + server_destroy_call_elem, sizeof(channel_data), + init_channel_elem, destroy_channel_elem, + grpc_call_next_get_peer, "census-server"}; diff --git a/src/core/census/record_stat.c b/src/core/census/record_stat.c deleted file mode 100644 index 3dd918618b6..00000000000 --- a/src/core/census/record_stat.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * Copyright 2015, Google Inc. - * All rights reserved. - * - * 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. - * - */ - -#include -#include "src/core/census/rpc_stat_id.h" - -void census_record_stat(census_context *context, census_stat *stats, - size_t nstats) {} diff --git a/src/core/census/rpc_stat_id.h b/src/core/census/rpc_metric_id.h similarity index 69% rename from src/core/census/rpc_stat_id.h rename to src/core/census/rpc_metric_id.h index fc0aa6f43f6..2cd30c2fc09 100644 --- a/src/core/census/rpc_stat_id.h +++ b/src/core/census/rpc_metric_id.h @@ -31,16 +31,21 @@ * */ -#ifndef CENSUS_RPC_STAT_ID_H -#define CENSUS_RPC_STAT_ID_H +#ifndef CENSUS_RPC_METRIC_ID_H +#define CENSUS_RPC_METRIC_ID_H -/* Stats ID's used for RPC measurements. */ -#define CENSUS_INVALID_STAT_ID 0 /* ID 0 is always invalid */ -#define CENSUS_RPC_CLIENT_REQUESTS 1 /* Count of client requests sent. */ -#define CENSUS_RPC_SERVER_REQUESTS 2 /* Count of server requests sent. */ -#define CENSUS_RPC_CLIENT_ERRORS 3 /* Client error counts. */ -#define CENSUS_RPC_SERVER_ERRORS 4 /* Server error counts. */ -#define CENSUS_RPC_CLIENT_LATENCY 5 /* Client side request latency. */ -#define CENSUS_RPC_SERVER_LATENCY 6 /* Server side request latency. */ +/* Metric ID's used for RPC measurements. */ +/* Count of client requests sent. */ +#define CENSUS_METRIC_RPC_CLIENT_REQUESTS ((gpr_int32)0) +/* Count of server requests sent. */ +#define CENSUS_METRIC_RPC_SERVER_REQUESTS ((gpr_int32)1) +/* Client error counts. */ +#define CENSUS_METRIC_RPC_CLIENT_ERRORS ((gpr_int32)2) +/* Server error counts. */ +#define CENSUS_METRIC_RPC_SERVER_ERRORS ((gpr_int32)3) +/* Client side request latency. */ +#define CENSUS_METRIC_RPC_CLIENT_LATENCY ((gpr_int32)4) +/* Server side request latency. */ +#define CENSUS_METRIC_RPC_SERVER_LATENCY ((gpr_int32)5) -#endif /* CENSUS_RPC_STAT_ID_H */ +#endif /* CENSUS_RPC_METRIC_ID_H */ diff --git a/third_party/openssl b/third_party/openssl index 33dd0832064..3df69d3aefd 160000 --- a/third_party/openssl +++ b/third_party/openssl @@ -1 +1 @@ -Subproject commit 33dd08320648ac71d7d9d732be774ed3818dccc5 +Subproject commit 3df69d3aefde7671053d4e3c242b228e5d79c83f diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 06f0f4ee834..1fe43efe46a 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -883,7 +883,7 @@ src/core/transport/stream_op.h \ src/core/transport/transport.h \ src/core/transport/transport_impl.h \ src/core/census/context.h \ -src/core/census/rpc_stat_id.h \ +src/core/census/rpc_metric_id.h \ src/core/httpcli/httpcli_security_connector.c \ src/core/security/base64.c \ src/core/security/client_auth_filter.c \ @@ -1023,7 +1023,6 @@ src/core/transport/transport.c \ src/core/transport/transport_op_string.c \ src/core/census/context.c \ src/core/census/initialize.c \ -src/core/census/record_stat.c \ include/grpc/support/alloc.h \ include/grpc/support/atm.h \ include/grpc/support/atm_gcc_atomic.h \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index c7df23a7c4d..e8cd3ef1bf8 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -12265,7 +12265,7 @@ "include/grpc/status.h", "src/core/census/context.h", "src/core/census/grpc_filter.h", - "src/core/census/rpc_stat_id.h", + "src/core/census/rpc_metric_id.h", "src/core/channel/channel_args.h", "src/core/channel/channel_stack.h", "src/core/channel/client_channel.h", @@ -12397,8 +12397,7 @@ "src/core/census/grpc_filter.c", "src/core/census/grpc_filter.h", "src/core/census/initialize.c", - "src/core/census/record_stat.c", - "src/core/census/rpc_stat_id.h", + "src/core/census/rpc_metric_id.h", "src/core/channel/channel_args.c", "src/core/channel/channel_args.h", "src/core/channel/channel_stack.c", @@ -12744,7 +12743,7 @@ "include/grpc/status.h", "src/core/census/context.h", "src/core/census/grpc_filter.h", - "src/core/census/rpc_stat_id.h", + "src/core/census/rpc_metric_id.h", "src/core/channel/channel_args.h", "src/core/channel/channel_stack.h", "src/core/channel/client_channel.h", @@ -12862,8 +12861,7 @@ "src/core/census/grpc_filter.c", "src/core/census/grpc_filter.h", "src/core/census/initialize.c", - "src/core/census/record_stat.c", - "src/core/census/rpc_stat_id.h", + "src/core/census/rpc_metric_id.h", "src/core/channel/channel_args.c", "src/core/channel/channel_args.h", "src/core/channel/channel_stack.c", diff --git a/vsprojects/grpc/grpc.vcxproj b/vsprojects/grpc/grpc.vcxproj index b17eea9235d..fdb637b590e 100644 --- a/vsprojects/grpc/grpc.vcxproj +++ b/vsprojects/grpc/grpc.vcxproj @@ -345,7 +345,7 @@ - + @@ -626,8 +626,6 @@ - - diff --git a/vsprojects/grpc/grpc.vcxproj.filters b/vsprojects/grpc/grpc.vcxproj.filters index a955e9e9934..10ec6e62039 100644 --- a/vsprojects/grpc/grpc.vcxproj.filters +++ b/vsprojects/grpc/grpc.vcxproj.filters @@ -418,9 +418,6 @@ src\core\census - - src\core\census - @@ -794,7 +791,7 @@ src\core\census - + src\core\census diff --git a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj index a692c48f81d..93e1e0fc292 100644 --- a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj @@ -328,7 +328,7 @@ - + @@ -569,8 +569,6 @@ - - diff --git a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters index 1c4036d464b..ed0896c81a0 100644 --- a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -358,9 +358,6 @@ src\core\census - - src\core\census - @@ -692,7 +689,7 @@ src\core\census - + src\core\census From e62f68cebb8a43f880542035ef8b3369ebb46f6b Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Thu, 27 Aug 2015 16:24:27 -0700 Subject: [PATCH 07/33] make metric part of view --- include/grpc/census.h | 59 ++++++++++++++++----------------- src/core/census/rpc_metric_id.h | 12 +++---- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/include/grpc/census.h b/include/grpc/census.h index 968f5825a59..77b93c1cb86 100644 --- a/include/grpc/census.h +++ b/include/grpc/census.h @@ -159,7 +159,7 @@ int census_tag_set_next(census_tag_set_iterator *it, census_tag_const *tag); invalidated, and should not be used once close is called. */ void census_tag_set_close(census_tag_set_iterator *it); -/* Core stats collection API's. There following concepts are used: +/* Core stats collection API's. The following concepts are used: * Aggregation: A collection of values. Census supports the following aggregation types: Scalar - a single scalar value. Typically used for keeping (e.g.) @@ -174,18 +174,18 @@ void census_tag_set_close(census_tag_set_iterator *it); * Metric: Each measurement is for a single metric. Examples include RPC latency, CPU seconds consumed, and bytes transmitted. * View: A view is a tag set, in which the tag values are regular expressions, - combined with an arbitrary number of aggregations and their initialization - parameters. + combined with a metric and an arbitrary number of aggregations and their + initialization parameters. Each metric can have an arbitrary number of views by which it will be broken down. For every measurement recorded, they are broken down by - unique tag combinations, and recorded in each matvhing view/aggregation. + unique tag combinations, and recorded in each matching view/aggregation. */ /* A single value to be recorded comprises two parts: an ID for the particular * metric and the value to be recorded against it. */ typedef struct { - gpr_int32 metric_id; + gpr_uint32 metric_id; double value; } census_value; @@ -210,25 +210,30 @@ typedef struct { void (*free_data)(const void *data); /* Reset an aggregation to default (zero) values. */ void (*reset)(void *aggregation); + /* Merge 'from' aggregation into 'to'. Both aggregations must be compatible */ + void (*merge)(void *to, const void *from); + /* Fill buffer with printable string version of aggregation contents. For + * debugging only. */ + void (*print)(const void *aggregation, char *buffer, size_t n); } census_aggregation_descriptor; /** Register a new aggregation type. @param descriptor Describes aggregation @return An identifier that can be used to identify the aggregation in other census functions. */ -gpr_int32 census_register_aggregation( +gpr_uint32 census_register_aggregation( const census_aggregation_descriptor *descriptor); /* Aggregation Identifiers for built-in census aggregations. */ -#define CENSUS_AGGREGATION_ID_SCALAR ((gpr_int32)0) -#define CENSUS_AGGREGATION_ID_DISTRIBUTION ((gpr_int32)1) -#define CENSUS_AGGREGATION_ID_HISTOGRAM ((gpr_int32)2) -#define CENSUS_AGGREGATION_ID_WINDOW ((gpr_int32)3) +#define CENSUS_AGGREGATION_ID_SCALAR ((gpr_uint32)0) +#define CENSUS_AGGREGATION_ID_DISTRIBUTION ((gpr_uint32)1) +#define CENSUS_AGGREGATION_ID_HISTOGRAM ((gpr_uint32)2) +#define CENSUS_AGGREGATION_ID_WINDOW ((gpr_uint32)3) /** Information needed to instantiate a new aggregation. Used in view construction via census_define_view(). */ typedef struct { - gpr_int32 id; /* aggregation ID */ + gpr_uint32 id; /* aggregation ID */ const void *create_arg; /* Argument to be used for aggregation initialization. */ } census_aggregation; @@ -237,16 +242,21 @@ typedef struct { typedef struct census_view census_view; /** Create a new view. + @param metric_id Metric with which this view is associated. @param tags tags that define the view @param aggregations aggregations to associate with the view @param naggregations number of aggregations @return A new census view */ -const census_view *census_define_view(const census_tag_set *tags, +const census_view *census_define_view(gpr_uint32 metric_id, + const census_tag_set *tags, const census_aggregation *aggregations, size_t naggregations); +/** Metric ID associated with a view */ +size_t census_view_metric(const census_view *view); + /** Number of aggregations associated with view. */ size_t census_view_naggregations(const census_view *view); @@ -256,15 +266,6 @@ const census_tag_set *census_view_tags(const census_view *view); /** Get aggregations associated with a view. */ const census_aggregation *census_view_aggregrations(const census_view *view); -/** Associate a given view with a metric. Every metric can have many different - views. - @param metric_id Identifier of metric with which to attah the view - @param view View to attach to the metric - @return A view identifier: can be used to retrieve aggregation data from - the view using census_view_data(). -*/ -gpr_int64 census_attach_view(gpr_int32 metric_id, const census_view *view); - /** Holds aggregation data, as it applies to a particular view. This structure is used as one component of the data returned from census_get_view_data(). */ typedef struct { @@ -288,25 +289,23 @@ typedef struct { /** Census view data as returned by census_get_view_data(). */ typedef struct { - const census_view *view; /* Original view */ - size_t n_tag_sets; /* Number of unique tag sets that matched view. */ + size_t n_tag_sets; /* Number of unique tag sets that matched view. */ const census_view_aggregation_data *data; /* n_tag_sets entries */ } census_view_data; /** Get data from aggregations associated with a view. - @param view_id View identifier returned from census_attach_view - @param aggregation_indices Indexes of aggregations (relative to original view) - for which to return current data. This parameter is ignored if - nindices == 0. + @param view View from which to get data. + @param aggregation_indices Indexes of view aggregations for which to return + current data. This parameter is ignored if nindices == 0. @param nindices. Number of entries in aggregation_indices. If this is set to - 0, then all aggregations for the current view are returned. + 0, then all aggregations are returned. */ -const census_view_data *census_get_view_data(gpr_int64 view_id, +const census_view_data *census_get_view_data(census_view *view, size_t *aggregation_indices, size_t nindices); /** Reset all view data to zero for the specified view id. */ -void census_reset_view_data(gpr_int64 view_id); +void census_reset_view_data(gpr_uint64 view_id); #ifdef __cplusplus } diff --git a/src/core/census/rpc_metric_id.h b/src/core/census/rpc_metric_id.h index 2cd30c2fc09..1d8e8806f50 100644 --- a/src/core/census/rpc_metric_id.h +++ b/src/core/census/rpc_metric_id.h @@ -36,16 +36,16 @@ /* Metric ID's used for RPC measurements. */ /* Count of client requests sent. */ -#define CENSUS_METRIC_RPC_CLIENT_REQUESTS ((gpr_int32)0) +#define CENSUS_METRIC_RPC_CLIENT_REQUESTS ((gpr_uint32)0) /* Count of server requests sent. */ -#define CENSUS_METRIC_RPC_SERVER_REQUESTS ((gpr_int32)1) +#define CENSUS_METRIC_RPC_SERVER_REQUESTS ((gpr_uint32)1) /* Client error counts. */ -#define CENSUS_METRIC_RPC_CLIENT_ERRORS ((gpr_int32)2) +#define CENSUS_METRIC_RPC_CLIENT_ERRORS ((gpr_uint32)2) /* Server error counts. */ -#define CENSUS_METRIC_RPC_SERVER_ERRORS ((gpr_int32)3) +#define CENSUS_METRIC_RPC_SERVER_ERRORS ((gpr_uint32)3) /* Client side request latency. */ -#define CENSUS_METRIC_RPC_CLIENT_LATENCY ((gpr_int32)4) +#define CENSUS_METRIC_RPC_CLIENT_LATENCY ((gpr_uint32)4) /* Server side request latency. */ -#define CENSUS_METRIC_RPC_SERVER_LATENCY ((gpr_int32)5) +#define CENSUS_METRIC_RPC_SERVER_LATENCY ((gpr_uint32)5) #endif /* CENSUS_RPC_METRIC_ID_H */ From b8552024179a2910f10d916e69495779271f9344 Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Fri, 28 Aug 2015 10:54:17 -0700 Subject: [PATCH 08/33] rewrite to reviewer comments --- include/grpc/census.h | 98 ++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 61 deletions(-) diff --git a/include/grpc/census.h b/include/grpc/census.h index 77b93c1cb86..3fd8266acd5 100644 --- a/include/grpc/census.h +++ b/include/grpc/census.h @@ -173,13 +173,11 @@ void census_tag_set_close(census_tag_set_iterator *it); census_register_aggregation()). * Metric: Each measurement is for a single metric. Examples include RPC latency, CPU seconds consumed, and bytes transmitted. - * View: A view is a tag set, in which the tag values are regular expressions, - combined with a metric and an arbitrary number of aggregations and their - initialization parameters. - - Each metric can have an arbitrary number of views by which it will be - broken down. For every measurement recorded, they are broken down by - unique tag combinations, and recorded in each matching view/aggregation. + * View: A view is a combination of a metric, a tag set (in which the tag + values are regular expressions) and a set of aggregations. When a + measurement for a metric matches the view tags, it is recorded (for each + unique set of tags) against each aggregation. Each metric can have an + arbitrary number of views by which it will be broken down. */ /* A single value to be recorded comprises two parts: an ID for the particular @@ -190,8 +188,8 @@ typedef struct { } census_value; /* Record new usage values against the given context. */ -void census_record_usage(census_context *context, census_value *values, - size_t nvalues); +void census_record(census_context *context, census_value *values, + size_t nvalues); /** Structure used to describe an aggregation type. */ typedef struct { @@ -206,39 +204,33 @@ typedef struct { the correct type for the aggregation result. The object returned can be freed by using free_data(). */ const void *(*data)(const void *aggregation); - /* destroy an aggregation result eturned from get_aggregation(). */ + /* free data returned by data() */ void (*free_data)(const void *data); /* Reset an aggregation to default (zero) values. */ void (*reset)(void *aggregation); /* Merge 'from' aggregation into 'to'. Both aggregations must be compatible */ void (*merge)(void *to, const void *from); /* Fill buffer with printable string version of aggregation contents. For - * debugging only. */ - void (*print)(const void *aggregation, char *buffer, size_t n); -} census_aggregation_descriptor; - -/** Register a new aggregation type. - @param descriptor Describes aggregation - @return An identifier that can be used to identify the aggregation in other - census functions. */ -gpr_uint32 census_register_aggregation( - const census_aggregation_descriptor *descriptor); + debugging only. Returns the number of bytes added to buffer (a value == n + implies the buffer was of insufficient size). */ + size_t (*print)(const void *aggregation, char *buffer, size_t n); +} census_aggregation; -/* Aggregation Identifiers for built-in census aggregations. */ -#define CENSUS_AGGREGATION_ID_SCALAR ((gpr_uint32)0) -#define CENSUS_AGGREGATION_ID_DISTRIBUTION ((gpr_uint32)1) -#define CENSUS_AGGREGATION_ID_HISTOGRAM ((gpr_uint32)2) -#define CENSUS_AGGREGATION_ID_WINDOW ((gpr_uint32)3) +/* Predefined aggregation types. */ +extern census_aggregation census_agg_scalar; +extern census_aggregation census_agg_distribution; +extern census_aggregation census_agg_histogram; +extern census_aggregation census_agg_window; /** Information needed to instantiate a new aggregation. Used in view construction via census_define_view(). */ typedef struct { - gpr_uint32 id; /* aggregation ID */ + const census_aggregation *aggregation; const void *create_arg; /* Argument to be used for aggregation initialization. */ -} census_aggregation; +} census_aggregation_descriptor; -/** Type representing a single view. */ +/** A census view type. Opaque. */ typedef struct census_view census_view; /** Create a new view. @@ -249,10 +241,12 @@ typedef struct census_view census_view; @return A new census view */ -const census_view *census_define_view(gpr_uint32 metric_id, - const census_tag_set *tags, - const census_aggregation *aggregations, - size_t naggregations); +census_view *census_view_create( + gpr_uint32 metric_id, const census_tag_set *tags, + const census_aggregation_descriptor *aggregations, size_t naggregations); + +/** Destroy a previously created view. */ +void census_view_delete(census_view *view); /** Metric ID associated with a view */ size_t census_view_metric(const census_view *view); @@ -263,31 +257,18 @@ size_t census_view_naggregations(const census_view *view); /** Get tags associated with view. */ const census_tag_set *census_view_tags(const census_view *view); -/** Get aggregations associated with a view. */ -const census_aggregation *census_view_aggregrations(const census_view *view); - -/** Holds aggregation data, as it applies to a particular view. This structure - is used as one component of the data returned from census_get_view_data(). */ -typedef struct { - /** Aggregation index in original view. Use as (e.g.) - census_view_aggregations(view)[index] to get the original - census_aggregation structure. */ - size_t index; - /** Data as returned from the data() function for the relevant - aggregation descriptor. It is the user responsibility to cast this to the - correct type for the aggregation. */ - void *data; -} census_aggregation_data; +/** Get aggregation descriptors associated with a view. */ +const census_aggregation_descriptor *census_view_aggregrations( + const census_view *view); /** Holds all the aggregation data for a particular view instantiation. Forms - part of the data returned by census_get_view_data(). */ + part of the data returned by census_view_data(). */ typedef struct { - const census_tag_set *tags; /* Tags for this set of aggregations */ - size_t naggregations; /* Number of aggregations in data. */ - const census_aggregation_data *data; /* Aggregation data */ + const census_tag_set *tags; /* Tags for this set of aggregations. */ + const void **data; /* One data set for every aggregation in the view. */ } census_view_aggregation_data; -/** Census view data as returned by census_get_view_data(). */ +/** Census view data as returned by census_view_get_data(). */ typedef struct { size_t n_tag_sets; /* Number of unique tag sets that matched view. */ const census_view_aggregation_data *data; /* n_tag_sets entries */ @@ -295,17 +276,12 @@ typedef struct { /** Get data from aggregations associated with a view. @param view View from which to get data. - @param aggregation_indices Indexes of view aggregations for which to return - current data. This parameter is ignored if nindices == 0. - @param nindices. Number of entries in aggregation_indices. If this is set to - 0, then all aggregations are returned. + @return Full set of data for all aggregations for the view. */ -const census_view_data *census_get_view_data(census_view *view, - size_t *aggregation_indices, - size_t nindices); +const census_view_data *census_view_get_data(const census_view *view); -/** Reset all view data to zero for the specified view id. */ -void census_reset_view_data(gpr_uint64 view_id); +/** Reset all view data to zero for the specified view */ +void census_view_reset(census_view *view); #ifdef __cplusplus } From 75d04da2e4d31753c9d8a8bb46a7260e3e44484b Mon Sep 17 00:00:00 2001 From: yang-g Date: Fri, 28 Aug 2015 14:17:33 -0700 Subject: [PATCH 09/33] sync up with CreateChannel API change --- examples/cpp/helloworld/greeter_async_client.cc | 2 +- examples/cpp/helloworld/greeter_client.cc | 3 +-- examples/cpp/route_guide/route_guide_client.cc | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/cpp/helloworld/greeter_async_client.cc b/examples/cpp/helloworld/greeter_async_client.cc index d99f89b1359..bc95c54e06b 100644 --- a/examples/cpp/helloworld/greeter_async_client.cc +++ b/examples/cpp/helloworld/greeter_async_client.cc @@ -89,7 +89,7 @@ class GreeterClient { int main(int argc, char** argv) { GreeterClient greeter(grpc::CreateChannel( - "localhost:50051", grpc::InsecureCredentials(), ChannelArguments())); + "localhost:50051", grpc::InsecureCredentials())); std::string user("world"); std::string reply = greeter.SayHello(user); std::cout << "Greeter received: " << reply << std::endl; diff --git a/examples/cpp/helloworld/greeter_client.cc b/examples/cpp/helloworld/greeter_client.cc index dd0358ac95d..2b542cd8349 100644 --- a/examples/cpp/helloworld/greeter_client.cc +++ b/examples/cpp/helloworld/greeter_client.cc @@ -75,8 +75,7 @@ class GreeterClient { int main(int argc, char** argv) { GreeterClient greeter( - grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(), - ChannelArguments())); + grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials())); std::string user("world"); std::string reply = greeter.SayHello(user); std::cout << "Greeter received: " << reply << std::endl; diff --git a/examples/cpp/route_guide/route_guide_client.cc b/examples/cpp/route_guide/route_guide_client.cc index 814def27f35..fe998079c40 100644 --- a/examples/cpp/route_guide/route_guide_client.cc +++ b/examples/cpp/route_guide/route_guide_client.cc @@ -235,8 +235,7 @@ int main(int argc, char** argv) { // Expect only arg: --db_path=path/to/route_guide_db.json. std::string db = examples::GetDbFileContent(argc, argv); RouteGuideClient guide( - grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(), - ChannelArguments()), + grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials()), db); std::cout << "-------------- GetFeature --------------" << std::endl; From b00a3f689fef00f029589f52b3dda2272deb7914 Mon Sep 17 00:00:00 2001 From: yang-g Date: Fri, 28 Aug 2015 14:19:37 -0700 Subject: [PATCH 10/33] fix links in docs --- examples/cpp/README.md | 11 +++++------ examples/cpp/cpptutorial.md | 12 ++++++------ examples/cpp/helloworld/README.md | 12 ++++++------ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/examples/cpp/README.md b/examples/cpp/README.md index 70418b44253..85c495099b7 100644 --- a/examples/cpp/README.md +++ b/examples/cpp/README.md @@ -2,12 +2,11 @@ ## Installation -To install gRPC on your system, follow the instructions here: -[https://github.com/grpc/grpc/blob/master/INSTALL](https://github.com/grpc/grpc/blob/master/INSTALL). +To install gRPC on your system, follow the instructions [here](../../INSTALL). ## Hello C++ gRPC! -Here's how to build and run the C++ implementation of the [Hello World](examples/protos/helloworld.proto) example used in [Getting started](https://github.com/grpc/grpc/tree/master/examples). +Here's how to build and run the C++ implementation of the [Hello World](../protos/helloworld.proto) example used in [Getting started](..). The example code for this and our other examples lives in the `examples` directory. Clone this repository to your local machine by running the @@ -41,9 +40,9 @@ $ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto ### Client and server implementations -The client implementation is at [greeter_client.cc](examples/cpp/helloworld/greeter_client.cc). +The client implementation is at [greeter_client.cc](helloworld/greeter_client.cc). -The server implementation is at [greeter_server.cc](examples/cpp/helloworld/greeter_server.cc). +The server implementation is at [greeter_server.cc](helloworld/greeter_server.cc). ### Try it! Build client and server: @@ -62,4 +61,4 @@ If things go smoothly, you will see the "Greeter received: Hello world" in the c ## Tutorial -You can find a more detailed tutorial in [gRPC Basics: C++](examples/cpp/cpptutorial.md) +You can find a more detailed tutorial in [gRPC Basics: C++](cpptutorial.md) diff --git a/examples/cpp/cpptutorial.md b/examples/cpp/cpptutorial.md index 22be42d500d..a23633d83cd 100644 --- a/examples/cpp/cpptutorial.md +++ b/examples/cpp/cpptutorial.md @@ -6,7 +6,7 @@ This tutorial provides a basic C++ programmer's introduction to working with gRP - Generate server and client code using the protocol buffer compiler. - Use the C++ gRPC API to write a simple client and server for your service. -It assumes that you have read the [Getting started](https://github.com/grpc/grpc/tree/master/examples) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto3 version of the protocol buffers language, which is currently in alpha release: you can find out more in the [proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3) and see the [release notes](https://github.com/google/protobuf/releases) for the new version in the protocol buffers Github repository. +It assumes that you have read the [Getting started](..) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto3 version of the protocol buffers language, which is currently in alpha release: you can find out more in the [proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3) and see the [release notes](https://github.com/google/protobuf/releases) for the new version in the protocol buffers Github repository. This isn't a comprehensive guide to using gRPC in C++: more reference documentation is coming soon. @@ -18,7 +18,7 @@ With gRPC we can define our service once in a .proto file and implement clients ## Example code and setup -The example code for our tutorial is in [examples/cpp/route_guide](examples/cpp/route_guide). To download the example, clone this repository by running the following command: +The example code for our tutorial is in [examples/cpp/route_guide](route_guide). To download the example, clone this repository by running the following command: ```shell $ git clone https://github.com/grpc/grpc.git ``` @@ -33,7 +33,7 @@ You also should have the relevant tools installed to generate the server and cli ## Defining the service -Our first step (as you'll know from [Getting started](examples/) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto). +Our first step (as you'll know from [Getting started](..) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](../protos/route_guide.proto). To define a service, you specify a named `service` in your .proto file: @@ -91,7 +91,7 @@ message Point { Next we need to generate the gRPC client and server interfaces from our .proto service definition. We do this using the protocol buffer compiler `protoc` with a special gRPC C++ plugin. -For simplicity, we've provided a [makefile](examples/cpp/route_guide/Makefile) that runs `protoc` for you with the appropriate plugin, input, and output (if you want to run this yourself, make sure you've installed protoc and followed the gRPC code [installation instructions](https://github.com/grpc/grpc/blob/master/INSTALL) first): +For simplicity, we've provided a [makefile](route_guide/Makefile) that runs `protoc` for you with the appropriate plugin, input, and output (if you want to run this yourself, make sure you've installed protoc and followed the gRPC code [installation instructions](../../INSTALL) first): ```shell $ make route_guide.grpc.pb.cc route_guide.pb.cc @@ -126,7 +126,7 @@ There are two parts to making our `RouteGuide` service do its job: - Implementing the service interface generated from our service definition: doing the actual "work" of our service. - Running a gRPC server to listen for requests from clients and return the service responses. -You can find our example `RouteGuide` server in [examples/cpp/route_guide/route_guide_server.cc](examples/cpp/route_guide/route_guide_server.cc). Let's take a closer look at how it works. +You can find our example `RouteGuide` server in [route_guide/route_guide_server.cc](route_guide/route_guide_server.cc). Let's take a closer look at how it works. ### Implementing RouteGuide @@ -236,7 +236,7 @@ As you can see, we build and start our server using a `ServerBuilder`. To do thi ## Creating the client -In this section, we'll look at creating a C++ client for our `RouteGuide` service. You can see our complete example client code in [examples/cpp/route_guide/route_guide_client.cc](examples/cpp/route_guide/route_guide_client.cc). +In this section, we'll look at creating a C++ client for our `RouteGuide` service. You can see our complete example client code in [route_guide/route_guide_client.cc](route_guide/route_guide_client.cc). ### Creating a stub diff --git a/examples/cpp/helloworld/README.md b/examples/cpp/helloworld/README.md index 641aadd52d3..ac833e98eb3 100644 --- a/examples/cpp/helloworld/README.md +++ b/examples/cpp/helloworld/README.md @@ -2,7 +2,7 @@ ### Install gRPC Make sure you have installed gRPC on your system. Follow the instructions here: -[https://github.com/grpc/grpc/blob/master/INSTALL](https://github.com/grpc/grpc/blob/master/INSTALL). +[https://github.com/grpc/grpc/blob/master/INSTALL](../../../INSTALL). ### Get the tutorial source code @@ -34,7 +34,7 @@ types as protocol buffer message types. Both the client and the server use interface code generated from the service definition. Here's our example service definition, defined using protocol buffers IDL in -[helloworld.proto](examples/protos/helloworld.proto). The `Greeting` +[helloworld.proto](../../protos/helloworld.proto). The `Greeting` service has one method, `hello`, that lets the server receive a single `HelloRequest` message from the remote client containing the user's name, then send back @@ -124,7 +124,7 @@ $ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto } ``` -For a working example, refer to [greeter_client.cc](examples/cpp/helloworld/greeter_client.cc). +For a working example, refer to [greeter_client.cc](greeter_client.cc). ### Writing a server @@ -152,7 +152,7 @@ For a working example, refer to [greeter_client.cc](examples/cpp/helloworld/gree std::unique_ptr server(builder.BuildAndStart()); ``` -For a working example, refer to [greeter_server.cc](examples/cpp/helloworld/greeter_server.cc). +For a working example, refer to [greeter_server.cc](greeter_server.cc). ### Writing asynchronous client and server @@ -194,7 +194,7 @@ The channel and stub creation code is the same as the sync client. } ``` -For a working example, refer to [greeter_async_client.cc](examples/cpp/helloworld/greeter_async_client.cc). +For a working example, refer to [greeter_async_client.cc](greeter_async_client.cc). #### Async server @@ -253,7 +253,7 @@ maintain the state of each rpc and use the address of it as the unique tag. For simplicity the server only uses one completion queue for all events, and runs a main loop in `HandleRpcs` to query the queue. -For a working example, refer to [greeter_async_server.cc](examples/cpp/helloworld/greeter_async_server.cc). +For a working example, refer to [greeter_async_server.cc](greeter_async_server.cc). From 92806a51ba419428c0e4a126e916860b0225c492 Mon Sep 17 00:00:00 2001 From: yang-g Date: Fri, 28 Aug 2015 14:24:44 -0700 Subject: [PATCH 11/33] remove ChannelArguments ref and update doc --- examples/cpp/cpptutorial.md | 4 ++-- examples/cpp/helloworld/README.md | 2 +- examples/cpp/helloworld/greeter_async_client.cc | 1 - examples/cpp/helloworld/greeter_client.cc | 1 - examples/cpp/route_guide/route_guide_client.cc | 1 - 5 files changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/cpp/cpptutorial.md b/examples/cpp/cpptutorial.md index a23633d83cd..c06233aa6b0 100644 --- a/examples/cpp/cpptutorial.md +++ b/examples/cpp/cpptutorial.md @@ -242,10 +242,10 @@ In this section, we'll look at creating a C++ client for our `RouteGuide` servic To call service methods, we first need to create a *stub*. -First we need to create a gRPC *channel* for our stub, specifying the server address and port we want to connect to and any special channel arguments - in our case we'll use the default `ChannelArguments` and no SSL: +First we need to create a gRPC *channel* for our stub, specifying the server address and port we want to connect to without SSL: ```cpp -grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(), ChannelArguments()); +grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials()); ``` Now we can use the channel to create our stub using the `NewStub` method provided in the `RouteGuide` class we generated from our .proto. diff --git a/examples/cpp/helloworld/README.md b/examples/cpp/helloworld/README.md index ac833e98eb3..b16c084583d 100644 --- a/examples/cpp/helloworld/README.md +++ b/examples/cpp/helloworld/README.md @@ -94,7 +94,7 @@ $ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto arguments as follows ``` - auto channel = CreateChannel("localhost:50051", InsecureCredentials(), ChannelArguments()); + auto channel = CreateChannel("localhost:50051", InsecureCredentials()); ``` - Create a stub. A stub implements the rpc methods of a service and in the diff --git a/examples/cpp/helloworld/greeter_async_client.cc b/examples/cpp/helloworld/greeter_async_client.cc index bc95c54e06b..875599e161e 100644 --- a/examples/cpp/helloworld/greeter_async_client.cc +++ b/examples/cpp/helloworld/greeter_async_client.cc @@ -45,7 +45,6 @@ #include "helloworld.grpc.pb.h" using grpc::Channel; -using grpc::ChannelArguments; using grpc::ClientAsyncResponseReader; using grpc::ClientContext; using grpc::CompletionQueue; diff --git a/examples/cpp/helloworld/greeter_client.cc b/examples/cpp/helloworld/greeter_client.cc index 2b542cd8349..3d2fcba6106 100644 --- a/examples/cpp/helloworld/greeter_client.cc +++ b/examples/cpp/helloworld/greeter_client.cc @@ -43,7 +43,6 @@ #include "helloworld.grpc.pb.h" using grpc::Channel; -using grpc::ChannelArguments; using grpc::ClientContext; using grpc::Status; using helloworld::HelloRequest; diff --git a/examples/cpp/route_guide/route_guide_client.cc b/examples/cpp/route_guide/route_guide_client.cc index fe998079c40..ec0a75e0393 100644 --- a/examples/cpp/route_guide/route_guide_client.cc +++ b/examples/cpp/route_guide/route_guide_client.cc @@ -47,7 +47,6 @@ #include "route_guide.grpc.pb.h" using grpc::Channel; -using grpc::ChannelArguments; using grpc::ClientContext; using grpc::ClientReader; using grpc::ClientReaderWriter; From bcebb5d230611f530ae8daaeb172bc896d0ec39b Mon Sep 17 00:00:00 2001 From: yang-g Date: Fri, 28 Aug 2015 14:29:53 -0700 Subject: [PATCH 12/33] fix link --- examples/cpp/cpptutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/cpp/cpptutorial.md b/examples/cpp/cpptutorial.md index c06233aa6b0..78de014f97d 100644 --- a/examples/cpp/cpptutorial.md +++ b/examples/cpp/cpptutorial.md @@ -28,7 +28,7 @@ Then change your current directory to `examples/cpp/route_guide`: $ cd examples/cpp/route_guide ``` -You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the C++ quick start guide](examples/cpp). +You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [gRPC in 3 minutes](README.md). ## Defining the service From 76ba1ff65af66550f71ee2fcac1e715535c98b94 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 28 Aug 2015 14:57:04 -0700 Subject: [PATCH 13/33] Switched to using static functions for accessing Client properties --- src/node/index.js | 10 ++++ src/node/interop/interop_client.js | 4 +- src/node/src/client.js | 83 +++++++++++++++++------------- src/node/test/surface_test.js | 17 +++--- 4 files changed, 68 insertions(+), 46 deletions(-) diff --git a/src/node/index.js b/src/node/index.js index 51d3fa590cd..02b73f66ee7 100644 --- a/src/node/index.js +++ b/src/node/index.js @@ -164,3 +164,13 @@ exports.ServerCredentials = grpc.ServerCredentials; * @see module:src/client.makeClientConstructor */ exports.makeGenericClientConstructor = client.makeClientConstructor; + +/** + * @see module:src/client.getClientChannel + */ +exports.getClientChannel = client.getClientChannel; + +/** + * @see module:src/client.waitForClientReady + */ +exports.waitForClientReady = client.waitForClientReady; diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js index da5e0f4afb8..6a8d2633ca9 100644 --- a/src/node/interop/interop_client.js +++ b/src/node/interop/interop_client.js @@ -285,7 +285,7 @@ function authTest(expected_user, scope, client, done) { if (credential.createScopedRequired() && scope) { credential = credential.createScoped(scope); } - client.$_updateMetadata = grpc.getGoogleAuthDelegate(credential); + client.$updateMetadata = grpc.getGoogleAuthDelegate(credential); var arg = { response_type: 'COMPRESSABLE', response_size: 314159, @@ -338,7 +338,7 @@ function oauth2Test(expected_user, scope, per_rpc, client, done) { if (per_rpc) { updateMetadata('', {}, makeTestCall); } else { - client.$_updateMetadata = updateMetadata; + client.$updateMetadata = updateMetadata; makeTestCall(null, {}); } }); diff --git a/src/node/src/client.js b/src/node/src/client.js index 53b7cc3e8d8..d6b7f59d7e3 100644 --- a/src/node/src/client.js +++ b/src/node/src/client.js @@ -275,7 +275,7 @@ function makeUnaryRequestFunction(method, serialize, deserialize) { emitter.getPeer = function getPeer() { return call.getPeer(); }; - this.$_updateMetadata(this.$_auth_uri, metadata, function(error, metadata) { + this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) { if (error) { call.cancel(); callback(error); @@ -349,7 +349,7 @@ function makeClientStreamRequestFunction(method, serialize, deserialize) { metadata = metadata.clone(); } var stream = new ClientWritableStream(call, serialize); - this.$_updateMetadata(this.$_auth_uri, metadata, function(error, metadata) { + this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) { if (error) { call.cancel(); callback(error); @@ -425,7 +425,7 @@ function makeServerStreamRequestFunction(method, serialize, deserialize) { metadata = metadata.clone(); } var stream = new ClientReadableStream(call, deserialize); - this.$_updateMetadata(this.$_auth_uri, metadata, function(error, metadata) { + this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) { if (error) { call.cancel(); stream.emit('error', error); @@ -503,7 +503,7 @@ function makeBidiStreamRequestFunction(method, serialize, deserialize) { metadata = metadata.clone(); } var stream = new ClientDuplexStream(call, serialize, deserialize); - this.$_updateMetadata(this.$_auth_uri, metadata, function(error, metadata) { + this.$updateMetadata(this.$auth_uri, metadata, function(error, metadata) { if (error) { call.cancel(); stream.emit('error', error); @@ -594,43 +594,16 @@ exports.makeClientConstructor = function(methods, serviceName) { options = {}; } options['grpc.primary_user_agent'] = 'grpc-node/' + version; + /* Private fields use $ as a prefix instead of _ because it is an invalid + * prefix of a method name */ this.$channel = new grpc.Channel(address, credentials, options); // Remove the optional DNS scheme, trailing port, and trailing backslash address = address.replace(/^(dns:\/{3})?([^:\/]+)(:\d+)?\/?$/, '$2'); - this.$_server_address = address; - this.$_auth_uri = 'https://' + this.server_address + '/' + serviceName; - this.$_updateMetadata = updateMetadata; + this.$server_address = address; + this.$auth_uri = 'https://' + this.server_address + '/' + serviceName; + this.$updateMetadata = updateMetadata; } - /** - * Wait for the client to be ready. The callback will be called when the - * client has successfully connected to the server, and it will be called - * with an error if the attempt to connect to the server has unrecoverablly - * failed or if the deadline expires. This function will make the channel - * start connecting if it has not already done so. - * @param {(Date|Number)} deadline When to stop waiting for a connection. Pass - * Infinity to wait forever. - * @param {function(Error)} callback The callback to call when done attempting - * to connect. - */ - Client.prototype.$waitForReady = function(deadline, callback) { - var self = this; - var checkState = function(err) { - if (err) { - callback(new Error('Failed to connect before the deadline')); - } - var new_state = self.$channel.getConnectivityState(true); - if (new_state === grpc.connectivityState.READY) { - callback(); - } else if (new_state === grpc.connectivityState.FATAL_FAILURE) { - callback(new Error('Failed to connect to server')); - } else { - self.$channel.watchConnectivityState(new_state, deadline, checkState); - } - }; - checkState(); - }; - _.each(methods, function(attrs, name) { var method_type; if (_.startsWith(name, '$')) { @@ -660,6 +633,44 @@ exports.makeClientConstructor = function(methods, serviceName) { return Client; }; +/** + * Return the underlying channel object for the specified client + * @param {Client} client + * @return {Channel} The channel + */ +exports.getClientChannel = function(client) { + return client.$channel; +}; + +/** + * Wait for the client to be ready. The callback will be called when the + * client has successfully connected to the server, and it will be called + * with an error if the attempt to connect to the server has unrecoverablly + * failed or if the deadline expires. This function will make the channel + * start connecting if it has not already done so. + * @param {Client} client The client to wait on + * @param {(Date|Number)} deadline When to stop waiting for a connection. Pass + * Infinity to wait forever. + * @param {function(Error)} callback The callback to call when done attempting + * to connect. + */ +exports.waitForClientReady = function(client, deadline, callback) { + var checkState = function(err) { + if (err) { + callback(new Error('Failed to connect before the deadline')); + } + var new_state = client.$channel.getConnectivityState(true); + if (new_state === grpc.connectivityState.READY) { + callback(); + } else if (new_state === grpc.connectivityState.FATAL_FAILURE) { + callback(new Error('Failed to connect to server')); + } else { + client.$channel.watchConnectivityState(new_state, deadline, checkState); + } + }; + checkState(); +}; + /** * Creates a constructor for clients for the given service * @param {ProtoBuf.Reflect.Service} service The service to generate a client diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js index 6bb90a23033..d917c7a1712 100644 --- a/src/node/test/surface_test.js +++ b/src/node/test/surface_test.js @@ -151,7 +151,7 @@ describe('Client constructor building', function() { }, /\$/); }); }); -describe('Client#$waitForReady', function() { +describe('waitForClientReady', function() { var server; var port; var Client; @@ -169,13 +169,13 @@ describe('Client#$waitForReady', function() { server.forceShutdown(); }); it('should complete when called alone', function(done) { - client.$waitForReady(Infinity, function(error) { + grpc.waitForClientReady(client, Infinity, function(error) { assert.ifError(error); done(); }); }); it('should complete when a call is initiated', function(done) { - client.$waitForReady(Infinity, function(error) { + grpc.waitForClientReady(client, Infinity, function(error) { assert.ifError(error); done(); }); @@ -184,19 +184,19 @@ describe('Client#$waitForReady', function() { }); it('should complete if called more than once', function(done) { done = multiDone(done, 2); - client.$waitForReady(Infinity, function(error) { + grpc.waitForClientReady(client, Infinity, function(error) { assert.ifError(error); done(); }); - client.$waitForReady(Infinity, function(error) { + grpc.waitForClientReady(client, Infinity, function(error) { assert.ifError(error); done(); }); }); it('should complete if called when already ready', function(done) { - client.$waitForReady(Infinity, function(error) { + grpc.waitForClientReady(client, Infinity, function(error) { assert.ifError(error); - client.$waitForReady(Infinity, function(error) { + grpc.waitForClientReady(client, Infinity, function(error) { assert.ifError(error); done(); }); @@ -444,7 +444,8 @@ describe('Other conditions', function() { server.forceShutdown(); }); it('channel.getTarget should be available', function() { - assert.strictEqual(typeof client.$channel.getTarget(), 'string'); + assert.strictEqual(typeof grpc.getClientChannel(client).getTarget(), + 'string'); }); describe('Server recieving bad input', function() { var misbehavingClient; From c919228e0ae7982c60e40d59a946ac0288ae8ce5 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Fri, 28 Aug 2015 15:24:07 -0700 Subject: [PATCH 14/33] Updated Node examples to be compatible with master --- examples/node/greeter_client.js | 3 ++- examples/node/greeter_server.js | 14 ++++--------- examples/node/package.json | 2 +- .../node/route_guide/route_guide_client.js | 3 ++- .../node/route_guide/route_guide_server.js | 20 +++++++++---------- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/examples/node/greeter_client.js b/examples/node/greeter_client.js index ab7050ab213..ddc8abbbed2 100644 --- a/examples/node/greeter_client.js +++ b/examples/node/greeter_client.js @@ -37,7 +37,8 @@ var grpc = require('grpc'); var hello_proto = grpc.load(PROTO_PATH).helloworld; function main() { - var client = new hello_proto.Greeter('localhost:50051'); + var client = new hello_proto.Greeter('localhost:50051', + grpc.Credentials.createInsecure()); var user; if (process.argv.length >= 3) { user = process.argv[2]; diff --git a/examples/node/greeter_server.js b/examples/node/greeter_server.js index 2fb95f0f90e..44b44afaafb 100644 --- a/examples/node/greeter_server.js +++ b/examples/node/greeter_server.js @@ -36,8 +36,6 @@ var PROTO_PATH = __dirname + '/helloworld.proto'; var grpc = require('grpc'); var hello_proto = grpc.load(PROTO_PATH).helloworld; -var Server = grpc.buildServer([hello_proto.Greeter.service]); - /** * Implements the SayHello RPC method. */ @@ -50,14 +48,10 @@ function sayHello(call, callback) { * sample server port */ function main() { - var server = new Server({ - "helloworld.Greeter": { - sayHello: sayHello - } - }); - - server.bind('0.0.0.0:50051'); - server.listen(); + var server = new grpc.Server(); + server.addProtoService(hello_proto.Greeter.service, {sayHello: sayHello}); + server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); + server.start(); } main(); diff --git a/examples/node/package.json b/examples/node/package.json index caf539518f1..6c4f95b1093 100644 --- a/examples/node/package.json +++ b/examples/node/package.json @@ -3,7 +3,7 @@ "version": "0.5.0", "dependencies": { "async": "^0.9.0", - "grpc": "~0.9.0", + "grpc": "~0.11.0", "minimist": "^1.1.0", "underscore": "^1.8.2" } diff --git a/examples/node/route_guide/route_guide_client.js b/examples/node/route_guide/route_guide_client.js index 60c47a429d6..3550d797d92 100644 --- a/examples/node/route_guide/route_guide_client.js +++ b/examples/node/route_guide/route_guide_client.js @@ -34,7 +34,8 @@ var path = require('path'); var _ = require('underscore'); var grpc = require('grpc'); var examples = grpc.load(__dirname + '/route_guide.proto').examples; -var client = new examples.RouteGuide('localhost:50051'); +var client = new examples.RouteGuide('localhost:50051', + grpc.Credentials.createInsecure()); var COORD_FACTOR = 1e7; diff --git a/examples/node/route_guide/route_guide_server.js b/examples/node/route_guide/route_guide_server.js index 5dd84126543..38e1f94a92a 100644 --- a/examples/node/route_guide/route_guide_server.js +++ b/examples/node/route_guide/route_guide_server.js @@ -34,8 +34,6 @@ var _ = require('underscore'); var grpc = require('grpc'); var examples = grpc.load(__dirname + '/route_guide.proto').examples; -var Server = grpc.buildServer([examples.RouteGuide.service]); - var COORD_FACTOR = 1e7; /** @@ -222,27 +220,27 @@ function routeChat(call) { * @return {Server} The new server object */ function getServer() { - return new Server({ - 'examples.RouteGuide' : { - getFeature: getFeature, - listFeatures: listFeatures, - recordRoute: recordRoute, - routeChat: routeChat - } + var server = new grpc.Server(); + server.addProtoService(examples.RouteGuide.service, { + getFeature: getFeature, + listFeatures: listFeatures, + recordRoute: recordRoute, + routeChat: routeChat }); + return server; } if (require.main === module) { // If this is run as a script, start a server on an unused port var routeServer = getServer(); - routeServer.bind('0.0.0.0:50051'); + routeServer.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); var argv = parseArgs(process.argv, { string: 'db_path' }); fs.readFile(path.resolve(argv.db_path), function(err, data) { if (err) throw err; feature_list = JSON.parse(data); - routeServer.listen(); + routeServer.start(); }); } From 8f691e6c947092da9c046b451f7666fc981fae8f Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Mon, 31 Aug 2015 08:27:11 -0700 Subject: [PATCH 15/33] add clone to aggregation ops --- include/grpc/census.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/grpc/census.h b/include/grpc/census.h index 3fd8266acd5..f01c8e30bfc 100644 --- a/include/grpc/census.h +++ b/include/grpc/census.h @@ -194,8 +194,10 @@ void census_record(census_context *context, census_value *values, /** Structure used to describe an aggregation type. */ typedef struct { /* Create a new aggregation. The pointer returned can be used in future calls - to free(), record(), data() and reset(). */ + to clone(), free(), record(), data() and reset(). */ void *(*create)(const void *create_arg); + /* Make a copy of an aggregation created by create() */ + void *(*clone)(const void *aggregation); /* Destroy an aggregation created by create() */ void (*free)(void *aggregation); /* Record a new value against aggregation. */ From a24148ea383fbb508e4f8ca76837560322d87b8b Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Mon, 31 Aug 2015 08:30:32 -0700 Subject: [PATCH 16/33] change aggregation type names --- include/grpc/census.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/include/grpc/census.h b/include/grpc/census.h index f01c8e30bfc..d1486a32d31 100644 --- a/include/grpc/census.h +++ b/include/grpc/census.h @@ -216,21 +216,21 @@ typedef struct { debugging only. Returns the number of bytes added to buffer (a value == n implies the buffer was of insufficient size). */ size_t (*print)(const void *aggregation, char *buffer, size_t n); -} census_aggregation; +} census_aggregation_ops; /* Predefined aggregation types. */ -extern census_aggregation census_agg_scalar; -extern census_aggregation census_agg_distribution; -extern census_aggregation census_agg_histogram; -extern census_aggregation census_agg_window; +extern census_aggregation_ops census_agg_scalar; +extern census_aggregation_ops census_agg_distribution; +extern census_aggregation_ops census_agg_histogram; +extern census_aggregation_ops census_agg_window; /** Information needed to instantiate a new aggregation. Used in view construction via census_define_view(). */ typedef struct { - const census_aggregation *aggregation; + const census_aggregation_ops *ops; const void *create_arg; /* Argument to be used for aggregation initialization. */ -} census_aggregation_descriptor; +} census_aggregation; /** A census view type. Opaque. */ typedef struct census_view census_view; @@ -243,9 +243,10 @@ typedef struct census_view census_view; @return A new census view */ -census_view *census_view_create( - gpr_uint32 metric_id, const census_tag_set *tags, - const census_aggregation_descriptor *aggregations, size_t naggregations); +census_view *census_view_create(gpr_uint32 metric_id, + const census_tag_set *tags, + const census_aggregation *aggregations, + size_t naggregations); /** Destroy a previously created view. */ void census_view_delete(census_view *view); @@ -260,8 +261,7 @@ size_t census_view_naggregations(const census_view *view); const census_tag_set *census_view_tags(const census_view *view); /** Get aggregation descriptors associated with a view. */ -const census_aggregation_descriptor *census_view_aggregrations( - const census_view *view); +const census_aggregation *census_view_aggregrations(const census_view *view); /** Holds all the aggregation data for a particular view instantiation. Forms part of the data returned by census_view_data(). */ From 5b61479b0b5b968e26391476b59837951bddba02 Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Mon, 31 Aug 2015 08:43:37 -0700 Subject: [PATCH 17/33] rename record fn --- include/grpc/census.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/grpc/census.h b/include/grpc/census.h index 861da716c47..affb91968fd 100644 --- a/include/grpc/census.h +++ b/include/grpc/census.h @@ -408,8 +408,8 @@ typedef struct { } census_value; /* Record new usage values against the given context. */ -void census_record(census_context *context, census_value *values, - size_t nvalues); +void census_record_values(census_context *context, census_value *values, + size_t nvalues); /** Structure used to describe an aggregation type. */ typedef struct { From e41d9d5f930bb1ec3fc22a92c6f3604ca7e74575 Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Mon, 31 Aug 2015 10:35:32 -0700 Subject: [PATCH 18/33] remove const from data() type --- include/grpc/census.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/grpc/census.h b/include/grpc/census.h index affb91968fd..89eb12a36cd 100644 --- a/include/grpc/census.h +++ b/include/grpc/census.h @@ -425,9 +425,9 @@ typedef struct { /* Return current aggregation data. The caller must cast this object into the correct type for the aggregation result. The object returned can be freed by using free_data(). */ - const void *(*data)(const void *aggregation); + void *(*data)(const void *aggregation); /* free data returned by data() */ - void (*free_data)(const void *data); + void (*free_data)(void *data); /* Reset an aggregation to default (zero) values. */ void (*reset)(void *aggregation); /* Merge 'from' aggregation into 'to'. Both aggregations must be compatible */ From 9a72021cc6c32837869be7fab406ec620d91f595 Mon Sep 17 00:00:00 2001 From: yang-g Date: Mon, 31 Aug 2015 13:14:13 -0700 Subject: [PATCH 19/33] fix c++ proto --- examples/protos/route_guide.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/protos/route_guide.proto b/examples/protos/route_guide.proto index bfde5f1ead6..7a70040e1ce 100644 --- a/examples/protos/route_guide.proto +++ b/examples/protos/route_guide.proto @@ -32,7 +32,7 @@ syntax = "proto3"; option java_package = "ex.grpc"; option objc_class_prefix = "RTG"; -package examples; +package routeguide; // Interface exported by the server. service RouteGuide { From b2a30c196e587e9eca495294db0800db4d60df2d Mon Sep 17 00:00:00 2001 From: yang-g Date: Mon, 31 Aug 2015 12:43:41 -0700 Subject: [PATCH 20/33] fix cpp --- examples/cpp/route_guide/helper.cc | 4 ++-- examples/cpp/route_guide/helper.h | 4 ++-- .../cpp/route_guide/route_guide_client.cc | 21 +++++++++---------- .../cpp/route_guide/route_guide_server.cc | 18 ++++++++-------- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/examples/cpp/route_guide/helper.cc b/examples/cpp/route_guide/helper.cc index c2415afdf72..f76990f6fce 100644 --- a/examples/cpp/route_guide/helper.cc +++ b/examples/cpp/route_guide/helper.cc @@ -40,7 +40,7 @@ #include #include "route_guide.grpc.pb.h" -namespace examples { +namespace routeguide { std::string GetDbFileContent(int argc, char** argv) { std::string db_path; @@ -174,5 +174,5 @@ void ParseDb(const std::string& db, std::vector* feature_list) { } -} // namespace examples +} // namespace routeguide diff --git a/examples/cpp/route_guide/helper.h b/examples/cpp/route_guide/helper.h index 65c93c1d347..db36596f90c 100644 --- a/examples/cpp/route_guide/helper.h +++ b/examples/cpp/route_guide/helper.h @@ -37,14 +37,14 @@ #include #include -namespace examples { +namespace routeguide { class Feature; std::string GetDbFileContent(int argc, char** argv); void ParseDb(const std::string& db, std::vector* feature_list); -} // namespace examples +} // namespace routeguide #endif // GRPC_COMMON_CPP_ROUTE_GUIDE_HELPER_H_ diff --git a/examples/cpp/route_guide/route_guide_client.cc b/examples/cpp/route_guide/route_guide_client.cc index 814def27f35..10864229a24 100644 --- a/examples/cpp/route_guide/route_guide_client.cc +++ b/examples/cpp/route_guide/route_guide_client.cc @@ -53,12 +53,12 @@ using grpc::ClientReader; using grpc::ClientReaderWriter; using grpc::ClientWriter; using grpc::Status; -using examples::Point; -using examples::Feature; -using examples::Rectangle; -using examples::RouteSummary; -using examples::RouteNote; -using examples::RouteGuide; +using routeguide::Point; +using routeguide::Feature; +using routeguide::Rectangle; +using routeguide::RouteSummary; +using routeguide::RouteNote; +using routeguide::RouteGuide; Point MakePoint(long latitude, long longitude) { Point p; @@ -87,7 +87,7 @@ class RouteGuideClient { public: RouteGuideClient(std::shared_ptr channel, const std::string& db) : stub_(RouteGuide::NewStub(channel)) { - examples::ParseDb(db, &feature_list_); + routeguide::ParseDb(db, &feature_list_); } void GetFeature() { @@ -100,7 +100,7 @@ class RouteGuideClient { } void ListFeatures() { - examples::Rectangle rect; + routeguide::Rectangle rect; Feature feature; ClientContext context; @@ -233,10 +233,9 @@ class RouteGuideClient { int main(int argc, char** argv) { // Expect only arg: --db_path=path/to/route_guide_db.json. - std::string db = examples::GetDbFileContent(argc, argv); + std::string db = routeguide::GetDbFileContent(argc, argv); RouteGuideClient guide( - grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(), - ChannelArguments()), + grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials()), db); std::cout << "-------------- GetFeature --------------" << std::endl; diff --git a/examples/cpp/route_guide/route_guide_server.cc b/examples/cpp/route_guide/route_guide_server.cc index b37539299a3..aa808321a1a 100644 --- a/examples/cpp/route_guide/route_guide_server.cc +++ b/examples/cpp/route_guide/route_guide_server.cc @@ -53,12 +53,12 @@ using grpc::ServerReader; using grpc::ServerReaderWriter; using grpc::ServerWriter; using grpc::Status; -using examples::Point; -using examples::Feature; -using examples::Rectangle; -using examples::RouteSummary; -using examples::RouteNote; -using examples::RouteGuide; +using routeguide::Point; +using routeguide::Feature; +using routeguide::Rectangle; +using routeguide::RouteSummary; +using routeguide::RouteNote; +using routeguide::RouteGuide; using std::chrono::system_clock; @@ -99,7 +99,7 @@ std::string GetFeatureName(const Point& point, class RouteGuideImpl final : public RouteGuide::Service { public: explicit RouteGuideImpl(const std::string& db) { - examples::ParseDb(db, &feature_list_); + routeguide::ParseDb(db, &feature_list_); } Status GetFeature(ServerContext* context, const Point* point, @@ -110,7 +110,7 @@ class RouteGuideImpl final : public RouteGuide::Service { } Status ListFeatures(ServerContext* context, - const examples::Rectangle* rectangle, + const routeguide::Rectangle* rectangle, ServerWriter* writer) override { auto lo = rectangle->lo(); auto hi = rectangle->hi(); @@ -195,7 +195,7 @@ void RunServer(const std::string& db_path) { int main(int argc, char** argv) { // Expect only arg: --db_path=path/to/route_guide_db.json. - std::string db = examples::GetDbFileContent(argc, argv); + std::string db = routeguide::GetDbFileContent(argc, argv); RunServer(db); return 0; From aafe9725b058d3710209bf0c95911928428eb2f2 Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Mon, 31 Aug 2015 13:15:00 -0700 Subject: [PATCH 21/33] scalar -> sum --- include/grpc/census.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/grpc/census.h b/include/grpc/census.h index 89eb12a36cd..9c0291bf964 100644 --- a/include/grpc/census.h +++ b/include/grpc/census.h @@ -382,7 +382,7 @@ void census_tag_set_close(census_tag_set_iterator *it); /* Core stats collection API's. The following concepts are used: * Aggregation: A collection of values. Census supports the following aggregation types: - Scalar - a single scalar value. Typically used for keeping (e.g.) + Sum - a single summation type. Typically used for keeping (e.g.) counts of events. Distribution - statistical distribution information, used for recording average, standard deviation etc. @@ -439,7 +439,7 @@ typedef struct { } census_aggregation_ops; /* Predefined aggregation types. */ -extern census_aggregation_ops census_agg_scalar; +extern census_aggregation_ops census_agg_sum; extern census_aggregation_ops census_agg_distribution; extern census_aggregation_ops census_agg_histogram; extern census_aggregation_ops census_agg_window; From e69909a7e7d6186b904b7d0eea88beb7d49fb157 Mon Sep 17 00:00:00 2001 From: yang-g Date: Mon, 31 Aug 2015 13:27:58 -0700 Subject: [PATCH 22/33] fix build --- examples/cpp/helloworld/greeter_async_client.cc | 4 ++-- examples/cpp/helloworld/greeter_async_server.cc | 2 +- examples/cpp/helloworld/greeter_client.cc | 5 ++--- examples/cpp/helloworld/greeter_server.cc | 2 +- examples/cpp/route_guide/route_guide_client.cc | 2 +- examples/cpp/route_guide/route_guide_server.cc | 2 +- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/examples/cpp/helloworld/greeter_async_client.cc b/examples/cpp/helloworld/greeter_async_client.cc index d99f89b1359..ace5c4a2730 100644 --- a/examples/cpp/helloworld/greeter_async_client.cc +++ b/examples/cpp/helloworld/greeter_async_client.cc @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include "helloworld.grpc.pb.h" using grpc::Channel; @@ -89,7 +89,7 @@ class GreeterClient { int main(int argc, char** argv) { GreeterClient greeter(grpc::CreateChannel( - "localhost:50051", grpc::InsecureCredentials(), ChannelArguments())); + "localhost:50051", grpc::InsecureCredentials())); std::string user("world"); std::string reply = greeter.SayHello(user); std::cout << "Greeter received: " << reply << std::endl; diff --git a/examples/cpp/helloworld/greeter_async_server.cc b/examples/cpp/helloworld/greeter_async_server.cc index b8a0dbf0e2e..189c3afe6dc 100644 --- a/examples/cpp/helloworld/greeter_async_server.cc +++ b/examples/cpp/helloworld/greeter_async_server.cc @@ -39,10 +39,10 @@ #include #include #include +#include #include #include #include -#include #include "helloworld.grpc.pb.h" using grpc::Server; diff --git a/examples/cpp/helloworld/greeter_client.cc b/examples/cpp/helloworld/greeter_client.cc index dd0358ac95d..d29e12d4a83 100644 --- a/examples/cpp/helloworld/greeter_client.cc +++ b/examples/cpp/helloworld/greeter_client.cc @@ -39,7 +39,7 @@ #include #include #include -#include +#include #include "helloworld.grpc.pb.h" using grpc::Channel; @@ -75,8 +75,7 @@ class GreeterClient { int main(int argc, char** argv) { GreeterClient greeter( - grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials(), - ChannelArguments())); + grpc::CreateChannel("localhost:50051", grpc::InsecureCredentials())); std::string user("world"); std::string reply = greeter.SayHello(user); std::cout << "Greeter received: " << reply << std::endl; diff --git a/examples/cpp/helloworld/greeter_server.cc b/examples/cpp/helloworld/greeter_server.cc index c1efdf563c4..b434752d874 100644 --- a/examples/cpp/helloworld/greeter_server.cc +++ b/examples/cpp/helloworld/greeter_server.cc @@ -36,10 +36,10 @@ #include #include +#include #include #include #include -#include #include "helloworld.grpc.pb.h" using grpc::Server; diff --git a/examples/cpp/route_guide/route_guide_client.cc b/examples/cpp/route_guide/route_guide_client.cc index 10864229a24..27628da2785 100644 --- a/examples/cpp/route_guide/route_guide_client.cc +++ b/examples/cpp/route_guide/route_guide_client.cc @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include "helper.h" #include "route_guide.grpc.pb.h" diff --git a/examples/cpp/route_guide/route_guide_server.cc b/examples/cpp/route_guide/route_guide_server.cc index aa808321a1a..2be57428628 100644 --- a/examples/cpp/route_guide/route_guide_server.cc +++ b/examples/cpp/route_guide/route_guide_server.cc @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include "helper.h" #include "route_guide.grpc.pb.h" From 7d3d485aa7dc5ed98f2152aceeb79674286aed15 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 31 Aug 2015 13:36:48 -0700 Subject: [PATCH 23/33] add roots.pem to Grpc C# nuget package --- src/csharp/Grpc.Core/Grpc.Core.nuspec | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/csharp/Grpc.Core/Grpc.Core.nuspec b/src/csharp/Grpc.Core/Grpc.Core.nuspec index fe49efc7ec0..06de55c8c3c 100644 --- a/src/csharp/Grpc.Core/Grpc.Core.nuspec +++ b/src/csharp/Grpc.Core/Grpc.Core.nuspec @@ -14,15 +14,16 @@ Release $version$ of gRPC C# Copyright 2015, Google Inc. gRPC RPC Protocol HTTP/2 - - - + + + + - - - + + + From e7fb1899f80eb6eb257f6dc8ddd27aa3398614f0 Mon Sep 17 00:00:00 2001 From: yang-g Date: Mon, 31 Aug 2015 14:13:25 -0700 Subject: [PATCH 24/33] fix internal objc test proto --- .../generated_libraries/RouteGuideClient/route_guide.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objective-c/generated_libraries/RouteGuideClient/route_guide.proto b/src/objective-c/generated_libraries/RouteGuideClient/route_guide.proto index dace1a5d260..19592e2ebdd 100644 --- a/src/objective-c/generated_libraries/RouteGuideClient/route_guide.proto +++ b/src/objective-c/generated_libraries/RouteGuideClient/route_guide.proto @@ -29,7 +29,7 @@ syntax = "proto3"; -package examples; +package routeguide; option objc_class_prefix = "RGD"; From d87e203622bb65c5d21e2e4fd6bc601f272f4a07 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Mon, 31 Aug 2015 11:16:51 -0700 Subject: [PATCH 25/33] fix examples links --- examples/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/README.md b/examples/README.md index 6465115e185..cc4b239f8e2 100644 --- a/examples/README.md +++ b/examples/README.md @@ -10,16 +10,16 @@ Hello World example. You'll find more tutorials and reference docs in this repos ## Quick start You can find quick start guides for each language, including installation instructions, examples, and tutorials here: -* [C++](examples/cpp) +* [C++](cpp) * [Java](https://github.com/grpc/grpc-java/tree/master/examples) * [Go](https://github.com/grpc/grpc-go/tree/master/examples) -* [Ruby](examples/ruby) -* [Node.js](examples/node) -* [Android Java](examples/java/android) -* [Python](examples/python/helloworld) -* [C#](examples/csharp) -* [Objective-C](examples/objective-c/route_guide) -* [PHP](examples/php) +* [Ruby](ruby) +* [Node.js](node) +* [Android Java](https://github.com/grpc/grpc-java/tree/master/examples/android) +* [Python](python/helloworld) +* [C#](csharp) +* [Objective-C](objective-c/route_guide) +* [PHP](php) ## What's in this repository? From 56debcb6d18762e41a21b7404c2a35a04219a026 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Mon, 31 Aug 2015 12:17:34 -0700 Subject: [PATCH 26/33] fix more examples links --- examples/csharp/README.md | 2 +- examples/csharp/route_guide/README.md | 8 ++++---- examples/node/route_guide/README.md | 10 +++++----- examples/objective-c/auth_sample/README.md | 6 +++--- examples/objective-c/helloworld/README.md | 4 ++-- examples/objective-c/route_guide/README.md | 8 ++++---- examples/php/route_guide/README.md | 8 ++++---- examples/python/helloworld/README.md | 6 +++--- examples/python/route_guide/README.md | 10 +++++----- examples/ruby/README.md | 4 ++-- examples/ruby/route_guide/README.md | 10 +++++----- 11 files changed, 38 insertions(+), 38 deletions(-) diff --git a/examples/csharp/README.md b/examples/csharp/README.md index fcdcc735f9b..3719080f4ae 100644 --- a/examples/csharp/README.md +++ b/examples/csharp/README.md @@ -69,4 +69,4 @@ On Linux or Mac, use `mono GreeterServer.exe` and `mono GreeterClient.exe` to ru Tutorial -------- -You can find a more detailed tutorial in [gRPC Basics: C#](examples/csharp/route_guide/README.md) +You can find a more detailed tutorial in [gRPC Basics: C#](route_guide/README.md) diff --git a/examples/csharp/route_guide/README.md b/examples/csharp/route_guide/README.md index c3262c9b8ae..ec9a0c048ef 100644 --- a/examples/csharp/route_guide/README.md +++ b/examples/csharp/route_guide/README.md @@ -18,7 +18,7 @@ With gRPC we can define our service once in a .proto file and implement clients ## Example code and setup -The example code for our tutorial is in [examples/csharp/route_guide](examples/csharp/route_guide). To download the example, clone this repository by running the following command: +The example code for our tutorial is in [examples/csharp/route_guide](.). To download the example, clone this repository by running the following command: ```shell $ git clone https://github.com/grpc/grpc.git ``` @@ -34,7 +34,7 @@ able to generate the server and client interface code and run the examples. Foll ## Defining the service -Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/csharp/route_guide/RouteGuide/protos/route_guide.proto`](examples/csharp/route_guide/RouteGuide/protos/route_guide.proto). +Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`RouteGuide/protos/route_guide.proto`](RouteGuide/protos/route_guide.proto). To define a service, you specify a named `service` in your .proto file: @@ -127,7 +127,7 @@ There are two parts to making our `RouteGuide` service do its job: - Implementing the service interface generated from our service definition: doing the actual "work" of our service. - Running a gRPC server to listen for requests from clients and return the service responses. -You can find our example `RouteGuide` server in [examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs](examples/csharp/route_guide/RouteGuideServer/RouteGuideServerImpl.cs). Let's take a closer look at how it works. +You can find our example `RouteGuide` server in [RouteGuideServer/RouteGuideImpl.cs](RouteGuideServer/RouteGuideServerImpl.cs). Let's take a closer look at how it works. ### Implementing RouteGuide @@ -288,7 +288,7 @@ As you can see, we build and start our server using `Grpc.Core.Server` class. To ## Creating the client -In this section, we'll look at creating a C# client for our `RouteGuide` service. You can see our complete example client code in [examples/csharp/route_guide/RouteGuideClient/Program.cs](examples/csharp/route_guide/RouteGuideClient/Program.cs). +In this section, we'll look at creating a C# client for our `RouteGuide` service. You can see our complete example client code in [RouteGuideClient/Program.cs](RouteGuideClient/Program.cs). ### Creating a stub diff --git a/examples/node/route_guide/README.md b/examples/node/route_guide/README.md index 2efc5a5da52..1dbaac9f9ff 100644 --- a/examples/node/route_guide/README.md +++ b/examples/node/route_guide/README.md @@ -17,7 +17,7 @@ With gRPC we can define our service once in a .proto file and implement clients ## Example code and setup -The example code for our tutorial is in [examples/node/route_guide](examples/node/route_guide). To download the example, clone this repository by running the following command: +The example code for our tutorial is in [examples/node/route_guide](.). To download the example, clone this repository by running the following command: ```shell $ git clone https://github.com/grpc/grpc.git ``` @@ -27,12 +27,12 @@ Then change your current directory to `examples/node/route_guide`: $ cd examples/node/route_guide ``` -You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Node.js quick start guide](examples/node). +You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Node.js quick start guide](..). ## Defining the service -Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto). +Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](../../route_guide.proto). To define a service, you specify a named `service` in your .proto file: @@ -110,7 +110,7 @@ There are two parts to making our `RouteGuide` service do its job: - Implementing the service interface generated from our service definition: doing the actual "work" of our service. - Running a gRPC server to listen for requests from clients and return the service responses. -You can find our example `RouteGuide` server in [examples/node/route_guide/route_guide_server.js](examples/node/route_guide/route_guide_server.js). Let's take a closer look at how it works. +You can find our example `RouteGuide` server in [route_guide_server.js](route_guide_server.js). Let's take a closer look at how it works. ### Implementing RouteGuide @@ -244,7 +244,7 @@ As you can see, we build and start our server with the following steps: ## Creating the client -In this section, we'll look at creating a Node.js client for our `RouteGuide` service. You can see our complete example client code in [examples/node/route_guide/route_guide_client.js](examples/node/route_guide/route_guide_client.js). +In this section, we'll look at creating a Node.js client for our `RouteGuide` service. You can see our complete example client code in [route_guide_client.js](route_guide_client.js). ### Creating a stub diff --git a/examples/objective-c/auth_sample/README.md b/examples/objective-c/auth_sample/README.md index 3dbe7e334cc..5ae64526191 100644 --- a/examples/objective-c/auth_sample/README.md +++ b/examples/objective-c/auth_sample/README.md @@ -9,8 +9,8 @@ headers. - Read response metadata from a call, which is equivalent to HTTP response headers and trailers. It assumes you know the basics on how to make gRPC API calls using the Objective-C client library, -as shown in the [Hello World](examples/objective-c/helloworld) -or [Route Guide](examples/objective-c/route_guide) tutorials, +as shown in the [Hello World](../helloworld) +or [Route Guide](../route_guide) tutorials, and are familiar with OAuth2 concepts like _access token_. - [Example code and setup](#setup) @@ -22,7 +22,7 @@ and are familiar with OAuth2 concepts like _access token_. ## Example code and setup -The example code for our tutorial is in [examples/objective-c/auth_sample](examples/objective-c/auth_sample). +The example code for our tutorial is in [examples/objective-c/auth_sample](.). To download the example, clone this repository by running the following command: ```shell $ git clone https://github.com/grpc/grpc.git diff --git a/examples/objective-c/helloworld/README.md b/examples/objective-c/helloworld/README.md index 3b852f857fd..75df1a7a26e 100644 --- a/examples/objective-c/helloworld/README.md +++ b/examples/objective-c/helloworld/README.md @@ -8,7 +8,7 @@ testing). You can obtain the latter by following [these setup instructions](http ## Hello Objective-C gRPC! -Here's how to build and run the Objective-C implementation of the [Hello World](examples/protos/helloworld.proto) +Here's how to build and run the Objective-C implementation of the [Hello World](../../protos/helloworld.proto) example used in [Getting started](https://github.com/grpc/grpc/tree/master/examples). The example code for this and our other examples lives in the `examples` directory. Clone @@ -53,4 +53,4 @@ responds with a `HLWHelloResponse`, which contains a string that is then output ## Tutorial -You can find a more detailed tutorial in [gRPC Basics: Objective-C](examples/objective-c/route_guide/README.md). +You can find a more detailed tutorial in [gRPC Basics: Objective-C](../route_guide/README.md). diff --git a/examples/objective-c/route_guide/README.md b/examples/objective-c/route_guide/README.md index dd20a07995b..15864c01f4b 100644 --- a/examples/objective-c/route_guide/README.md +++ b/examples/objective-c/route_guide/README.md @@ -43,7 +43,7 @@ code is limited by the dynamic nature of the language. ## Example code and setup -The example code for our tutorial is in [examples/objective-c/route_guide](examples/objective-c/route_guide). +The example code for our tutorial is in [examples/objective-c/route_guide](.). To download the example, clone this repository by running the following command: ```shell $ git clone https://github.com/grpc/grpc.git @@ -97,7 +97,7 @@ a client library from it, and how to create an app that uses that library. First let's look at how the service we're using is defined. A gRPC *service* and its method *request* and *response* types using [protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). -You can see the complete .proto file for our example in [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto). +You can see the complete .proto file for our example in [`examples/protos/route_guide.proto`](../../protos/route_guide.proto). To define a service, you specify a named `service` in your .proto file: @@ -177,7 +177,7 @@ option objc_class_prefix = "RTG"; Next we need to generate the gRPC client interfaces from our .proto service definition. We do this using the protocol buffer compiler (`protoc`) with a special gRPC Objective-C plugin. -For simplicity, we've provided a [Podspec file](examples/objective-c/route_guide/RouteGuide.podspec) +For simplicity, we've provided a [Podspec file](RouteGuide.podspec) that runs `protoc` for you with the appropriate plugin, input, and output, and describes how to compile the generated files. You just need to run in this directory (`examples/objective-c/route_guide`): @@ -211,7 +211,7 @@ definition; just replace the name (matching the file name), version, and other m ## Creating the client In this section, we'll look at creating an Objective-C client for our `RouteGuide` service. You can -see our complete example client code in [examples/objective-c/route_guide/ViewControllers.m](examples/objective-c/route_guide/ViewControllers.m). +see our complete example client code in [ViewControllers.m](ViewControllers.m). (Note: In your apps, for maintainability and readability reasons, you shouldn't put all of your view controllers in a single file; it's done here only to simplify the learning process). diff --git a/examples/php/route_guide/README.md b/examples/php/route_guide/README.md index e5230ae4e43..258158d5d1f 100644 --- a/examples/php/route_guide/README.md +++ b/examples/php/route_guide/README.md @@ -8,7 +8,7 @@ This tutorial provides a basic PHP programmer's introduction to working with gRP It assumes a passing familiarity with [protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto2 version of the protocol buffers language. -Also note that currently you can only create clients in PHP for gRPC services - you can find out how to create gRPC servers in our other tutorials, e.g. [Node.js](examples/node/route_guide). +Also note that currently you can only create clients in PHP for gRPC services - you can find out how to create gRPC servers in our other tutorials, e.g. [Node.js](../node/route_guide). This isn't a comprehensive guide to using gRPC in PHP: more reference documentation is coming soon. @@ -29,7 +29,7 @@ With gRPC you can define your service once in a .proto file and implement client ## Example code and setup -The example code for our tutorial is in [examples/php/route_guide](examples/php/route_guide). To download the example, clone this repository by running the following command: +The example code for our tutorial is in [examples/php/route_guide](.). To download the example, clone this repository by running the following command: ```shell $ git clone https://github.com/grpc/grpc.git ``` @@ -68,7 +68,7 @@ The next sections guide you step-by-step through how this proto service is defin ## Defining the service -First let's look at how the service we're using is defined. A gRPC *service* and its method *request* and *response* types using [protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file for our example in [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto). +First let's look at how the service we're using is defined. A gRPC *service* and its method *request* and *response* types using [protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file for our example in [`route_guide.proto`](route_guide.proto). To define a service, you specify a named `service` in your .proto file: @@ -159,7 +159,7 @@ The file contains: ## Creating the client -In this section, we'll look at creating a PHP client for our `RouteGuide` service. You can see our complete example client code in [examples/php/route_guide/route_guide_client.php](examples/php/route_guide/route_guide_client.php). +In this section, we'll look at creating a PHP client for our `RouteGuide` service. You can see our complete example client code in [route_guide_client.php](route_guide_client.php). ### Constructing a client object diff --git a/examples/python/helloworld/README.md b/examples/python/helloworld/README.md index d199c401ecf..8fde0d2315c 100644 --- a/examples/python/helloworld/README.md +++ b/examples/python/helloworld/README.md @@ -1,6 +1,6 @@ # gRPC Python Hello World -This is a quick introduction with a simple example and installation instructions: for a more complete tutorial see [gRPC Basics: Python](examples/python/route_guide). +This is a quick introduction with a simple example and installation instructions: for a more complete tutorial see [gRPC Basics: Python](../route_guide). ### Install gRPC Make sure you have built gRPC Python from source on your system. Follow the instructions here: @@ -96,7 +96,7 @@ been generated for you (helloworld_pb2.py). ### The client -Client-side code can be found in [greeter_client.py](examples/python/helloworld/greeter_client.py). +Client-side code can be found in [greeter_client.py](greeter_client.py). You can run the client using: @@ -107,7 +107,7 @@ $ ./run_client.sh ### The server -Server side code can be found in [greeter_server.py](examples/python/helloworld/greeter_server.py). +Server side code can be found in [greeter_server.py](greeter_server.py). You can run the server using: diff --git a/examples/python/route_guide/README.md b/examples/python/route_guide/README.md index dc97892ea58..636e134964d 100644 --- a/examples/python/route_guide/README.md +++ b/examples/python/route_guide/README.md @@ -19,7 +19,7 @@ With gRPC you can define your service once in a .proto file and implement client ## Example code and setup -The example code for this tutorial is in [examples/python/route_guide](examples/python/route_guide). To download the example, clone this repository by running the following command: +The example code for this tutorial is in [examples/python/route_guide](.). To download the example, clone this repository by running the following command: ```shell $ git clone https://github.com/grpc/grpc.git ``` @@ -29,11 +29,11 @@ Then change your current directory to `examples/python/route_guide`: $ cd examples/python/route_guide ``` -You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Python quick start guide](examples/python). +You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Python quick start guide](../python). ## Defining the service -Your first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto). +Your first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](../../protos/route_guide.proto). To define a service, you specify a named `service` in your .proto file: @@ -115,7 +115,7 @@ Creating and running a `RouteGuide` server breaks down into two work items: - Implementing the servicer interface generated from our service definition with functions that perform the actual "work" of the service. - Running a gRPC server to listen for requests from clients and transmit responses. -You can find the example `RouteGuide` server in [examples/python/route_guide/route_guide_server.py](examples/python/route_guide/route_guide_server.py). +You can find the example `RouteGuide` server in [route_guide_server.py](route_guide_server.py). ### Implementing RouteGuide @@ -222,7 +222,7 @@ Because `start()` does not block you may need to sleep-loop if there is nothing ## Creating the client -You can see the complete example client code in [examples/python/route_guide/route_guide_client.py](examples/python/route_guide/route_guide_client.py). +You can see the complete example client code in [route_guide_client.py](route_guide_client.py). ### Creating a stub diff --git a/examples/ruby/README.md b/examples/ruby/README.md index dc21f5dd49d..36f3527006c 100644 --- a/examples/ruby/README.md +++ b/examples/ruby/README.md @@ -55,7 +55,7 @@ Try it! Tutorial -------- -You can find a more detailed tutorial in [gRPC Basics: Ruby](examples/ruby/route_guide/README.md) +You can find a more detailed tutorial in [gRPC Basics: Ruby](route_guide/README.md) -[helloworld.proto]:examples/protos/helloworld.proto +[helloworld.proto]:../protos/helloworld.proto [RVM]:https://www.rvm.io/ diff --git a/examples/ruby/route_guide/README.md b/examples/ruby/route_guide/README.md index c7231fb43f3..77e93d8bd4e 100644 --- a/examples/ruby/route_guide/README.md +++ b/examples/ruby/route_guide/README.md @@ -18,7 +18,7 @@ With gRPC we can define our service once in a .proto file and implement clients ## Example code and setup -The example code for our tutorial is in [examples/ruby/route_guide](examples/ruby/route_guide). To download the example, clone this repository by running the following command: +The example code for our tutorial is in [examples/ruby/route_guide](.). To download the example, clone this repository by running the following command: ```shell $ git clone https://github.com/grpc/grpc.git ``` @@ -28,12 +28,12 @@ Then change your current directory to `examples/ruby/route_guide`: $ cd examples/ruby/route_guide ``` -You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Ruby quick start guide](examples/ruby). +You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Ruby quick start guide](..). ## Defining the service -Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](examples/protos/route_guide.proto). +Our first step (as you'll know from [Getting started](https://github.com/grpc/grpc/tree/master/examples)) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](../../route_guide.proto). To define a service, you specify a named `service` in your .proto file: @@ -116,7 +116,7 @@ There are two parts to making our `RouteGuide` service do its job: - Implementing the service interface generated from our service definition: doing the actual "work" of our service. - Running a gRPC server to listen for requests from clients and return the service responses. -You can find our example `RouteGuide` server in [examples/ruby/route_guide/route_guide_server.rb](examples/ruby/route_guide/route_guide_server.rb). Let's take a closer look at how it works. +You can find our example `RouteGuide` server in [route_guide_server.rb](route_guide_server.rb). Let's take a closer look at how it works. ### Implementing RouteGuide @@ -199,7 +199,7 @@ As you can see, we build and start our server using a `GRPC::RpcServer`. To do t ## Creating the client -In this section, we'll look at creating a Ruby client for our `RouteGuide` service. You can see our complete example client code in [examples/ruby/route_guide/route_guide_client.rb](examples/ruby/route_guide/route_guide_client.rb). +In this section, we'll look at creating a Ruby client for our `RouteGuide` service. You can see our complete example client code in [route_guide_client.rb](route_guide_client.rb). ### Creating a stub From 391664afa1e7fc79b7817658699fc7886f70adbb Mon Sep 17 00:00:00 2001 From: Tim Emiola Date: Mon, 31 Aug 2015 15:38:43 -0700 Subject: [PATCH 27/33] Improves test stability --- src/ruby/.rspec | 1 + src/ruby/lib/grpc/generic/rpc_server.rb | 12 ++++++------ src/ruby/spec/client_server_spec.rb | 3 +-- src/ruby/spec/pb/health/checker_spec.rb | 1 - 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/ruby/.rspec b/src/ruby/.rspec index 2320752db4d..efeee2c1d22 100755 --- a/src/ruby/.rspec +++ b/src/ruby/.rspec @@ -1,5 +1,6 @@ -I. -Ipb +--backtrace --require spec_helper --format documentation --color diff --git a/src/ruby/lib/grpc/generic/rpc_server.rb b/src/ruby/lib/grpc/generic/rpc_server.rb index 38ea3334136..3740ac52da2 100644 --- a/src/ruby/lib/grpc/generic/rpc_server.rb +++ b/src/ruby/lib/grpc/generic/rpc_server.rb @@ -417,18 +417,18 @@ module GRPC begin an_rpc = @server.request_call(@cq, loop_tag, INFINITE_FUTURE) c = new_active_server_call(an_rpc) + unless c.nil? + mth = an_rpc.method.to_sym + @pool.schedule(c) do |call| + rpc_descs[mth].run_server_method(call, rpc_handlers[mth]) + end + end rescue Core::CallError, RuntimeError => e # these might happen for various reasonse. The correct behaviour of # the server is to log them and continue, if it's not shutting down. GRPC.logger.warn("server call failed: #{e}") unless stopped? next end - unless c.nil? - mth = an_rpc.method.to_sym - @pool.schedule(c) do |call| - rpc_descs[mth].run_server_method(call, rpc_handlers[mth]) - end - end end @running = false GRPC.logger.info("stopped: #{self}") diff --git a/src/ruby/spec/client_server_spec.rb b/src/ruby/spec/client_server_spec.rb index 2e673ff4138..bfd3d4188b4 100644 --- a/src/ruby/spec/client_server_spec.rb +++ b/src/ruby/spec/client_server_spec.rb @@ -28,7 +28,6 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. require 'grpc' -require 'spec_helper' include GRPC::Core @@ -47,7 +46,7 @@ shared_context 'setup: tags' do end def deadline - Time.now + 2 + Time.now + 5 end def server_allows_client_to_proceed diff --git a/src/ruby/spec/pb/health/checker_spec.rb b/src/ruby/spec/pb/health/checker_spec.rb index 6999a691058..e743ff496d7 100644 --- a/src/ruby/spec/pb/health/checker_spec.rb +++ b/src/ruby/spec/pb/health/checker_spec.rb @@ -179,7 +179,6 @@ describe Grpc::Health::Checker do describe 'running on RpcServer' do RpcServer = GRPC::RpcServer - StatusCodes = GRPC::Core::StatusCodes CheckerStub = Grpc::Health::Checker.rpc_stub_class before(:each) do From bab6706f4118dbff14c55f08fd0b5c59759cc8b8 Mon Sep 17 00:00:00 2001 From: Tim Emiola Date: Mon, 31 Aug 2015 15:51:53 -0700 Subject: [PATCH 28/33] Bumps the ruby version to beta --- src/ruby/grpc.gemspec | 2 +- src/ruby/lib/grpc/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ruby/grpc.gemspec b/src/ruby/grpc.gemspec index 20a6206e7ed..093606bb8b0 100755 --- a/src/ruby/grpc.gemspec +++ b/src/ruby/grpc.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |s| s.license = 'BSD-3-Clause' s.required_ruby_version = '>= 2.0.0' - s.requirements << 'libgrpc ~> 0.10.0 needs to be installed' + s.requirements << 'libgrpc ~> 0.11.0 needs to be installed' s.files = %w( Rakefile ) s.files += Dir.glob('lib/**/*') diff --git a/src/ruby/lib/grpc/version.rb b/src/ruby/lib/grpc/version.rb index 431e8774b58..108c22b25ed 100644 --- a/src/ruby/lib/grpc/version.rb +++ b/src/ruby/lib/grpc/version.rb @@ -29,5 +29,5 @@ # GRPC contains the General RPC module. module GRPC - VERSION = '0.10.0' + VERSION = '0.11.0' end From b6c6efdd005c231af0cb31a8db38877e6f494d2b Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 31 Aug 2015 15:56:15 -0700 Subject: [PATCH 29/33] Update Node verison to 0.11 and status to 'Beta' --- src/node/README.md | 2 +- src/node/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/node/README.md b/src/node/README.md index c96bc966429..0b97680feb9 100644 --- a/src/node/README.md +++ b/src/node/README.md @@ -1,7 +1,7 @@ # Node.js gRPC Library ## Status -Alpha : Ready for early adopters +Beta ## PREREQUISITES - `node`: This requires `node` to be installed. If you instead have the `nodejs` executable on Debian, you should install the [`nodejs-legacy`](https://packages.debian.org/sid/nodejs-legacy) package. diff --git a/src/node/package.json b/src/node/package.json index 756d41b0af2..bb8987cc0d7 100644 --- a/src/node/package.json +++ b/src/node/package.json @@ -1,6 +1,6 @@ { "name": "grpc", - "version": "0.10.0", + "version": "0.11.0", "author": "Google Inc.", "description": "gRPC Library for Node", "homepage": "http://www.grpc.io/", From 72642455a1d10656de719409806e88b6cc635758 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Mon, 31 Aug 2015 14:05:47 -0700 Subject: [PATCH 30/33] php: change routeguide package name --- examples/php/route_guide/README.md | 20 +-- examples/php/route_guide/route_guide.php | 128 +++++++++--------- examples/php/route_guide/route_guide.proto | 2 +- .../php/route_guide/route_guide_client.php | 16 +-- 4 files changed, 83 insertions(+), 83 deletions(-) diff --git a/examples/php/route_guide/README.md b/examples/php/route_guide/README.md index 258158d5d1f..00610ffb091 100644 --- a/examples/php/route_guide/README.md +++ b/examples/php/route_guide/README.md @@ -153,7 +153,7 @@ require dirname(__FILE__) . '/route_guide.php'; The file contains: - All the protocol buffer code to populate, serialize, and retrieve our request and response message types. -- A class called `examples\RouteGuideClient` that lets clients call the methods defined in the `RouteGuide` service. +- A class called `routeguide\RouteGuideClient` that lets clients call the methods defined in the `RouteGuide` service. @@ -166,7 +166,7 @@ In this section, we'll look at creating a PHP client for our `RouteGuide` servic To call service methods, we first need to create a client object, an instance of the generated `RouteGuideClient` class. The constructor of the class expects the server address and port we want to connect to: ```php -$client = new examples\RouteGuideClient(new Grpc\BaseStub('localhost:50051', [])); +$client = new routeguide\RouteGuideClient(new Grpc\BaseStub('localhost:50051', [])); ``` ### Calling service methods @@ -178,13 +178,13 @@ Now let's look at how we call our service methods. Calling the simple RPC `GetFeature` is nearly as straightforward as calling a local asynchronous method. ```php - $point = new examples\Point(); + $point = new routeguide\Point(); $point->setLatitude(409146138); $point->setLongitude(-746188906); list($feature, $status) = $client->GetFeature($point)->wait(); ``` -As you can see, we create and populate a request object, i.e. an `examples\Point` object. Then, we call the method on the stub, passing it the request object. If there is no error, then we can read the response information from the server from our response object, i.e. an `examples\Feature` object. +As you can see, we create and populate a request object, i.e. an `routeguide\Point` object. Then, we call the method on the stub, passing it the request object. If there is no error, then we can read the response information from the server from our response object, i.e. an `routeguide\Feature` object. ```php print sprintf("Found %s \n at %f, %f\n", $feature->getName(), @@ -197,15 +197,15 @@ As you can see, we create and populate a request object, i.e. an `examples\Point Now let's look at our streaming methods. Here's where we call the server-side streaming method `ListFeatures`, which returns a stream of geographical `Feature`s: ```php - $lo_point = new examples\Point(); - $hi_point = new examples\Point(); + $lo_point = new routeguide\Point(); + $hi_point = new routeguide\Point(); $lo_point->setLatitude(400000000); $lo_point->setLongitude(-750000000); $hi_point->setLatitude(420000000); $hi_point->setLongitude(-730000000); - $rectangle = new examples\Rectangle(); + $rectangle = new routeguide\Rectangle(); $rectangle->setLo($lo_point); $rectangle->setHi($hi_point); @@ -219,12 +219,12 @@ Now let's look at our streaming methods. Here's where we call the server-side st The `$call->responses()` method call returns an iterator. When the server sends a response, a `$feature` object will be returned in the `foreach` loop, until the server indiciates that there will be no more responses to be sent. -The client-side streaming method `RecordRoute` is similar, except there we pass the method an iterator and get back a `examples\RouteSummary`. +The client-side streaming method `RecordRoute` is similar, except there we pass the method an iterator and get back a `routeguide\RouteSummary`. ```php $points_iter = function($db) { for ($i = 0; $i < $num_points; $i++) { - $point = new examples\Point(); + $point = new routeguide\Point(); $point->setLatitude($lat); $point->setLongitude($long); yield $point; @@ -245,7 +245,7 @@ To write messages from the client: ```php foreach ($notes as $n) { - $route_note = new examples\RouteNote(); + $route_note = new routerguide\RouteNote(); $call->write($route_note); } $call->writesDone(); diff --git a/examples/php/route_guide/route_guide.php b/examples/php/route_guide/route_guide.php index a836e03b55b..634dfe01aa7 100644 --- a/examples/php/route_guide/route_guide.php +++ b/examples/php/route_guide/route_guide.php @@ -3,7 +3,7 @@ // Source: route_guide.proto // Date: 2015-06-12 00:32:41 -namespace examples { +namespace routeguide { class Point extends \DrSlump\Protobuf\Message { @@ -19,7 +19,7 @@ namespace examples { public static function descriptor() { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.Point'); + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Point'); // OPTIONAL INT32 latitude = 1 $f = new \DrSlump\Protobuf\Field(); @@ -58,7 +58,7 @@ namespace examples { /** * Clear value * - * @return \examples\Point + * @return \routeguide\Point */ public function clearLatitude(){ return $this->_clear(1); @@ -77,7 +77,7 @@ namespace examples { * Set value * * @param int $value - * @return \examples\Point + * @return \routeguide\Point */ public function setLatitude( $value){ return $this->_set(1, $value); @@ -95,7 +95,7 @@ namespace examples { /** * Clear value * - * @return \examples\Point + * @return \routeguide\Point */ public function clearLongitude(){ return $this->_clear(2); @@ -114,7 +114,7 @@ namespace examples { * Set value * * @param int $value - * @return \examples\Point + * @return \routeguide\Point */ public function setLongitude( $value){ return $this->_set(2, $value); @@ -122,14 +122,14 @@ namespace examples { } } -namespace examples { +namespace routeguide { class Rectangle extends \DrSlump\Protobuf\Message { - /** @var \examples\Point */ + /** @var \routeguide\Point */ public $lo = null; - /** @var \examples\Point */ + /** @var \routeguide\Point */ public $hi = null; @@ -138,7 +138,7 @@ namespace examples { public static function descriptor() { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.Rectangle'); + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Rectangle'); // OPTIONAL MESSAGE lo = 1 $f = new \DrSlump\Protobuf\Field(); @@ -146,7 +146,7 @@ namespace examples { $f->name = "lo"; $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->reference = '\examples\Point'; + $f->reference = '\routeguide\Point'; $descriptor->addField($f); // OPTIONAL MESSAGE hi = 2 @@ -155,7 +155,7 @@ namespace examples { $f->name = "hi"; $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->reference = '\examples\Point'; + $f->reference = '\routeguide\Point'; $descriptor->addField($f); foreach (self::$__extensions as $cb) { @@ -177,7 +177,7 @@ namespace examples { /** * Clear value * - * @return \examples\Rectangle + * @return \routeguide\Rectangle */ public function clearLo(){ return $this->_clear(1); @@ -186,7 +186,7 @@ namespace examples { /** * Get value * - * @return \examples\Point + * @return \routeguide\Point */ public function getLo(){ return $this->_get(1); @@ -195,10 +195,10 @@ namespace examples { /** * Set value * - * @param \examples\Point $value - * @return \examples\Rectangle + * @param \routeguide\Point $value + * @return \routeguide\Rectangle */ - public function setLo(\examples\Point $value){ + public function setLo(\routeguide\Point $value){ return $this->_set(1, $value); } @@ -214,7 +214,7 @@ namespace examples { /** * Clear value * - * @return \examples\Rectangle + * @return \routeguide\Rectangle */ public function clearHi(){ return $this->_clear(2); @@ -223,7 +223,7 @@ namespace examples { /** * Get value * - * @return \examples\Point + * @return \routeguide\Point */ public function getHi(){ return $this->_get(2); @@ -232,23 +232,23 @@ namespace examples { /** * Set value * - * @param \examples\Point $value - * @return \examples\Rectangle + * @param \routeguide\Point $value + * @return \routeguide\Rectangle */ - public function setHi(\examples\Point $value){ + public function setHi(\routeguide\Point $value){ return $this->_set(2, $value); } } } -namespace examples { +namespace routeguide { class Feature extends \DrSlump\Protobuf\Message { /** @var string */ public $name = null; - /** @var \examples\Point */ + /** @var \routeguide\Point */ public $location = null; @@ -257,7 +257,7 @@ namespace examples { public static function descriptor() { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.Feature'); + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.Feature'); // OPTIONAL STRING name = 1 $f = new \DrSlump\Protobuf\Field(); @@ -273,7 +273,7 @@ namespace examples { $f->name = "location"; $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->reference = '\examples\Point'; + $f->reference = '\routeguide\Point'; $descriptor->addField($f); foreach (self::$__extensions as $cb) { @@ -295,7 +295,7 @@ namespace examples { /** * Clear value * - * @return \examples\Feature + * @return \routeguide\Feature */ public function clearName(){ return $this->_clear(1); @@ -314,7 +314,7 @@ namespace examples { * Set value * * @param string $value - * @return \examples\Feature + * @return \routeguide\Feature */ public function setName( $value){ return $this->_set(1, $value); @@ -332,7 +332,7 @@ namespace examples { /** * Clear value * - * @return \examples\Feature + * @return \routeguide\Feature */ public function clearLocation(){ return $this->_clear(2); @@ -341,7 +341,7 @@ namespace examples { /** * Get value * - * @return \examples\Point + * @return \routeguide\Point */ public function getLocation(){ return $this->_get(2); @@ -350,20 +350,20 @@ namespace examples { /** * Set value * - * @param \examples\Point $value - * @return \examples\Feature + * @param \routeguide\Point $value + * @return \routeguide\Feature */ - public function setLocation(\examples\Point $value){ + public function setLocation(\routeguide\Point $value){ return $this->_set(2, $value); } } } -namespace examples { +namespace routeguide { class RouteNote extends \DrSlump\Protobuf\Message { - /** @var \examples\Point */ + /** @var \routeguide\Point */ public $location = null; /** @var string */ @@ -375,7 +375,7 @@ namespace examples { public static function descriptor() { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.RouteNote'); + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.RouteNote'); // OPTIONAL MESSAGE location = 1 $f = new \DrSlump\Protobuf\Field(); @@ -383,7 +383,7 @@ namespace examples { $f->name = "location"; $f->type = \DrSlump\Protobuf::TYPE_MESSAGE; $f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; - $f->reference = '\examples\Point'; + $f->reference = '\routeguide\Point'; $descriptor->addField($f); // OPTIONAL STRING message = 2 @@ -413,7 +413,7 @@ namespace examples { /** * Clear value * - * @return \examples\RouteNote + * @return \routeguide\RouteNote */ public function clearLocation(){ return $this->_clear(1); @@ -422,7 +422,7 @@ namespace examples { /** * Get value * - * @return \examples\Point + * @return \routeguide\Point */ public function getLocation(){ return $this->_get(1); @@ -431,10 +431,10 @@ namespace examples { /** * Set value * - * @param \examples\Point $value - * @return \examples\RouteNote + * @param \routeguide\Point $value + * @return \routeguide\RouteNote */ - public function setLocation(\examples\Point $value){ + public function setLocation(\routeguide\Point $value){ return $this->_set(1, $value); } @@ -450,7 +450,7 @@ namespace examples { /** * Clear value * - * @return \examples\RouteNote + * @return \routeguide\RouteNote */ public function clearMessage(){ return $this->_clear(2); @@ -469,7 +469,7 @@ namespace examples { * Set value * * @param string $value - * @return \examples\RouteNote + * @return \routeguide\RouteNote */ public function setMessage( $value){ return $this->_set(2, $value); @@ -477,7 +477,7 @@ namespace examples { } } -namespace examples { +namespace routeguide { class RouteSummary extends \DrSlump\Protobuf\Message { @@ -499,7 +499,7 @@ namespace examples { public static function descriptor() { - $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'examples.RouteSummary'); + $descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'routeguide.RouteSummary'); // OPTIONAL INT32 point_count = 1 $f = new \DrSlump\Protobuf\Field(); @@ -556,7 +556,7 @@ namespace examples { /** * Clear value * - * @return \examples\RouteSummary + * @return \routeguide\RouteSummary */ public function clearPointCount(){ return $this->_clear(1); @@ -575,7 +575,7 @@ namespace examples { * Set value * * @param int $value - * @return \examples\RouteSummary + * @return \routeguide\RouteSummary */ public function setPointCount( $value){ return $this->_set(1, $value); @@ -593,7 +593,7 @@ namespace examples { /** * Clear value * - * @return \examples\RouteSummary + * @return \routeguide\RouteSummary */ public function clearFeatureCount(){ return $this->_clear(2); @@ -612,7 +612,7 @@ namespace examples { * Set value * * @param int $value - * @return \examples\RouteSummary + * @return \routeguide\RouteSummary */ public function setFeatureCount( $value){ return $this->_set(2, $value); @@ -630,7 +630,7 @@ namespace examples { /** * Clear value * - * @return \examples\RouteSummary + * @return \routeguide\RouteSummary */ public function clearDistance(){ return $this->_clear(3); @@ -649,7 +649,7 @@ namespace examples { * Set value * * @param int $value - * @return \examples\RouteSummary + * @return \routeguide\RouteSummary */ public function setDistance( $value){ return $this->_set(3, $value); @@ -667,7 +667,7 @@ namespace examples { /** * Clear value * - * @return \examples\RouteSummary + * @return \routeguide\RouteSummary */ public function clearElapsedTime(){ return $this->_clear(4); @@ -686,7 +686,7 @@ namespace examples { * Set value * * @param int $value - * @return \examples\RouteSummary + * @return \routeguide\RouteSummary */ public function setElapsedTime( $value){ return $this->_set(4, $value); @@ -694,7 +694,7 @@ namespace examples { } } -namespace examples { +namespace routeguide { class RouteGuideClient{ @@ -704,28 +704,28 @@ namespace examples { $this->rpc_impl = $rpc_impl; } /** - * @param examples\Point $input + * @param routeguide\Point $input */ - public function GetFeature(\examples\Point $argument, $metadata = array()) { - return $this->rpc_impl->_simpleRequest('/examples.RouteGuide/GetFeature', $argument, '\examples\Feature::deserialize', $metadata); + public function GetFeature(\routeguide\Point $argument, $metadata = array()) { + return $this->rpc_impl->_simpleRequest('/routeguide.RouteGuide/GetFeature', $argument, '\routeguide\Feature::deserialize', $metadata); } /** - * @param examples\Rectangle $input + * @param routeguide\Rectangle $input */ public function ListFeatures($argument, $metadata = array()) { - return $this->rpc_impl->_serverStreamRequest('/examples.RouteGuide/ListFeatures', $argument, '\examples\Feature::deserialize', $metadata); + return $this->rpc_impl->_serverStreamRequest('/routeguide.RouteGuide/ListFeatures', $argument, '\routeguide\Feature::deserialize', $metadata); } /** - * @param examples\Point $input + * @param routeguide\Point $input */ public function RecordRoute($arguments, $metadata = array()) { - return $this->rpc_impl->_clientStreamRequest('/examples.RouteGuide/RecordRoute', $arguments, '\examples\RouteSummary::deserialize', $metadata); + return $this->rpc_impl->_clientStreamRequest('/routeguide.RouteGuide/RecordRoute', $arguments, '\routeguide\RouteSummary::deserialize', $metadata); } /** - * @param examples\RouteNote $input + * @param routeguide\RouteNote $input */ public function RouteChat($metadata = array()) { - return $this->rpc_impl->_bidiRequest('/examples.RouteGuide/RouteChat', '\examples\RouteNote::deserialize', $metadata); + return $this->rpc_impl->_bidiRequest('/routeguide.RouteGuide/RouteChat', '\routeguide\RouteNote::deserialize', $metadata); } } } diff --git a/examples/php/route_guide/route_guide.proto b/examples/php/route_guide/route_guide.proto index 0947184dbbd..d50f8a51692 100644 --- a/examples/php/route_guide/route_guide.proto +++ b/examples/php/route_guide/route_guide.proto @@ -31,7 +31,7 @@ syntax = "proto2"; option java_package = "io.grpc.examples"; -package examples; +package routeguide; // Interface exported by the server. service RouteGuide { diff --git a/examples/php/route_guide/route_guide_client.php b/examples/php/route_guide/route_guide_client.php index 6d9ae58b66c..d21a080995d 100644 --- a/examples/php/route_guide/route_guide_client.php +++ b/examples/php/route_guide/route_guide_client.php @@ -37,7 +37,7 @@ require dirname(__FILE__) . '/route_guide.php'; define('COORD_FACTOR', 1e7); -$client = new examples\RouteGuideClient( +$client = new routeguide\RouteGuideClient( new Grpc\BaseStub('localhost:50051', [])); function printFeature($feature) { @@ -60,7 +60,7 @@ function runGetFeature() { print "Running GetFeature...\n"; global $client; - $point = new examples\Point(); + $point = new routeguide\Point(); $points = array( array(409146138, -746188906), array(0, 0), @@ -84,15 +84,15 @@ function runListFeatures() { print "Running ListFeatures...\n"; global $client; - $lo_point = new examples\Point(); - $hi_point = new examples\Point(); + $lo_point = new routeguide\Point(); + $hi_point = new routeguide\Point(); $lo_point->setLatitude(400000000); $lo_point->setLongitude(-750000000); $hi_point->setLatitude(420000000); $hi_point->setLongitude(-730000000); - $rectangle = new examples\Rectangle(); + $rectangle = new routeguide\Rectangle(); $rectangle->setLo($lo_point); $rectangle->setHi($hi_point); @@ -118,7 +118,7 @@ function runRecordRoute() { $num_points_in_db = count($db); $num_points = 10; for ($i = 0; $i < $num_points; $i++) { - $point = new examples\Point(); + $point = new routeguide\Point(); $index = rand(0, $num_points_in_db - 1); $lat = $db[$index]['location']['latitude']; $long = $db[$index]['location']['longitude']; @@ -163,11 +163,11 @@ function runRouteChat() { ); foreach ($notes as $n) { - $point = new examples\Point(); + $point = new routeguide\Point(); $point->setLatitude($lat = $n[0]); $point->setLongitude($long = $n[1]); - $route_note = new examples\RouteNote(); + $route_note = new routeguide\RouteNote(); $route_note->setLocation($point); $route_note->setMessage($message = $n[2]); From c019d017af33f15a6e891595c67d4fad3f2a0d7b Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Mon, 31 Aug 2015 14:12:53 -0700 Subject: [PATCH 31/33] php: routeguide update codegen --- examples/php/route_guide/route_guide.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/examples/php/route_guide/route_guide.php b/examples/php/route_guide/route_guide.php index 634dfe01aa7..76086f9772d 100644 --- a/examples/php/route_guide/route_guide.php +++ b/examples/php/route_guide/route_guide.php @@ -1,7 +1,7 @@ rpc_impl = $rpc_impl; + public function __construct($hostname, $opts) { + parent::__construct($hostname, $opts); } /** * @param routeguide\Point $input */ - public function GetFeature(\routeguide\Point $argument, $metadata = array()) { - return $this->rpc_impl->_simpleRequest('/routeguide.RouteGuide/GetFeature', $argument, '\routeguide\Feature::deserialize', $metadata); + public function GetFeature(\routeguide\Point $argument, $metadata = array(), $options = array()) { + return $this->_simpleRequest('/routeguide.RouteGuide/GetFeature', $argument, '\routeguide\Feature::deserialize', $metadata, $options); } /** * @param routeguide\Rectangle $input */ - public function ListFeatures($argument, $metadata = array()) { - return $this->rpc_impl->_serverStreamRequest('/routeguide.RouteGuide/ListFeatures', $argument, '\routeguide\Feature::deserialize', $metadata); + public function ListFeatures($argument, $metadata = array(), $options = array()) { + return $this->_serverStreamRequest('/routeguide.RouteGuide/ListFeatures', $argument, '\routeguide\Feature::deserialize', $metadata, $options); } /** * @param routeguide\Point $input */ - public function RecordRoute($arguments, $metadata = array()) { - return $this->rpc_impl->_clientStreamRequest('/routeguide.RouteGuide/RecordRoute', $arguments, '\routeguide\RouteSummary::deserialize', $metadata); + public function RecordRoute($metadata = array()) { + return $this->_clientStreamRequest('/routeguide.RouteGuide/RecordRoute', '\routeguide\RouteSummary::deserialize', $metadata); } /** * @param routeguide\RouteNote $input */ public function RouteChat($metadata = array()) { - return $this->rpc_impl->_bidiRequest('/routeguide.RouteGuide/RouteChat', '\routeguide\RouteNote::deserialize', $metadata); + return $this->_bidiRequest('/routeguide.RouteGuide/RouteChat', '\routeguide\RouteNote::deserialize', $metadata); } } } From 61cfa57f5a1737ec7966733ec6932e1b29c33c42 Mon Sep 17 00:00:00 2001 From: yang-g Date: Mon, 31 Aug 2015 16:41:29 -0700 Subject: [PATCH 32/33] change test too --- src/objective-c/tests/LocalClearTextTests.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objective-c/tests/LocalClearTextTests.m b/src/objective-c/tests/LocalClearTextTests.m index d01fe91afaf..976fff55bcc 100644 --- a/src/objective-c/tests/LocalClearTextTests.m +++ b/src/objective-c/tests/LocalClearTextTests.m @@ -47,7 +47,7 @@ // instructions at https://github.com/grpc/homebrew-grpc static NSString * const kRouteGuideHost = @"http://localhost:50051"; -static NSString * const kPackage = @"examples"; +static NSString * const kPackage = @"routeguide"; static NSString * const kService = @"RouteGuide"; @interface LocalClearTextTests : XCTestCase From 1c09accaad6668b68ae47a7f9638bc4b79429caa Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Mon, 31 Aug 2015 16:57:32 -0700 Subject: [PATCH 33/33] change aggregation_ops to internal type --- BUILD | 3 + build.json | 1 + gRPC.podspec | 2 + include/grpc/census.h | 32 ++------- src/core/census/aggregation.h | 66 +++++++++++++++++++ tools/doxygen/Doxyfile.core.internal | 1 + tools/run_tests/sources_and_headers.json | 4 ++ vsprojects/grpc/grpc.vcxproj | 1 + vsprojects/grpc/grpc.vcxproj.filters | 3 + .../grpc_unsecure/grpc_unsecure.vcxproj | 1 + .../grpc_unsecure.vcxproj.filters | 3 + 11 files changed, 89 insertions(+), 28 deletions(-) create mode 100644 src/core/census/aggregation.h diff --git a/BUILD b/BUILD index d09a56f4efb..864d735e91f 100644 --- a/BUILD +++ b/BUILD @@ -245,6 +245,7 @@ cc_library( "src/core/transport/stream_op.h", "src/core/transport/transport.h", "src/core/transport/transport_impl.h", + "src/core/census/aggregation.h", "src/core/census/context.h", "src/core/census/rpc_metric_id.h", "src/core/httpcli/httpcli_security_connector.c", @@ -514,6 +515,7 @@ cc_library( "src/core/transport/stream_op.h", "src/core/transport/transport.h", "src/core/transport/transport_impl.h", + "src/core/census/aggregation.h", "src/core/census/context.h", "src/core/census/rpc_metric_id.h", "src/core/surface/init_unsecure.c", @@ -1271,6 +1273,7 @@ objc_library( "src/core/transport/stream_op.h", "src/core/transport/transport.h", "src/core/transport/transport_impl.h", + "src/core/census/aggregation.h", "src/core/census/context.h", "src/core/census/rpc_metric_id.h", ], diff --git a/build.json b/build.json index d62a7f34b8b..644253afc88 100644 --- a/build.json +++ b/build.json @@ -18,6 +18,7 @@ "include/grpc/census.h" ], "headers": [ + "src/core/census/aggregation.h", "src/core/census/context.h", "src/core/census/rpc_metric_id.h" ], diff --git a/gRPC.podspec b/gRPC.podspec index ff191c50731..d0e1e2d848d 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -247,6 +247,7 @@ Pod::Spec.new do |s| 'src/core/transport/stream_op.h', 'src/core/transport/transport.h', 'src/core/transport/transport_impl.h', + 'src/core/census/aggregation.h', 'src/core/census/context.h', 'src/core/census/rpc_metric_id.h', 'grpc/grpc_security.h', @@ -520,6 +521,7 @@ Pod::Spec.new do |s| 'src/core/transport/stream_op.h', 'src/core/transport/transport.h', 'src/core/transport/transport_impl.h', + 'src/core/census/aggregation.h', 'src/core/census/context.h', 'src/core/census/rpc_metric_id.h' diff --git a/include/grpc/census.h b/include/grpc/census.h index 9c0291bf964..2f36665d465 100644 --- a/include/grpc/census.h +++ b/include/grpc/census.h @@ -411,34 +411,10 @@ typedef struct { void census_record_values(census_context *context, census_value *values, size_t nvalues); -/** Structure used to describe an aggregation type. */ -typedef struct { - /* Create a new aggregation. The pointer returned can be used in future calls - to clone(), free(), record(), data() and reset(). */ - void *(*create)(const void *create_arg); - /* Make a copy of an aggregation created by create() */ - void *(*clone)(const void *aggregation); - /* Destroy an aggregation created by create() */ - void (*free)(void *aggregation); - /* Record a new value against aggregation. */ - void (*record)(void *aggregation, double value); - /* Return current aggregation data. The caller must cast this object into - the correct type for the aggregation result. The object returned can be - freed by using free_data(). */ - void *(*data)(const void *aggregation); - /* free data returned by data() */ - void (*free_data)(void *data); - /* Reset an aggregation to default (zero) values. */ - void (*reset)(void *aggregation); - /* Merge 'from' aggregation into 'to'. Both aggregations must be compatible */ - void (*merge)(void *to, const void *from); - /* Fill buffer with printable string version of aggregation contents. For - debugging only. Returns the number of bytes added to buffer (a value == n - implies the buffer was of insufficient size). */ - size_t (*print)(const void *aggregation, char *buffer, size_t n); -} census_aggregation_ops; - -/* Predefined aggregation types. */ +/** Type representing a particular aggregation */ +typedef struct census_aggregation_ops census_aggregation_ops; + +/* Predefined aggregation types, for use with census_view_create(). */ extern census_aggregation_ops census_agg_sum; extern census_aggregation_ops census_agg_distribution; extern census_aggregation_ops census_agg_histogram; diff --git a/src/core/census/aggregation.h b/src/core/census/aggregation.h new file mode 100644 index 00000000000..e9bc6ada960 --- /dev/null +++ b/src/core/census/aggregation.h @@ -0,0 +1,66 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * 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. + * + */ + +#include + +#ifndef GRPC_INTERNAL_CORE_CENSUS_AGGREGATION_H +#define GRPC_INTERNAL_CORE_CENSUS_AGGREGATION_H + +/** Structure used to describe an aggregation type. */ +struct census_aggregation_ops { + /* Create a new aggregation. The pointer returned can be used in future calls + to clone(), free(), record(), data() and reset(). */ + void *(*create)(const void *create_arg); + /* Make a copy of an aggregation created by create() */ + void *(*clone)(const void *aggregation); + /* Destroy an aggregation created by create() */ + void (*free)(void *aggregation); + /* Record a new value against aggregation. */ + void (*record)(void *aggregation, double value); + /* Return current aggregation data. The caller must cast this object into + the correct type for the aggregation result. The object returned can be + freed by using free_data(). */ + void *(*data)(const void *aggregation); + /* free data returned by data() */ + void (*free_data)(void *data); + /* Reset an aggregation to default (zero) values. */ + void (*reset)(void *aggregation); + /* Merge 'from' aggregation into 'to'. Both aggregations must be compatible */ + void (*merge)(void *to, const void *from); + /* Fill buffer with printable string version of aggregation contents. For + debugging only. Returns the number of bytes added to buffer (a value == n + implies the buffer was of insufficient size). */ + size_t (*print)(const void *aggregation, char *buffer, size_t n); +}; + +#endif /* GRPC_INTERNAL_CORE_CENSUS_AGGREGATION_H */ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 26846011ae1..729f8bf2ff7 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -881,6 +881,7 @@ src/core/transport/metadata.h \ src/core/transport/stream_op.h \ src/core/transport/transport.h \ src/core/transport/transport_impl.h \ +src/core/census/aggregation.h \ src/core/census/context.h \ src/core/census/rpc_metric_id.h \ src/core/httpcli/httpcli_security_connector.c \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 40a9fa4075e..36f8dc6f272 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -12229,6 +12229,7 @@ "include/grpc/grpc.h", "include/grpc/grpc_security.h", "include/grpc/status.h", + "src/core/census/aggregation.h", "src/core/census/context.h", "src/core/census/grpc_filter.h", "src/core/census/rpc_metric_id.h", @@ -12356,6 +12357,7 @@ "include/grpc/grpc.h", "include/grpc/grpc_security.h", "include/grpc/status.h", + "src/core/census/aggregation.h", "src/core/census/context.c", "src/core/census/context.h", "src/core/census/grpc_context.c", @@ -12707,6 +12709,7 @@ "include/grpc/compression.h", "include/grpc/grpc.h", "include/grpc/status.h", + "src/core/census/aggregation.h", "src/core/census/context.h", "src/core/census/grpc_filter.h", "src/core/census/rpc_metric_id.h", @@ -12820,6 +12823,7 @@ "include/grpc/compression.h", "include/grpc/grpc.h", "include/grpc/status.h", + "src/core/census/aggregation.h", "src/core/census/context.c", "src/core/census/context.h", "src/core/census/grpc_context.c", diff --git a/vsprojects/grpc/grpc.vcxproj b/vsprojects/grpc/grpc.vcxproj index 68be5277f0e..6857f7c9a2c 100644 --- a/vsprojects/grpc/grpc.vcxproj +++ b/vsprojects/grpc/grpc.vcxproj @@ -343,6 +343,7 @@ + diff --git a/vsprojects/grpc/grpc.vcxproj.filters b/vsprojects/grpc/grpc.vcxproj.filters index c6d88b827a9..dc35c0535f1 100644 --- a/vsprojects/grpc/grpc.vcxproj.filters +++ b/vsprojects/grpc/grpc.vcxproj.filters @@ -791,6 +791,9 @@ src\core\transport + + src\core\census + src\core\census diff --git a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj index 5aeaf89ac5a..bec4ebf6926 100644 --- a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj @@ -326,6 +326,7 @@ + diff --git a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters index ff8f3e18fa6..63d69222e84 100644 --- a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -689,6 +689,9 @@ src\core\transport + + src\core\census + src\core\census