diff --git a/BUILD b/BUILD index dcabd648e4c541f5767635864c224b43fe894e8c..2cf64dc9cf5a9080087a04f83a2d1f9457a94687 100644 --- a/BUILD +++ b/BUILD @@ -268,6 +268,7 @@ cc_library( "src/core/tsi/ssl_transport_security.c", "src/core/tsi/transport_security.c", "src/core/census/grpc_context.c", + "src/core/channel/census_filter.c", "src/core/channel/channel_args.c", "src/core/channel/channel_stack.c", "src/core/channel/client_channel.c", @@ -511,6 +512,7 @@ cc_library( "src/core/census/rpc_stat_id.h", "src/core/surface/init_unsecure.c", "src/core/census/grpc_context.c", + "src/core/channel/census_filter.c", "src/core/channel/channel_args.c", "src/core/channel/channel_stack.c", "src/core/channel/client_channel.c", @@ -998,6 +1000,7 @@ objc_library( "src/core/tsi/ssl_transport_security.c", "src/core/tsi/transport_security.c", "src/core/census/grpc_context.c", + "src/core/channel/census_filter.c", "src/core/channel/channel_args.c", "src/core/channel/channel_stack.c", "src/core/channel/client_channel.c", diff --git a/Makefile b/Makefile index 181194f78f07052c2e2b7887dbc5162e5c61723d..06c16478a99ed72d5ba0268406c316488f65e451 100644 --- a/Makefile +++ b/Makefile @@ -3977,6 +3977,7 @@ LIBGRPC_SRC = \ src/core/tsi/ssl_transport_security.c \ src/core/tsi/transport_security.c \ src/core/census/grpc_context.c \ + src/core/channel/census_filter.c \ src/core/channel/channel_args.c \ src/core/channel/channel_stack.c \ src/core/channel/client_channel.c \ @@ -4249,6 +4250,7 @@ endif LIBGRPC_UNSECURE_SRC = \ src/core/surface/init_unsecure.c \ src/core/census/grpc_context.c \ + src/core/channel/census_filter.c \ src/core/channel/channel_args.c \ src/core/channel/channel_stack.c \ src/core/channel/client_channel.c \ diff --git a/build.json b/build.json index 515cecdc5a77e2963050c03058aee4846116ae72..8636c84db367b45c6f7ddf789962b149618337f3 100644 --- a/build.json +++ b/build.json @@ -217,6 +217,7 @@ ], "src": [ "src/core/census/grpc_context.c", + "src/core/channel/census_filter.c", "src/core/channel/channel_args.c", "src/core/channel/channel_stack.c", "src/core/channel/client_channel.c", diff --git a/gRPC.podspec b/gRPC.podspec index 12ce7c1e7b95473acc76d19a35c0df5116daabc5..d1e95a1652f574c0296f0c9ac2dde265e09ced46 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -277,6 +277,7 @@ Pod::Spec.new do |s| 'src/core/tsi/ssl_transport_security.c', 'src/core/tsi/transport_security.c', 'src/core/census/grpc_context.c', + 'src/core/channel/census_filter.c', 'src/core/channel/channel_args.c', 'src/core/channel/channel_stack.c', 'src/core/channel/client_channel.c', diff --git a/src/core/channel/census_filter.c b/src/core/channel/census_filter.c index d996c3475e42b80460799f414218009709aed404..86bde85d12771f6bad51c354b59816b69220d789 100644 --- a/src/core/channel/census_filter.c +++ b/src/core/channel/census_filter.c @@ -47,13 +47,12 @@ typedef struct call_data { census_op_id op_id; - census_rpc_stats stats; + /*census_rpc_stats stats;*/ gpr_timespec start_ts; /* recv callback */ grpc_stream_op_buffer* recv_ops; - void (*on_done_recv)(void* user_data, int success); - void* recv_user_data; + grpc_iomgr_closure* on_done_recv; } call_data; typedef struct channel_data { @@ -108,7 +107,7 @@ static void server_on_done_recv(void* ptr, int success) { if (success) { 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, @@ -118,9 +117,7 @@ static void server_mutate_op(grpc_call_element* elem, /* substitute our callback for the op callback */ calld->recv_ops = op->recv_ops; calld->on_done_recv = op->on_done_recv; - calld->recv_user_data = op->recv_user_data; - op->on_done_recv = server_on_done_recv; - op->recv_user_data = elem; + op->on_done_recv = calld->on_done_recv; } } @@ -132,19 +129,6 @@ static void server_start_transport_op(grpc_call_element* elem, 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, const void* server_transport_data, 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); d->start_ts = gpr_now(GPR_CLOCK_REALTIME); 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); } @@ -179,18 +164,19 @@ static void server_destroy_call_elem(grpc_call_element* elem) { GPR_ASSERT(d != NULL); d->stats.elapsed_time_ms = gpr_timespec_to_micros( 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); } -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, int is_first, int is_last) { channel_data* chand = elem->channel_data; GPR_ASSERT(chand != NULL); GPR_ASSERT(!is_first); 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) { @@ -203,22 +189,24 @@ static void destroy_channel_elem(grpc_channel_element* elem) { const grpc_channel_filter grpc_client_census_filter = { client_start_transport_op, - channel_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, - channel_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"}; diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index cbf5c50a653bc71f37dd475017704aa83ed7a027..46c01e5e33d261c54cab1f90706091176c63b222 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -903,6 +903,7 @@ src/core/tsi/fake_transport_security.c \ src/core/tsi/ssl_transport_security.c \ src/core/tsi/transport_security.c \ src/core/census/grpc_context.c \ +src/core/channel/census_filter.c \ src/core/channel/channel_args.c \ src/core/channel/channel_stack.c \ src/core/channel/client_channel.c \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 5d23bf9e88f1133c7d558dfc9c986868c7d32fac..4a71ef90c95f847c8a86c8e225faa7750af62c13 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -12353,6 +12353,7 @@ "src/core/census/initialize.c", "src/core/census/record_stat.c", "src/core/census/rpc_stat_id.h", + "src/core/channel/census_filter.c", "src/core/channel/census_filter.h", "src/core/channel/channel_args.c", "src/core/channel/channel_args.h", @@ -12810,6 +12811,7 @@ "src/core/census/initialize.c", "src/core/census/record_stat.c", "src/core/census/rpc_stat_id.h", + "src/core/channel/census_filter.c", "src/core/channel/census_filter.h", "src/core/channel/channel_args.c", "src/core/channel/channel_args.h", diff --git a/vsprojects/grpc/grpc.vcxproj b/vsprojects/grpc/grpc.vcxproj index 067f341b9570b70fb4195cb7d91ce14b5fef9ca7..a87ad29d495234d741ce9f4817418521648974e0 100644 --- a/vsprojects/grpc/grpc.vcxproj +++ b/vsprojects/grpc/grpc.vcxproj @@ -389,6 +389,8 @@ </ClCompile> <ClCompile Include="..\..\src\core\census\grpc_context.c"> </ClCompile> + <ClCompile Include="..\..\src\core\channel\census_filter.c"> + </ClCompile> <ClCompile Include="..\..\src\core\channel\channel_args.c"> </ClCompile> <ClCompile Include="..\..\src\core\channel\channel_stack.c"> diff --git a/vsprojects/grpc/grpc.vcxproj.filters b/vsprojects/grpc/grpc.vcxproj.filters index fcc40c3a4bab803ef18d13d12e0bb8d55b418a71..c8812faa85c63b31f2040b5b41f1ea939e73adac 100644 --- a/vsprojects/grpc/grpc.vcxproj.filters +++ b/vsprojects/grpc/grpc.vcxproj.filters @@ -67,6 +67,9 @@ <ClCompile Include="..\..\src\core\census\grpc_context.c"> <Filter>src\core\census</Filter> </ClCompile> + <ClCompile Include="..\..\src\core\channel\census_filter.c"> + <Filter>src\core\channel</Filter> + </ClCompile> <ClCompile Include="..\..\src\core\channel\channel_args.c"> <Filter>src\core\channel</Filter> </ClCompile> diff --git a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj index b95658b70ce78af1b5367dd44c20968865ae8627..06da784323d5b186af8783fe47ab1e216c04a975 100644 --- a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj @@ -332,6 +332,8 @@ </ClCompile> <ClCompile Include="..\..\src\core\census\grpc_context.c"> </ClCompile> + <ClCompile Include="..\..\src\core\channel\census_filter.c"> + </ClCompile> <ClCompile Include="..\..\src\core\channel\channel_args.c"> </ClCompile> <ClCompile Include="..\..\src\core\channel\channel_stack.c"> diff --git a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters index 05e9d139e07b9e0825258dd8475eb5354886cc8e..2d10960a792af194cce16105f21256bf59df991b 100644 --- a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -7,6 +7,9 @@ <ClCompile Include="..\..\src\core\census\grpc_context.c"> <Filter>src\core\census</Filter> </ClCompile> + <ClCompile Include="..\..\src\core\channel\census_filter.c"> + <Filter>src\core\channel</Filter> + </ClCompile> <ClCompile Include="..\..\src\core\channel\channel_args.c"> <Filter>src\core\channel</Filter> </ClCompile>