|
|
@ -47,13 +47,12 @@ |
|
|
|
|
|
|
|
|
|
|
|
typedef struct call_data { |
|
|
|
typedef struct call_data { |
|
|
|
census_op_id op_id; |
|
|
|
census_op_id op_id; |
|
|
|
census_rpc_stats stats; |
|
|
|
/*census_rpc_stats stats;*/ |
|
|
|
gpr_timespec start_ts; |
|
|
|
gpr_timespec start_ts; |
|
|
|
|
|
|
|
|
|
|
|
/* recv callback */ |
|
|
|
/* recv callback */ |
|
|
|
grpc_stream_op_buffer* recv_ops; |
|
|
|
grpc_stream_op_buffer* recv_ops; |
|
|
|
void (*on_done_recv)(void* user_data, int success); |
|
|
|
grpc_iomgr_closure* on_done_recv; |
|
|
|
void* recv_user_data; |
|
|
|
|
|
|
|
} call_data; |
|
|
|
} call_data; |
|
|
|
|
|
|
|
|
|
|
|
typedef struct channel_data { |
|
|
|
typedef struct channel_data { |
|
|
@ -108,7 +107,7 @@ static void server_on_done_recv(void* ptr, int success) { |
|
|
|
if (success) { |
|
|
|
if (success) { |
|
|
|
extract_and_annotate_method_tag(calld->recv_ops, calld, chand); |
|
|
|
extract_and_annotate_method_tag(calld->recv_ops, calld, chand); |
|
|
|
} |
|
|
|
} |
|
|
|
calld->on_done_recv(calld->recv_user_data, success); |
|
|
|
calld->on_done_recv->cb(calld->on_done_recv->cb_arg, success); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void server_mutate_op(grpc_call_element* elem, |
|
|
|
static void server_mutate_op(grpc_call_element* elem, |
|
|
@ -118,9 +117,7 @@ static void server_mutate_op(grpc_call_element* elem, |
|
|
|
/* substitute our callback for the op callback */ |
|
|
|
/* substitute our callback for the op callback */ |
|
|
|
calld->recv_ops = op->recv_ops; |
|
|
|
calld->recv_ops = op->recv_ops; |
|
|
|
calld->on_done_recv = op->on_done_recv; |
|
|
|
calld->on_done_recv = op->on_done_recv; |
|
|
|
calld->recv_user_data = op->recv_user_data; |
|
|
|
op->on_done_recv = calld->on_done_recv; |
|
|
|
op->on_done_recv = server_on_done_recv; |
|
|
|
|
|
|
|
op->recv_user_data = elem; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -132,19 +129,6 @@ static void server_start_transport_op(grpc_call_element* elem, |
|
|
|
grpc_call_next_op(elem, op); |
|
|
|
grpc_call_next_op(elem, op); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void channel_op(grpc_channel_element* elem, |
|
|
|
|
|
|
|
grpc_channel_element* from_elem, grpc_channel_op* op) { |
|
|
|
|
|
|
|
switch (op->type) { |
|
|
|
|
|
|
|
case GRPC_TRANSPORT_CLOSED: |
|
|
|
|
|
|
|
/* TODO(hongyu): Annotate trace information for all calls of the channel
|
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
grpc_channel_next_op(elem, op); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void client_init_call_elem(grpc_call_element* elem, |
|
|
|
static void client_init_call_elem(grpc_call_element* elem, |
|
|
|
const void* server_transport_data, |
|
|
|
const void* server_transport_data, |
|
|
|
grpc_transport_stream_op* initial_op) { |
|
|
|
grpc_transport_stream_op* initial_op) { |
|
|
@ -171,6 +155,7 @@ static void server_init_call_elem(grpc_call_element* elem, |
|
|
|
init_rpc_stats(&d->stats); |
|
|
|
init_rpc_stats(&d->stats); |
|
|
|
d->start_ts = gpr_now(GPR_CLOCK_REALTIME); |
|
|
|
d->start_ts = gpr_now(GPR_CLOCK_REALTIME); |
|
|
|
d->op_id = census_tracing_start_op(); |
|
|
|
d->op_id = census_tracing_start_op(); |
|
|
|
|
|
|
|
grpc_iomgr_closure_init(d->on_done_recv, server_on_done_recv, elem); |
|
|
|
if (initial_op) server_mutate_op(elem, initial_op); |
|
|
|
if (initial_op) server_mutate_op(elem, initial_op); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -179,18 +164,19 @@ static void server_destroy_call_elem(grpc_call_element* elem) { |
|
|
|
GPR_ASSERT(d != NULL); |
|
|
|
GPR_ASSERT(d != NULL); |
|
|
|
d->stats.elapsed_time_ms = gpr_timespec_to_micros( |
|
|
|
d->stats.elapsed_time_ms = gpr_timespec_to_micros( |
|
|
|
gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), d->start_ts)); |
|
|
|
gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), d->start_ts)); |
|
|
|
census_record_rpc_server_stats(d->op_id, &d->stats); |
|
|
|
census_record_stats(d->ctxt, stats, nstats); |
|
|
|
|
|
|
|
/*census_record_rpc_server_stats(d->op_id, &d->stats);*/ |
|
|
|
census_tracing_end_op(d->op_id); |
|
|
|
census_tracing_end_op(d->op_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void init_channel_elem(grpc_channel_element* elem, |
|
|
|
static void init_channel_elem(grpc_channel_element* elem, grpc_channel* master, |
|
|
|
const grpc_channel_args* args, grpc_mdctx* mdctx, |
|
|
|
const grpc_channel_args* args, grpc_mdctx* mdctx, |
|
|
|
int is_first, int is_last) { |
|
|
|
int is_first, int is_last) { |
|
|
|
channel_data* chand = elem->channel_data; |
|
|
|
channel_data* chand = elem->channel_data; |
|
|
|
GPR_ASSERT(chand != NULL); |
|
|
|
GPR_ASSERT(chand != NULL); |
|
|
|
GPR_ASSERT(!is_first); |
|
|
|
GPR_ASSERT(!is_first); |
|
|
|
GPR_ASSERT(!is_last); |
|
|
|
GPR_ASSERT(!is_last); |
|
|
|
chand->path_str = grpc_mdstr_from_string(mdctx, ":path"); |
|
|
|
chand->path_str = grpc_mdstr_from_string(mdctx, ":path", 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void destroy_channel_elem(grpc_channel_element* elem) { |
|
|
|
static void destroy_channel_elem(grpc_channel_element* elem) { |
|
|
@ -203,22 +189,24 @@ static void destroy_channel_elem(grpc_channel_element* elem) { |
|
|
|
|
|
|
|
|
|
|
|
const grpc_channel_filter grpc_client_census_filter = { |
|
|
|
const grpc_channel_filter grpc_client_census_filter = { |
|
|
|
client_start_transport_op, |
|
|
|
client_start_transport_op, |
|
|
|
channel_op, |
|
|
|
grpc_channel_next_op, |
|
|
|
sizeof(call_data), |
|
|
|
sizeof(call_data), |
|
|
|
client_init_call_elem, |
|
|
|
client_init_call_elem, |
|
|
|
client_destroy_call_elem, |
|
|
|
client_destroy_call_elem, |
|
|
|
sizeof(channel_data), |
|
|
|
sizeof(channel_data), |
|
|
|
init_channel_elem, |
|
|
|
init_channel_elem, |
|
|
|
destroy_channel_elem, |
|
|
|
destroy_channel_elem, |
|
|
|
|
|
|
|
grpc_call_next_get_peer, |
|
|
|
"census-client"}; |
|
|
|
"census-client"}; |
|
|
|
|
|
|
|
|
|
|
|
const grpc_channel_filter grpc_server_census_filter = { |
|
|
|
const grpc_channel_filter grpc_server_census_filter = { |
|
|
|
server_start_transport_op, |
|
|
|
server_start_transport_op, |
|
|
|
channel_op, |
|
|
|
grpc_channel_next_op, |
|
|
|
sizeof(call_data), |
|
|
|
sizeof(call_data), |
|
|
|
server_init_call_elem, |
|
|
|
server_init_call_elem, |
|
|
|
server_destroy_call_elem, |
|
|
|
server_destroy_call_elem, |
|
|
|
sizeof(channel_data), |
|
|
|
sizeof(channel_data), |
|
|
|
init_channel_elem, |
|
|
|
init_channel_elem, |
|
|
|
destroy_channel_elem, |
|
|
|
destroy_channel_elem, |
|
|
|
|
|
|
|
grpc_call_next_get_peer, |
|
|
|
"census-server"}; |
|
|
|
"census-server"}; |
|
|
|