Add more filter priority levels

pull/16214/head
yang-g 6 years ago
parent b811b4e73d
commit d6ef707422
  1. 2
      src/core/ext/filters/client_channel/client_channel_plugin.cc
  2. 2
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  3. 4
      src/core/ext/filters/deadline/deadline_filter.cc
  4. 12
      src/core/ext/filters/http/client_authority_filter.cc
  5. 25
      src/core/ext/filters/http/http_filters_plugin.cc
  6. 3
      src/core/ext/filters/load_reporting/server_load_reporting_filter.cc
  7. 2
      src/core/ext/filters/max_age/max_age_filter.cc
  8. 6
      src/core/ext/filters/message_size/message_size_filter.cc
  9. 2
      src/core/lib/channel/connected_channel.cc
  10. 2
      src/core/lib/channel/connected_channel.h
  11. 27
      src/core/lib/surface/channel_init.h
  12. 24
      src/core/lib/surface/init.cc
  13. 11
      src/core/lib/surface/init_secure.cc
  14. 5
      src/cpp/common/channel_filter.cc
  15. 7
      src/cpp/common/channel_filter.h
  16. 6
      src/cpp/ext/filters/census/grpc_plugin.cc
  17. 16
      test/core/channel/minimal_stack_is_minimal_test.cc
  18. 15
      test/core/end2end/tests/filter_call_init_fails.cc
  19. 15
      test/core/end2end/tests/filter_latency.cc
  20. 15
      test/core/end2end/tests/filter_status_code.cc
  21. 3
      test/cpp/common/channel_filter_test.cc
  22. 3
      test/cpp/end2end/filter_end2end_test.cc

@ -56,7 +56,7 @@ void grpc_client_channel_init(void) {
grpc_register_http_proxy_mapper();
grpc_subchannel_index_init();
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, append_filter,
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_MAX, append_filter,
(void*)&grpc_client_channel_filter);
grpc_http_connect_register_handshaker_factory();
}

@ -1880,7 +1880,7 @@ void grpc_lb_policy_grpclb_init() {
grpc_core::UniquePtr<grpc_core::LoadBalancingPolicyFactory>(
grpc_core::New<grpc_core::GrpcLbFactory>()));
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
GRPC_CHANNEL_INIT_PRIORITY_LOW,
maybe_add_client_load_reporting_filter,
(void*)&grpc_client_load_reporting_filter);
}

@ -379,10 +379,10 @@ static bool maybe_add_deadline_filter(grpc_channel_stack_builder* builder,
void grpc_deadline_filter_init(void) {
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_VERY_HIGH,
maybe_add_deadline_filter, (void*)&grpc_client_deadline_filter);
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_VERY_HIGH,
maybe_add_deadline_filter, (void*)&grpc_server_deadline_filter);
}

@ -146,12 +146,12 @@ static bool add_client_authority_filter(grpc_channel_stack_builder* builder,
}
void grpc_client_authority_filter_init(void) {
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX,
add_client_authority_filter,
(void*)&grpc_client_authority_filter);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX,
add_client_authority_filter,
(void*)&grpc_client_authority_filter);
grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_PRIORITY_HIGH,
add_client_authority_filter, (void*)&grpc_client_authority_filter);
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_HIGH,
add_client_authority_filter, (void*)&grpc_client_authority_filter);
}
void grpc_client_authority_filter_shutdown(void) {}

