Skip to content

Commit

Permalink
Merge pull request grpc#3107 from a-veitch/view_api
Browse files Browse the repository at this point in the history
API for: defining view and aggregations, associating them with metrics, and retrieving data
  • Loading branch information
maxwell-demon committed Sep 1, 2015
2 parents 5cf62b3 1c09acc commit 106e154
Show file tree
Hide file tree
Showing 14 changed files with 191 additions and 78 deletions.
12 changes: 6 additions & 6 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 = \
Expand Down Expand Up @@ -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 = \
Expand Down
4 changes: 2 additions & 2 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
Expand Down
7 changes: 4 additions & 3 deletions gRPC.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 = '.'

Expand Down
105 changes: 98 additions & 7 deletions include/grpc/census.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
36 changes: 32 additions & 4 deletions src/core/census/record_stat.c → src/core/census/aggregation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
32 changes: 11 additions & 21 deletions src/core/census/grpc_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"};
27 changes: 16 additions & 11 deletions src/core/census/rpc_stat_id.h → src/core/census/rpc_metric_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions tools/doxygen/Doxyfile.core.internal
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
Loading

0 comments on commit 106e154

Please sign in to comment.