Skip to content

Commit

Permalink
removed some bits from invalid LR design
Browse files Browse the repository at this point in the history
  • Loading branch information
dgquintas committed Jul 27, 2016
1 parent 824363d commit fa30de9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 81 deletions.
2 changes: 2 additions & 0 deletions src/core/ext/load_reporting/load_reporting.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
#include "src/core/lib/channel/channel_stack.h"

/** Metadata key for initial metadata coming from clients */
/* TODO(dgq): change to the final value TBD */
#define GRPC_LOAD_REPORTING_INITIAL_MD_KEY "load-reporting-initial"

/** Metadata key for trailing metadata from servers */
/* TODO(dgq): change to the final value TBD */
#define GRPC_LOAD_REPORTING_TRAILING_MD_KEY "load-reporting-trailing"

/** Identifiers for the invocation point of the users LR callback */
Expand Down
33 changes: 12 additions & 21 deletions src/core/ext/load_reporting/load_reporting_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
#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;
Expand All @@ -68,15 +63,6 @@ typedef struct channel_data {
intptr_t id; /**< an id unique to the channel */
} channel_data;

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 {
grpc_call_element *elem;
grpc_exec_ctx *exec_ctx;
Expand All @@ -91,6 +77,7 @@ static grpc_mdelem *recv_md_filter(void *user_data, grpc_mdelem *md) {
calld->service_method = grpc_mdstr_as_c_string(md->value);
} else if (md->key == GRPC_MDSTR_LOAD_REPORTING_INITIAL) {
calld->initial_md_string = gpr_strdup(grpc_mdstr_as_c_string(md->value));
return NULL;
}

return md;
Expand Down Expand Up @@ -122,39 +109,40 @@ static void on_initial_md_ready(grpc_exec_ctx *exec_ctx, void *user_data,
/* Constructor for call_data */
static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
grpc_call_element_args *args) {
channel_data *chand = elem->channel_data;
call_data *calld = elem->call_data;
memset(calld, 0, sizeof(call_data));

calld->id = (intptr_t)args->call_stack;
grpc_closure_init(&calld->on_initial_md_ready, on_initial_md_ready, elem);

/* TODO(dgq): do something with the data
channel_data *chand = elem->channel_data;
grpc_load_reporting_call_data lr_call_data = {GRPC_LR_POINT_CALL_CREATION,
(intptr_t)chand->id,
(intptr_t)calld->id,
NULL,
NULL,
NULL,
NULL};
invoke_lr_fn(&lr_call_data);
*/
}

/* Destructor for call_data */
static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
const grpc_call_final_info *final_info,
void *ignored) {
channel_data *chand = elem->channel_data;
call_data *calld = elem->call_data;

/* TODO(dgq): do something with the data
channel_data *chand = elem->channel_data;
grpc_load_reporting_call_data lr_call_data = {GRPC_LR_POINT_CALL_DESTRUCTION,
(intptr_t)chand->id,
(intptr_t)calld->id,
final_info,
calld->initial_md_string,
calld->trailing_md_string,
calld->service_method};

invoke_lr_fn(&lr_call_data);
*/

gpr_free(calld->initial_md_string);
gpr_free(calld->trailing_md_string);
Expand All @@ -171,19 +159,21 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,

chand->id = (intptr_t)args->channel_stack;

/* TODO(dgq): do something with the data
grpc_load_reporting_call_data lr_call_data = {GRPC_LR_POINT_CHANNEL_CREATION,
(intptr_t)chand,
0,
NULL,
NULL,
NULL,
NULL};
invoke_lr_fn(&lr_call_data);
*/
}

/* Destructor for channel data */
static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
grpc_channel_element *elem) {
/* TODO(dgq): do something with the data
channel_data *chand = elem->channel_data;
grpc_load_reporting_call_data lr_call_data = {
GRPC_LR_POINT_CHANNEL_DESTRUCTION,
Expand All @@ -193,7 +183,7 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
NULL,
NULL,
NULL};
invoke_lr_fn(&lr_call_data);
*/
}

