aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2016-07-13 23:09:34 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2016-07-13 23:48:20 -0700
commit824363dc2f521d0712ab7d6bc03f15939ea51aa5 (patch)
tree43b79398d90565b19082e3e177016bfb93f63d34 /src/core
parentc0299df85decd3197c45550f19c874a8d96b8318 (diff)
Simplified LR filter
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ext/load_reporting/load_reporting.c59
-rw-r--r--src/core/ext/load_reporting/load_reporting.h31
-rw-r--r--src/core/ext/load_reporting/load_reporting_filter.c38
-rw-r--r--src/core/ext/load_reporting/load_reporting_filter.h1
4 files changed, 23 insertions, 106 deletions
diff --git a/src/core/ext/load_reporting/load_reporting.c b/src/core/ext/load_reporting/load_reporting.c
index 1a1562d058..592625496d 100644
--- a/src/core/ext/load_reporting/load_reporting.c
+++ b/src/core/ext/load_reporting/load_reporting.c
@@ -42,42 +42,13 @@
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/surface/channel_init.h"
-struct grpc_load_reporting_config {
- grpc_load_reporting_fn fn;
- void *user_data;
-};
-
-grpc_load_reporting_config *grpc_load_reporting_config_create(
- grpc_load_reporting_fn fn, void *user_data) {
- GPR_ASSERT(fn != NULL);
- grpc_load_reporting_config *lr_config =
- gpr_malloc(sizeof(grpc_load_reporting_config));
- lr_config->fn = fn;
- lr_config->user_data = user_data;
- return lr_config;
-}
-
-grpc_load_reporting_config *grpc_load_reporting_config_copy(
- grpc_load_reporting_config *src) {
- return grpc_load_reporting_config_create(src->fn, src->user_data);
-}
-
-void grpc_load_reporting_config_destroy(grpc_load_reporting_config *lr_config) {
- gpr_free(lr_config);
-}
-
-void grpc_load_reporting_config_call(
- grpc_load_reporting_config *lr_config,
- const grpc_load_reporting_call_data *call_data) {
- lr_config->fn(call_data, lr_config->user_data);
-}
static bool is_load_reporting_enabled(const grpc_channel_args *a) {
if (a == NULL) return false;
for (size_t i = 0; i < a->num_args; i++) {
if (0 == strcmp(a->args[i].key, GRPC_ARG_ENABLE_LOAD_REPORTING)) {
- return a->args[i].type == GRPC_ARG_POINTER &&
- a->args[i].value.pointer.p != NULL;
+ return a->args[i].type == GRPC_ARG_INTEGER &&
+ a->args[i].value.integer != 0;
}
}
return false;
@@ -94,37 +65,17 @@ static bool maybe_add_load_reporting_filter(grpc_channel_stack_builder *builder,
return true;
}
-static void lrd_arg_destroy(void *p) { grpc_load_reporting_config_destroy(p); }
-
-static void *lrd_arg_copy(void *p) {
- return grpc_load_reporting_config_copy(p);
-}
-
-static int lrd_arg_cmp(void *a, void *b) {
- grpc_load_reporting_config *lhs = a;
- grpc_load_reporting_config *rhs = b;
- return !(lhs->fn == rhs->fn && lhs->user_data == rhs->user_data);
-}
-
-static const grpc_arg_pointer_vtable lrd_ptr_vtable = {
- lrd_arg_copy, lrd_arg_destroy, lrd_arg_cmp};
-
-grpc_arg grpc_load_reporting_config_create_arg(
- grpc_load_reporting_config *lr_config) {
+grpc_arg grpc_load_reporting_enable_arg() {
grpc_arg arg;
- arg.type = GRPC_ARG_POINTER;
+ arg.type = GRPC_ARG_INTEGER;
arg.key = GRPC_ARG_ENABLE_LOAD_REPORTING;
- arg.value.pointer.p = lr_config;
- arg.value.pointer.vtable = &lrd_ptr_vtable;
+ arg.value.integer = 1;
return arg;
}
/* Plugin registration */
void grpc_load_reporting_plugin_init(void) {
- grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX,
- maybe_add_load_reporting_filter,
- (void *)&grpc_load_reporting_filter);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX,
maybe_add_load_reporting_filter,
(void *)&grpc_load_reporting_filter);
diff --git a/src/core/ext/load_reporting/load_reporting.h b/src/core/ext/load_reporting/load_reporting.h
index 6a9772a2bd..c3161bebb7 100644
--- a/src/core/ext/load_reporting/load_reporting.h
+++ b/src/core/ext/load_reporting/load_reporting.h
@@ -43,8 +43,6 @@
/** Metadata key for trailing metadata from servers */
#define GRPC_LOAD_REPORTING_TRAILING_MD_KEY "load-reporting-trailing"
-typedef struct grpc_load_reporting_config grpc_load_reporting_config;
-
/** Identifiers for the invocation point of the users LR callback */
typedef enum grpc_load_reporting_source {
GRPC_LR_POINT_UNKNOWN = 0,
@@ -75,33 +73,6 @@ typedef struct grpc_load_reporting_call_data {
} grpc_load_reporting_call_data;
/** Return a \a grpc_arg enabling load reporting */
-grpc_arg grpc_load_reporting_config_create_arg(
- grpc_load_reporting_config *lr_config);
-
-/** Custom function to be called by the load reporting filter.
- *
- * \a call_data is provided by the runtime. \a user_data is given by the user
- * as part of \a grpc_load_reporting_config_create */
-typedef void (*grpc_load_reporting_fn)(
- const grpc_load_reporting_call_data *call_data, void *user_data);
-
-/** Register \a fn as the function to be invoked by the load reporting filter.
- * \a fn will be invoked at the beginning and at the end of the call.
- *
- * For the first invocation, \a fn's first argument
- * (grpc_load_reporting_call_data*) will be NULL. \a user_data is always passed
- * as-is. */
-grpc_load_reporting_config *grpc_load_reporting_config_create(
- grpc_load_reporting_fn fn, void *user_data);
-
-grpc_load_reporting_config *grpc_load_reporting_config_copy(
- grpc_load_reporting_config *src);
-
-void grpc_load_reporting_config_destroy(grpc_load_reporting_config *lr_config);
-
-/** Invoke the LR callback from \a lr_config with \a call_data */
-void grpc_load_reporting_config_call(
- grpc_load_reporting_config *lr_config,
- const grpc_load_reporting_call_data *call_data);
+grpc_arg grpc_load_reporting_enable_arg();
#endif /* GRPC_CORE_EXT_LOAD_REPORTING_LOAD_REPORTING_H */
diff --git a/src/core/ext/load_reporting/load_reporting_filter.c b/src/core/ext/load_reporting/load_reporting_filter.c
index 55e06f2774..65aba2a650 100644
--- a/src/core/ext/load_reporting/load_reporting_filter.c
+++ b/src/core/ext/load_reporting/load_reporting_filter.c
@@ -43,6 +43,11 @@
#include "src/core/lib/profiling/timers.h"
#include "src/core/lib/transport/static_metadata.h"
+void (*g_load_reporting_fn)(const grpc_load_reporting_call_data *call_data);
+
+/* The function to be defined */
+void load_reporting_fn(const grpc_load_reporting_call_data *call_data) {}
+
typedef struct call_data {
intptr_t id; /**< an id unique to the call */
char *trailing_md_string;
@@ -61,14 +66,15 @@ typedef struct call_data {
typedef struct channel_data {
intptr_t id; /**< an id unique to the channel */
- grpc_load_reporting_config *lr_config;
} channel_data;
-static void invoke_lr_fn_locked(grpc_load_reporting_config *lr_config,
- grpc_load_reporting_call_data *lr_call_data) {
- GPR_TIMER_BEGIN("load_reporting_config_fn", 0);
- grpc_load_reporting_config_call(lr_config, lr_call_data);
- GPR_TIMER_END("load_reporting_config_fn", 0);
+static void invoke_lr_fn(grpc_load_reporting_call_data *lr_call_data) {
+ if (g_load_reporting_fn == NULL) {
+ g_load_reporting_fn = load_reporting_fn;
+ }
+ GPR_TIMER_BEGIN("load_reporting_fn", 0);
+ g_load_reporting_fn(lr_call_data);
+ GPR_TIMER_END("load_reporting_fn", 0);
}
typedef struct {
@@ -130,7 +136,7 @@ static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
NULL,
NULL,
NULL};
- invoke_lr_fn_locked(chand->lr_config, &lr_call_data);
+ invoke_lr_fn(&lr_call_data);
}
/* Destructor for call_data */
@@ -148,7 +154,7 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
calld->trailing_md_string,
calld->service_method};
- invoke_lr_fn_locked(chand->lr_config, &lr_call_data);
+ invoke_lr_fn(&lr_call_data);
gpr_free(calld->initial_md_string);
gpr_free(calld->trailing_md_string);
@@ -164,17 +170,6 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
memset(chand, 0, sizeof(channel_data));
chand->id = (intptr_t)args->channel_stack;
- for (size_t i = 0; i < args->channel_args->num_args; i++) {
- if (0 == strcmp(args->channel_args->args[i].key,
- GRPC_ARG_ENABLE_LOAD_REPORTING)) {
- grpc_load_reporting_config *arg_lr_config =
- args->channel_args->args[i].value.pointer.p;
- chand->lr_config = grpc_load_reporting_config_copy(arg_lr_config);
- GPR_ASSERT(chand->lr_config != NULL);
- break;
- }
- }
- GPR_ASSERT(chand->lr_config != NULL); /* arg actually found */
grpc_load_reporting_call_data lr_call_data = {GRPC_LR_POINT_CHANNEL_CREATION,
(intptr_t)chand,
@@ -183,7 +178,7 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
NULL,
NULL,
NULL};
- invoke_lr_fn_locked(chand->lr_config, &lr_call_data);
+ invoke_lr_fn(&lr_call_data);
}
/* Destructor for channel data */
@@ -198,8 +193,7 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
NULL,
NULL,
NULL};
- invoke_lr_fn_locked(chand->lr_config, &lr_call_data);
- grpc_load_reporting_config_destroy(chand->lr_config);
+ invoke_lr_fn(&lr_call_data);
}
static grpc_mdelem *lr_trailing_md_filter(void *user_data, grpc_mdelem *md) {
diff --git a/src/core/ext/load_reporting/load_reporting_filter.h b/src/core/ext/load_reporting/load_reporting_filter.h
index f69cd6fdc6..160ed32af9 100644
--- a/src/core/ext/load_reporting/load_reporting_filter.h
+++ b/src/core/ext/load_reporting/load_reporting_filter.h
@@ -34,6 +34,7 @@
#ifndef GRPC_CORE_EXT_LOAD_REPORTING_LOAD_REPORTING_FILTER_H
#define GRPC_CORE_EXT_LOAD_REPORTING_LOAD_REPORTING_FILTER_H
+#include "src/core/ext/load_reporting/load_reporting.h"
#include "src/core/lib/channel/channel_stack.h"
extern const grpc_channel_filter grpc_load_reporting_filter;