@ -18,6 +18,7 @@
#include <grpc/support/port_platform.h>
#include <limits.h>
#include <string.h>
#include "src/core/ext/filters/http/client/http_client_filter.h"
@ -51,15 +52,15 @@ static bool maybe_add_optional_filter(grpc_channel_stack_builder* builder,
bool enable = grpc_channel_arg_get_bool(
grpc_channel_args_find(channel_args, filtarg->control_channel_arg),
!grpc_channel_args_want_minimal_stack(channel_args));
return enable ? grpc_channel_stack_builder_prepend_filter(
return enable ? grpc_channel_stack_builder_append_filter(
builder, filtarg->filter, nullptr, nullptr)
: true;
}
static bool maybe_add_required_filter(grpc_channel_stack_builder* builder,
static bool maybe_append_required_filter(grpc_channel_stack_builder* builder,
void* arg) {
return is_building_http_like_transport(builder)
? grpc_channel_stack_builder_prepend_filter(
? grpc_channel_stack_builder_append_filter(
builder, static_cast<const grpc_channel_filter*>(arg),
nullptr, nullptr)
: true;
@ -67,23 +68,23 @@ static bool maybe_add_required_filter(grpc_channel_stack_builder* builder,
void grpc_http_filters_init(void) {
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
GRPC_CHANNEL_INIT_PRIORITY_HIGH,
maybe_add_optional_filter, &compress_filter);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
GRPC_CHANNEL_INIT_PRIORITY_HIGH,
maybe_add_optional_filter, &compress_filter);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
GRPC_CHANNEL_INIT_PRIORITY_HIGH,
maybe_add_optional_filter, &compress_filter);
grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_required_filter, (void*)&grpc_http_client_filter);
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_PRIORITY_HIGH,
maybe_append_required_filter, (void*)&grpc_http_client_filter);
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_required_filter, (void*)&grpc_http_client_filter);
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_HIGH,
maybe_append_required_filter, (void*)&grpc_http_client_filter);
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
maybe_add_required_filter, (void*)&grpc_http_server_filter);
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_HIGH,
maybe_append_required_filter, (void*)&grpc_http_server_filter);
}
void grpc_http_filters_shutdown(void) {}

@ -345,7 +345,8 @@ struct ServerLoadReportingFilterStaticRegistrar {
if (registered) return;
RegisterChannelFilter<ServerLoadReportingChannelData,
ServerLoadReportingCallData>(
"server_load_reporting", GRPC_SERVER_CHANNEL, INT_MAX,
"server_load_reporting", GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_PRIORITY_VERY_LOW, true,
MaybeAddServerLoadReportingFilter);
// Access measures to ensure they are initialized. Otherwise, we can't
// create any valid view before the first RPC.

@ -536,7 +536,7 @@ static bool maybe_add_max_age_filter(grpc_channel_stack_builder* builder,
void grpc_max_age_filter_init(void) {
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
GRPC_CHANNEL_INIT_PRIORITY_LOW,
maybe_add_max_age_filter, nullptr);
}

@ -311,13 +311,13 @@ static bool maybe_add_message_size_filter(grpc_channel_stack_builder* builder,
void grpc_message_size_filter_init(void) {
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
GRPC_CHANNEL_INIT_PRIORITY_LOW,
maybe_add_message_size_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
GRPC_CHANNEL_INIT_PRIORITY_LOW,
maybe_add_message_size_filter, nullptr);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
GRPC_CHANNEL_INIT_PRIORITY_LOW,
maybe_add_message_size_filter, nullptr);
}

