From 7e341a545a2c048796d68f1a5e0e5caab823bd29 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 27 Mar 2023 19:43:07 -0700 Subject: [PATCH] [metadata] Add a hook point for custom metadata (#32650) Aim here is to allow adding custom metadata types to the internal build. --------- Co-authored-by: ctiller --- BUILD | 8 +++++++ build_autogenerated.yaml | 4 ++++ gRPC-C++.podspec | 2 ++ gRPC-Core.podspec | 2 ++ grpc.gemspec | 1 + package.xml | 1 + src/core/lib/transport/custom_metadata.h | 30 ++++++++++++++++++++++++ src/core/lib/transport/metadata_batch.h | 4 +++- tools/doxygen/Doxyfile.c++.internal | 1 + tools/doxygen/Doxyfile.core.internal | 1 + 10 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/core/lib/transport/custom_metadata.h diff --git a/BUILD b/BUILD index 2befb8033f1..422f5bdc0e8 100644 --- a/BUILD +++ b/BUILD @@ -1444,6 +1444,7 @@ grpc_cc_library( "config", "config_vars", "cpp_impl_of", + "custom_metadata", "debug_location", "exec_ctx", "gpr", @@ -1536,6 +1537,13 @@ grpc_cc_library( ], ) +grpc_cc_library( + name = "custom_metadata", + hdrs = [ + "//src/core:lib/transport/custom_metadata.h", + ], +) + grpc_cc_library( name = "lb_load_data_store", srcs = [ diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 0e581fb3ff3..97dd0138a53 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -1066,6 +1066,7 @@ libs: - src/core/lib/transport/batch_builder.h - src/core/lib/transport/bdp_estimator.h - src/core/lib/transport/connectivity_state.h + - src/core/lib/transport/custom_metadata.h - src/core/lib/transport/error_utils.h - src/core/lib/transport/handshaker.h - src/core/lib/transport/handshaker_factory.h @@ -2380,6 +2381,7 @@ libs: - src/core/lib/transport/batch_builder.h - src/core/lib/transport/bdp_estimator.h - src/core/lib/transport/connectivity_state.h + - src/core/lib/transport/custom_metadata.h - src/core/lib/transport/error_utils.h - src/core/lib/transport/handshaker.h - src/core/lib/transport/handshaker_factory.h @@ -3843,6 +3845,7 @@ libs: - src/core/lib/surface/validate_metadata.h - src/core/lib/transport/batch_builder.h - src/core/lib/transport/connectivity_state.h + - src/core/lib/transport/custom_metadata.h - src/core/lib/transport/error_utils.h - src/core/lib/transport/handshaker.h - src/core/lib/transport/handshaker_factory.h @@ -7632,6 +7635,7 @@ targets: - src/core/lib/surface/validate_metadata.h - src/core/lib/transport/batch_builder.h - src/core/lib/transport/connectivity_state.h + - src/core/lib/transport/custom_metadata.h - src/core/lib/transport/error_utils.h - src/core/lib/transport/handshaker_factory.h - src/core/lib/transport/handshaker_registry.h diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index b0e425ffbd1..6a7b68f83f3 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -1033,6 +1033,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/batch_builder.h', 'src/core/lib/transport/bdp_estimator.h', 'src/core/lib/transport/connectivity_state.h', + 'src/core/lib/transport/custom_metadata.h', 'src/core/lib/transport/error_utils.h', 'src/core/lib/transport/handshaker.h', 'src/core/lib/transport/handshaker_factory.h', @@ -1970,6 +1971,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/batch_builder.h', 'src/core/lib/transport/bdp_estimator.h', 'src/core/lib/transport/connectivity_state.h', + 'src/core/lib/transport/custom_metadata.h', 'src/core/lib/transport/error_utils.h', 'src/core/lib/transport/handshaker.h', 'src/core/lib/transport/handshaker_factory.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 275a544195c..3538133b3ec 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -1716,6 +1716,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/bdp_estimator.h', 'src/core/lib/transport/connectivity_state.cc', 'src/core/lib/transport/connectivity_state.h', + 'src/core/lib/transport/custom_metadata.h', 'src/core/lib/transport/error_utils.cc', 'src/core/lib/transport/error_utils.h', 'src/core/lib/transport/handshaker.cc', @@ -2660,6 +2661,7 @@ Pod::Spec.new do |s| 'src/core/lib/transport/batch_builder.h', 'src/core/lib/transport/bdp_estimator.h', 'src/core/lib/transport/connectivity_state.h', + 'src/core/lib/transport/custom_metadata.h', 'src/core/lib/transport/error_utils.h', 'src/core/lib/transport/handshaker.h', 'src/core/lib/transport/handshaker_factory.h', diff --git a/grpc.gemspec b/grpc.gemspec index eb43170aab2..bde18690f0d 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -1623,6 +1623,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/transport/bdp_estimator.h ) s.files += %w( src/core/lib/transport/connectivity_state.cc ) s.files += %w( src/core/lib/transport/connectivity_state.h ) + s.files += %w( src/core/lib/transport/custom_metadata.h ) s.files += %w( src/core/lib/transport/error_utils.cc ) s.files += %w( src/core/lib/transport/error_utils.h ) s.files += %w( src/core/lib/transport/handshaker.cc ) diff --git a/package.xml b/package.xml index 95210b55be4..806ed773534 100644 --- a/package.xml +++ b/package.xml @@ -1605,6 +1605,7 @@ + diff --git a/src/core/lib/transport/custom_metadata.h b/src/core/lib/transport/custom_metadata.h new file mode 100644 index 00000000000..7cf9c2fc320 --- /dev/null +++ b/src/core/lib/transport/custom_metadata.h @@ -0,0 +1,30 @@ +// Copyright 2023 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef GRPC_SRC_CORE_LIB_TRANSPORT_CUSTOM_METADATA_H +#define GRPC_SRC_CORE_LIB_TRANSPORT_CUSTOM_METADATA_H + +// This file defines two macros: GRPC_CUSTOM_CLIENT_METADATA and +// GRPC_CUSTOM_SERVER_METADATA. +// Each of these is a comma-prefixed and comma-separated list of metadata types +// that will be added to ClientMetadata and ServerMetadata respectively. +// (note: for now both are added to both). +// Different sites with internal grpc-core extensions can substitute this file +// and define their own versions of these macros to extend the metadata system +// with fast metadata types of their own. + +#define GRPC_CUSTOM_CLIENT_METADATA +#define GRPC_CUSTOM_SERVER_METADATA + +#endif // GRPC_SRC_CORE_LIB_TRANSPORT_CUSTOM_METADATA_H diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h index 493a9f9d94b..3e83ffc320f 100644 --- a/src/core/lib/transport/metadata_batch.h +++ b/src/core/lib/transport/metadata_batch.h @@ -45,6 +45,7 @@ #include "src/core/lib/gprpp/time.h" #include "src/core/lib/resource_quota/arena.h" #include "src/core/lib/slice/slice.h" +#include "src/core/lib/transport/custom_metadata.h" #include "src/core/lib/transport/parsed_metadata.h" namespace grpc_core { @@ -1388,7 +1389,8 @@ using grpc_metadata_batch_base = grpc_core::MetadataMap< grpc_core::GrpcStreamNetworkState, grpc_core::PeerString, grpc_core::GrpcStatusContext, grpc_core::GrpcStatusFromWire, grpc_core::GrpcCallWasCancelled, grpc_core::WaitForReady, - grpc_core::GrpcTrailersOnly>; + grpc_core::GrpcTrailersOnly GRPC_CUSTOM_CLIENT_METADATA + GRPC_CUSTOM_SERVER_METADATA>; struct grpc_metadata_batch : public grpc_metadata_batch_base { using grpc_metadata_batch_base::grpc_metadata_batch_base; diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index c6f2daaa29a..bdb366573c7 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -2618,6 +2618,7 @@ src/core/lib/transport/bdp_estimator.cc \ src/core/lib/transport/bdp_estimator.h \ src/core/lib/transport/connectivity_state.cc \ src/core/lib/transport/connectivity_state.h \ +src/core/lib/transport/custom_metadata.h \ src/core/lib/transport/error_utils.cc \ src/core/lib/transport/error_utils.h \ src/core/lib/transport/handshaker.cc \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index f1286029829..d2ce6501391 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -2401,6 +2401,7 @@ src/core/lib/transport/bdp_estimator.cc \ src/core/lib/transport/bdp_estimator.h \ src/core/lib/transport/connectivity_state.cc \ src/core/lib/transport/connectivity_state.h \ +src/core/lib/transport/custom_metadata.h \ src/core/lib/transport/error_utils.cc \ src/core/lib/transport/error_utils.h \ src/core/lib/transport/handshaker.cc \