Merge pull request #3107 from a-veitch/view_api

API for: defining view and aggregations, associating them with metrics, and retrieving data
pull/2707/merge
Hongyu Chen 9 years ago
commit 106e15432e
  1. 12
      BUILD
  2. 2
      Makefile
  3. 4
      build.json
  4. 7
      gRPC.podspec
  5. 105
      include/grpc/census.h
  6. 36
      src/core/census/aggregation.h
  7. 32
      src/core/census/grpc_filter.c
  8. 27
      src/core/census/rpc_metric_id.h
  9. 4
      tools/doxygen/Doxyfile.core.internal
  10. 14
      tools/run_tests/sources_and_headers.json
  11. 5
      vsprojects/grpc/grpc.vcxproj
  12. 8
      vsprojects/grpc/grpc.vcxproj.filters
  13. 5
      vsprojects/grpc_unsecure/grpc_unsecure.vcxproj
  14. 8
      vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters

12
BUILD

@ -245,8 +245,9 @@ 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_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",
@ -387,7 +388,6 @@ cc_library(
"src/core/census/context.c",
"src/core/census/initialize.c",
"src/core/census/operation.c",
"src/core/census/record_stat.c",
"src/core/census/tracing.c",
],
hdrs = [
@ -515,8 +515,9 @@ 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_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",
@ -637,7 +638,6 @@ cc_library(
"src/core/census/context.c",
"src/core/census/initialize.c",
"src/core/census/operation.c",
"src/core/census/record_stat.c",
"src/core/census/tracing.c",
],
hdrs = [
@ -1151,7 +1151,6 @@ objc_library(
"src/core/census/context.c",
"src/core/census/initialize.c",
"src/core/census/operation.c",
"src/core/census/record_stat.c",
"src/core/census/tracing.c",
],
hdrs = [
@ -1276,8 +1275,9 @@ 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_stat_id.h",
"src/core/census/rpc_metric_id.h",
],
includes = [
"include",

@ -4150,7 +4150,6 @@ LIBGRPC_SRC = \
src/core/census/context.c \
src/core/census/initialize.c \
src/core/census/operation.c \
src/core/census/record_stat.c \
src/core/census/tracing.c \
PUBLIC_HEADERS_C += \
@ -4426,7 +4425,6 @@ LIBGRPC_UNSECURE_SRC = \
src/core/census/context.c \
src/core/census/initialize.c \
src/core/census/operation.c \
src/core/census/record_stat.c \
src/core/census/tracing.c \
PUBLIC_HEADERS_C += \

@ -18,14 +18,14 @@
"include/grpc/census.h"
],
"headers": [
"src/core/census/aggregation.h",
"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/operation.c",
"src/core/census/record_stat.c",
"src/core/census/tracing.c"
]
},

@ -247,8 +247,9 @@ 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_stat_id.h',
'src/core/census/rpc_metric_id.h',
'grpc/grpc_security.h',
'grpc/byte_buffer.h',
'grpc/byte_buffer_reader.h',
@ -396,7 +397,6 @@ Pod::Spec.new do |s|
'src/core/census/context.c',
'src/core/census/initialize.c',
'src/core/census/operation.c',
'src/core/census/record_stat.c',
'src/core/census/tracing.c'
ss.private_header_files = 'src/core/support/env.h',
@ -521,8 +521,9 @@ 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_stat_id.h'
'src/core/census/rpc_metric_id.h'
ss.header_mappings_dir = '.'

@ -379,16 +379,107 @@ 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. The following concepts are used:
* Aggregation: A collection of values. Census supports the following
aggregation types:
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.
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 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
* metric and the value to be recorded against it. */
typedef struct {
int id;
gpr_uint32 metric_id;
double value;
} census_stat;
} census_value;
/* Record new usage values against the given context. */
void census_record_values(census_context *context, census_value *values,
size_t nvalues);
/** 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;
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_ops *ops;
const void
*create_arg; /* Argument to be used for aggregation initialization. */
} census_aggregation;
/** A census view type. Opaque. */
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
*/
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);
/** 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);
/** Get tags associated with view. */
const census_tag_set *census_view_tags(const census_view *view);
/** Get aggregation descriptors associated with a 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(). */
typedef struct {
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_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 */
} census_view_data;
/** Get data from aggregations associated with a view.
@param view View from which to get data.
@return Full set of data for all aggregations for the view.
*/
const census_view_data *census_view_get_data(const census_view *view);
/* Record new stats against the given context. */
void census_record_stat(census_context *context, census_stat *stats,
size_t nstats);
/** Reset all view data to zero for the specified view */
void census_view_reset(census_view *view);
#ifdef __cplusplus
}

@ -31,8 +31,36 @@
*
*/
#include <grpc/census.h>
#include "src/core/census/rpc_stat_id.h"
#include <stddef.h>
void census_record_stat(census_context *context, census_stat *stats,
size_t nstats) {}
#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 */

@ -36,7 +36,7 @@
#include <stdio.h>
#include <string.h>
#include "src/core/census/rpc_stat_id.h"
#include "include/grpc/census.h"
#include "src/core/channel/channel_stack.h"
#include "src/core/channel/noop_filter.h"
#include "src/core/statistics/census_interface.h"
@ -173,25 +173,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"};