@ -228,7 +228,7 @@ static void bind_transport(grpc_channel_stack* channel_stack,
grpc_transport_stream_size(static_cast<grpc_transport*>(t));
}
bool grpc_add_connected_filter(grpc_channel_stack_builder* builder,
bool grpc_append_connected_filter(grpc_channel_stack_builder* builder,
void* arg_must_be_null) {
GPR_ASSERT(arg_must_be_null == nullptr);
grpc_transport* t = grpc_channel_stack_builder_get_transport(builder);

@ -25,7 +25,7 @@
extern const grpc_channel_filter grpc_connected_filter;
bool grpc_add_connected_filter(grpc_channel_stack_builder* builder,
bool grpc_append_connected_filter(grpc_channel_stack_builder* builder,
void* arg_must_be_null);
/* Debug helper to dig the transport stream out of a call element */

@ -19,13 +19,38 @@
#ifndef GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H
#define GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H
#include <limits.h>
#include <grpc/support/port_platform.h>
#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/surface/channel_stack_type.h"
#include "src/core/lib/transport/transport.h"
#define GRPC_CHANNEL_INIT_BUILTIN_PRIORITY 10000
// Priority for channel registration functions to be used in
// grpc_channel_init_register_stage(). The priority dictates the
// order in which the registration functions run.
//
// When used to register a filter, the filter can either be appended or
// prepended, thus dictating whether the filter goes at the top or bottom of
// the stack. Higher priority functions can get closer to the top or bottom
// of the stack than lower priority functions.
enum {
// Default level. Most of filters should use this level if their location in
// the stack does not matter.
GRPC_CHANNEL_INIT_PRIORITY_LOW = 0,
// For filters that should be added after the group of filters with default
// priority, such as auth filters.
GRPC_CHANNEL_INIT_PRIORITY_MED = 10000,
// For filters that need to be close to top or bottom, such as protocol-level
// filters (client_authority, http-client, http-server) and stats (census).
GRPC_CHANNEL_INIT_PRIORITY_HIGH = 20000,
// For filters that need to be very close to the wire or surface.
GRPC_CHANNEL_INIT_PRIORITY_VERY_HIGH = 30000,
// For things that have to happen last, such as connected channel filter or
// surface server filter. Consider as reserved for gRPC internals.
GRPC_CHANNEL_INIT_PRIORITY_MAX = INT_MAX
};
/// This module provides a way for plugins (and the grpc core library itself)
/// to register mutators for channel stacks.

@ -70,11 +70,6 @@ static void do_basic_init(void) {
g_initializations = 0;
}
static bool append_filter(grpc_channel_stack_builder* builder, void* arg) {
return grpc_channel_stack_builder_append_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
}
static bool prepend_filter(grpc_channel_stack_builder* builder, void* arg) {
return grpc_channel_stack_builder_prepend_filter(
builder, static_cast<const grpc_channel_filter*>(arg), nullptr, nullptr);
@ -82,18 +77,19 @@ static bool prepend_filter(grpc_channel_stack_builder* builder, void* arg) {
static void register_builtin_channel_init() {
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter, nullptr);
GRPC_CHANNEL_INIT_PRIORITY_MAX,
grpc_append_connected_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter, nullptr);
GRPC_CHANNEL_INIT_PRIORITY_MAX,
grpc_append_connected_filter, nullptr);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
grpc_add_connected_filter, nullptr);
GRPC_CHANNEL_INIT_PRIORITY_MAX,
grpc_append_connected_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_LAME_CHANNEL,
GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
append_filter, (void*)&grpc_lame_filter);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX, prepend_filter,
GRPC_CHANNEL_INIT_PRIORITY_MAX,
prepend_filter, (void*)&grpc_lame_filter);
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_MAX, prepend_filter,
(void*)&grpc_server_top_filter);
}

@ -67,14 +67,17 @@ static bool maybe_prepend_server_auth_filter(
}
void grpc_register_security_filters(void) {
// Register the auth client with a priority < INT_MAX to allow the authority
// Register the auth client with a low priority to allow the authority
// filter -on which the auth filter depends- to be higher on the channel
// stack.
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX - 1,
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_PRIORITY_MED,
maybe_prepend_client_auth_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX - 1,
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_PRIORITY_MED,
maybe_prepend_client_auth_filter, nullptr);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX,
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_PRIORITY_MED,
maybe_prepend_server_auth_filter, nullptr);
}

@ -78,8 +78,13 @@ bool MaybeAddFilter(grpc_channel_stack_builder* builder, void* arg) {
grpc_channel_stack_builder_get_channel_arguments(builder);
if (!filter.include_filter(*args)) return true;
}
if (filter.prepend) {
return grpc_channel_stack_builder_prepend_filter(builder, &filter.filter,
nullptr, nullptr);
} else {
return grpc_channel_stack_builder_append_filter(builder, &filter.filter,
nullptr, nullptr);
}
}
} // namespace