static grpc_mdelem *lr_trailing_md_filter(void *user_data, grpc_mdelem *md) {
Expand All @@ -202,6 +192,7 @@ static grpc_mdelem *lr_trailing_md_filter(void *user_data, grpc_mdelem *md) {

if (md->key == GRPC_MDSTR_LOAD_REPORTING_TRAILING) {
calld->trailing_md_string = gpr_strdup(grpc_mdstr_as_c_string(md->value));
return NULL;
}

return md;
Expand Down
62 changes: 2 additions & 60 deletions test/core/end2end/tests/load_reporting_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,44 +69,6 @@ typedef struct {
bool fully_processed;
} load_reporting_data;

static load_reporting_data lr_data;

static void load_reporting_test_fn(
const grpc_load_reporting_call_data *call_data) {
gpr_mu_lock(&lr_data.mu);
switch (call_data->source) {
case GRPC_LR_POINT_CHANNEL_CREATION:
lr_data.channel_id = call_data->channel_id;
break;
case GRPC_LR_POINT_CHANNEL_DESTRUCTION:
break;
case GRPC_LR_POINT_CALL_CREATION:
lr_data.call_id = call_data->call_id;
break;
case GRPC_LR_POINT_CALL_DESTRUCTION:
if (lr_data.initial_md_str == NULL) {
lr_data.initial_md_str = gpr_strdup(call_data->initial_md_string);
}
if (lr_data.trailing_md_str == NULL) {
lr_data.trailing_md_str = gpr_strdup(call_data->trailing_md_string);
}
if (lr_data.method_name == NULL) {
lr_data.method_name = gpr_strdup(call_data->method_name);
}

lr_data.incoming_bytes = call_data->final_info->stats
.transport_stream_stats.incoming.data_bytes;
lr_data.outgoing_bytes = call_data->final_info->stats
.transport_stream_stats.outgoing.data_bytes;
lr_data.call_final_status = call_data->final_info->final_status;
lr_data.fully_processed = true;
break;
default:
abort();
}
gpr_mu_unlock(&lr_data.mu);
}

static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
const char *test_name,
grpc_channel_args *client_args,
Expand Down Expand Up @@ -315,8 +277,8 @@ extern void (*g_load_reporting_fn)(
const grpc_load_reporting_call_data *call_data);

static void test_load_reporting_hook(grpc_end2end_test_config config) {
gpr_mu_init(&lr_data.mu);
g_load_reporting_fn = load_reporting_test_fn;
/* TODO(dgq): this test is currently a noop until LR is fully defined.
* Leaving the rest here, as it'll likely be reusable. */

/* Introduce load reporting for the server through its arguments */
grpc_arg arg = grpc_load_reporting_enable_arg();
Expand Down Expand Up @@ -350,26 +312,6 @@ static void test_load_reporting_hook(grpc_end2end_test_config config) {
end_test(&f);
grpc_channel_args_destroy(lr_server_args);
config.tear_down_data(&f);

GPR_ASSERT(lr_data.fully_processed);
GPR_ASSERT(lr_data.incoming_bytes == strlen(request_msg));
GPR_ASSERT(lr_data.outgoing_bytes == strlen(response_msg));

GPR_ASSERT(lr_data.call_id > 0);
GPR_ASSERT(lr_data.channel_id > 0);

GPR_ASSERT(strcmp(lr_data.method_name, "/gRPCFTW") == 0);

GPR_ASSERT(lr_data.initial_md_str != NULL);
GPR_ASSERT(lr_data.trailing_md_str != NULL);
GPR_ASSERT(strcmp(lr_data.initial_md_str, "client-token") == 0);
GPR_ASSERT(strcmp(lr_data.trailing_md_str, "server-token") == 0);

GPR_ASSERT(lr_data.call_final_status == GRPC_STATUS_OK);

gpr_free(lr_data.initial_md_str);
gpr_free(lr_data.trailing_md_str);
gpr_free(lr_data.method_name);
}

void load_reporting_hook(grpc_end2end_test_config config) {
Expand Down

0 comments on commit fa30de9

Please sign in to comment.