@ -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_uint32)0)
/* Count of server requests sent. */
#define CENSUS_METRIC_RPC_SERVER_REQUESTS ((gpr_uint32)1)
/* Client error counts. */
#define CENSUS_METRIC_RPC_CLIENT_ERRORS ((gpr_uint32)2)
/* Server error counts. */
#define CENSUS_METRIC_RPC_SERVER_ERRORS ((gpr_uint32)3)
/* Client side request latency. */
#define CENSUS_METRIC_RPC_CLIENT_LATENCY ((gpr_uint32)4)
/* Server side request latency. */
#define CENSUS_METRIC_RPC_SERVER_LATENCY ((gpr_uint32)5)
#endif /* CENSUS_RPC_STAT_ID_H */
#endif /* CENSUS_RPC_METRIC_ID_H */

@ -881,8 +881,9 @@ 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_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 +1024,6 @@ src/core/transport/transport_op_string.c \
src/core/census/context.c \
src/core/census/initialize.c \
src/core/census/operation.c \
src/core/census/record_stat.c \
src/core/census/tracing.c \
include/grpc/support/alloc.h \
include/grpc/support/atm.h \

@ -12229,9 +12229,10 @@
"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_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",
@ -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",
@ -12363,8 +12365,7 @@
"src/core/census/grpc_filter.h",
"src/core/census/initialize.c",
"src/core/census/operation.c",
"src/core/census/record_stat.c",
"src/core/census/rpc_stat_id.h",
"src/core/census/rpc_metric_id.h",
"src/core/census/tracing.c",
"src/core/channel/channel_args.c",
"src/core/channel/channel_args.h",
@ -12708,9 +12709,10 @@
"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_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",
@ -12821,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",
@ -12828,8 +12831,7 @@
"src/core/census/grpc_filter.h",
"src/core/census/initialize.c",
"src/core/census/operation.c",
"src/core/census/record_stat.c",
"src/core/census/rpc_stat_id.h",
"src/core/census/rpc_metric_id.h",
"src/core/census/tracing.c",
"src/core/channel/channel_args.c",
"src/core/channel/channel_args.h",

@ -343,8 +343,9 @@
<ClInclude Include="..\..\src\core\transport\stream_op.h" />
<ClInclude Include="..\..\src\core\transport\transport.h" />
<ClInclude Include="..\..\src\core\transport\transport_impl.h" />
<ClInclude Include="..\..\src\core\census\aggregation.h" />
<ClInclude Include="..\..\src\core\census\context.h" />
<ClInclude Include="..\..\src\core\census\rpc_stat_id.h" />
<ClInclude Include="..\..\src\core\census\rpc_metric_id.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\core\httpcli\httpcli_security_connector.c">
@ -627,8 +628,6 @@
</ClCompile>
<ClCompile Include="..\..\src\core\census\operation.c">
</ClCompile>
<ClCompile Include="..\..\src\core\census\record_stat.c">
</ClCompile>
<ClCompile Include="..\..\src\core\census\tracing.c">
</ClCompile>
</ItemGroup>

@ -421,9 +421,6 @@
<ClCompile Include="..\..\src\core\census\operation.c">
<Filter>src\core\census</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\census\record_stat.c">
<Filter>src\core\census</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\census\tracing.c">
<Filter>src\core\census</Filter>
</ClCompile>
@ -794,10 +791,13 @@
<ClInclude Include="..\..\src\core\transport\transport_impl.h">
<Filter>src\core\transport</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\census\aggregation.h">
<Filter>src\core\census</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\census\context.h">
<Filter>src\core\census</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\census\rpc_stat_id.h">
<ClInclude Include="..\..\src\core\census\rpc_metric_id.h">
<Filter>src\core\census</Filter>
</ClInclude>
</ItemGroup>

@ -326,8 +326,9 @@
<ClInclude Include="..\..\src\core\transport\stream_op.h" />
<ClInclude Include="..\..\src\core\transport\transport.h" />
<ClInclude Include="..\..\src\core\transport\transport_impl.h" />
<ClInclude Include="..\..\src\core\census\aggregation.h" />
<ClInclude Include="..\..\src\core\census\context.h" />
<ClInclude Include="..\..\src\core\census\rpc_stat_id.h" />
<ClInclude Include="..\..\src\core\census\rpc_metric_id.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\core\surface\init_unsecure.c">
@ -570,8 +571,6 @@
</ClCompile>
<ClCompile Include="..\..\src\core\census\operation.c">
</ClCompile>
<ClCompile Include="..\..\src\core\census\record_stat.c">
</ClCompile>
<ClCompile Include="..\..\src\core\census\tracing.c">
</ClCompile>
</ItemGroup>

@ -361,9 +361,6 @@
<ClCompile Include="..\..\src\core\census\operation.c">
<Filter>src\core\census</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\census\record_stat.c">
<Filter>src\core\census</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\census\tracing.c">
<Filter>src\core\census</Filter>
</ClCompile>
@ -692,10 +689,13 @@
<ClInclude Include="..\..\src\core\transport\transport_impl.h">
<Filter>src\core\transport</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\census\aggregation.h">
<Filter>src\core\census</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\census\context.h">
<Filter>src\core\census</Filter>
</ClInclude>
<ClInclude Include="..\..\src\core\census\rpc_stat_id.h">
<ClInclude Include="..\..\src\core\census\rpc_metric_id.h">
<Filter>src\core\census</Filter>
</ClInclude>
</ItemGroup>

Loading…
Cancel
Save