@ -36,7 +36,8 @@
/// \c ChannelData. Then register the filter using something like this:
/// \code{.cpp}
/// RegisterChannelFilter<MyChannelDataSubclass, MyCallDataSubclass>(
/// "name-of-filter", GRPC_SERVER_CHANNEL, INT_MAX, nullptr);
/// "name-of-filter", GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_LOW,
/// true, nullptr);
/// \endcode
namespace grpc {
@ -351,6 +352,7 @@ class ChannelFilter final {
struct FilterRecord {
grpc_channel_stack_type stack_type;
int priority;
bool prepend;
std::function<bool(const grpc_channel_args&)> include_filter;
grpc_channel_filter filter;
};
@ -363,12 +365,14 @@ void ChannelFilterPluginShutdown();
/// Registers a new filter.
/// Must be called by only one thread at a time.
/// The \a prepend argument decides whether to prepend or append the filter.
/// The \a include_filter argument specifies a function that will be called
/// to determine at run-time whether or not to add the filter. If the
/// value is nullptr, the filter will be added unconditionally.
template <typename ChannelDataType, typename CallDataType>
void RegisterChannelFilter(
const char* name, grpc_channel_stack_type stack_type, int priority,
bool prepend,
std::function<bool(const grpc_channel_args&)> include_filter) {
// If we haven't been called before, initialize channel_filters and
// call grpc_register_plugin().
@ -383,6 +387,7 @@ void RegisterChannelFilter(
internal::FilterRecord filter_record = {
stack_type,
priority,
prepend,
include_filter,
{FilterType::StartTransportStreamOpBatch, FilterType::StartTransportOp,
FilterType::call_data_size, FilterType::InitCallElement,

@ -32,10 +32,12 @@ namespace grpc {
void RegisterOpenCensusPlugin() {
RegisterChannelFilter<CensusChannelData, CensusClientCallData>(
"opencensus_client", GRPC_CLIENT_CHANNEL, INT_MAX /* priority */,
"opencensus_client", GRPC_CLIENT_CHANNEL,
GRPC_CHANNEL_INIT_PRIORITY_VERY_HIGH, true /* prepend */,
nullptr /* condition function */);
RegisterChannelFilter<CensusChannelData, CensusServerCallData>(
"opencensus_server", GRPC_SERVER_CHANNEL, INT_MAX /* priority */,
"opencensus_server", GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_PRIORITY_VERY_HIGH, true /* prepend */,
nullptr /* condition function */);
// Access measures to ensure they are initialized. Otherwise, creating a view

@ -85,21 +85,21 @@ int main(int argc, char** argv) {
// tests with a default stack
errors +=
CHECK_STACK("unknown", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, "authority",
"message_size", "deadline", "connected", NULL);
CHECK_STACK("unknown", nullptr, GRPC_CLIENT_DIRECT_CHANNEL, "deadline",
"authority", "message_size", "connected", NULL);
errors += CHECK_STACK("unknown", nullptr, GRPC_CLIENT_SUBCHANNEL, "authority",
"message_size", "connected", NULL);
errors += CHECK_STACK("unknown", nullptr, GRPC_SERVER_CHANNEL, "server",
"message_size", "deadline", "connected", NULL);
"deadline", "message_size", "connected", NULL);
errors += CHECK_STACK("chttp2", nullptr, GRPC_CLIENT_DIRECT_CHANNEL,
"authority", "message_size", "deadline", "http-client",
"message_compress", "connected", NULL);
"deadline", "authority", "message_size",
"message_compress", "http-client", "connected", NULL);
errors += CHECK_STACK("chttp2", nullptr, GRPC_CLIENT_SUBCHANNEL, "authority",
"message_size", "http-client", "message_compress",
"message_size", "message_compress", "http-client",
"connected", NULL);
errors += CHECK_STACK("chttp2", nullptr, GRPC_SERVER_CHANNEL, "server",
"message_size", "deadline", "http-server",
"message_compress", "connected", NULL);
"deadline", "message_size", "message_compress",
"http-server", "connected", NULL);
errors += CHECK_STACK(nullptr, nullptr, GRPC_CLIENT_CHANNEL, "client-channel",
NULL);

@ -438,7 +438,6 @@ static bool maybe_add_server_channel_filter(grpc_channel_stack_builder* builder,
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
@ -457,7 +456,6 @@ static bool maybe_add_client_channel_filter(grpc_channel_stack_builder* builder,
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
@ -476,7 +474,6 @@ static bool maybe_add_client_subchannel_filter(
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, &test_filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
@ -487,13 +484,17 @@ static bool maybe_add_client_subchannel_filter(
}
static void init_plugin(void) {
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX,
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
GRPC_CHANNEL_INIT_PRIORITY_MAX,
maybe_add_server_channel_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX,
grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL,
GRPC_CHANNEL_INIT_PRIORITY_MAX,
maybe_add_client_channel_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, INT_MAX,
grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
GRPC_CHANNEL_INIT_PRIORITY_MAX,
maybe_add_client_subchannel_filter, nullptr);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX,
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
GRPC_CHANNEL_INIT_PRIORITY_MAX,
maybe_add_client_channel_filter, nullptr);
}

@ -314,7 +314,6 @@ static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) {
// must be the last one. So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
@ -326,14 +325,14 @@ static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) {
static void init_plugin(void) {
gpr_mu_init(&g_mu);
grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX,
maybe_add_filter,
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_MAX, maybe_add_filter,
(void*)&test_client_filter);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX,
maybe_add_filter,
(void*)&test_client_filter);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX,
maybe_add_filter,
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_MAX,
maybe_add_filter, (void*)&test_client_filter);
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_MAX, maybe_add_filter,
(void*)&test_server_filter);
}

@ -333,7 +333,6 @@ static bool maybe_add_filter(grpc_channel_stack_builder* builder, void* arg) {
// So we add it right before the last one.
grpc_channel_stack_builder_iterator* it =
grpc_channel_stack_builder_create_iterator_at_last(builder);
GPR_ASSERT(grpc_channel_stack_builder_move_prev(it));
const bool retval = grpc_channel_stack_builder_add_filter_before(
it, filter, nullptr, nullptr);
grpc_channel_stack_builder_iterator_destroy(it);
@ -350,14 +349,14 @@ static void init_plugin(void) {
g_client_code_recv = false;
g_server_code_recv = false;
grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MAX,
maybe_add_filter,
grpc_channel_init_register_stage(
GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_MAX, maybe_add_filter,
(void*)&test_client_filter);
grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL, INT_MAX,
maybe_add_filter,
(void*)&test_client_filter);
grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL, INT_MAX,
maybe_add_filter,
grpc_channel_init_register_stage(
GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_MAX,
maybe_add_filter, (void*)&test_client_filter);
grpc_channel_init_register_stage(
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_MAX, maybe_add_filter,
(void*)&test_server_filter);
}

@ -50,7 +50,8 @@ class MyCallData : public CallData {
// C-core, we don't accidentally break the C++ filter API.
TEST(ChannelFilterTest, RegisterChannelFilter) {
grpc::RegisterChannelFilter<MyChannelData, MyCallData>(
"myfilter", GRPC_CLIENT_CHANNEL, INT_MAX, nullptr);
"myfilter", GRPC_CLIENT_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_LOW, true,
nullptr);
}
// TODO(roth): When we have time, add tests for all methods of the

@ -323,7 +323,8 @@ TEST_F(FilterEnd2endTest, SimpleBidiStreaming) {
void RegisterFilter() {
grpc::RegisterChannelFilter<ChannelDataImpl, CallDataImpl>(
"test-filter", GRPC_SERVER_CHANNEL, INT_MAX, nullptr);
"test-filter", GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_PRIORITY_LOW, true,
nullptr);
}
} // namespace

Loading…
Cancel
Save