From ade0021289f366d5bc7e5d6fc669217280e4e828 Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Tue, 25 Aug 2015 15:00:26 -0700 Subject: [PATCH 01/11] 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 02/11] 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 03/11] 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 04/11] 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 05/11] 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 8f691e6c947092da9c046b451f7666fc981fae8f Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Mon, 31 Aug 2015 08:27:11 -0700 Subject: [PATCH 06/11] 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 07/11] 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 08/11] 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 09/11] 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 aafe9725b058d3710209bf0c95911928428eb2f2 Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Mon, 31 Aug 2015 13:15:00 -0700 Subject: [PATCH 10/11] 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 1c09accaad6668b68ae47a7f9638bc4b79429caa Mon Sep 17 00:00:00 2001 From: Alistair Veitch Date: Mon, 31 Aug 2015 16:57:32 -0700 Subject: [PATCH 11/11] 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