diff options
Diffstat (limited to 'include/grpcpp')
-rw-r--r-- | include/grpcpp/ext/csm_observability.h | 21 | ||||
-rw-r--r-- | include/grpcpp/ext/otel_plugin.h | 127 | ||||
-rw-r--r-- | include/grpcpp/ext/proto_server_reflection_plugin.h | 8 | ||||
-rw-r--r-- | include/grpcpp/security/tls_credentials_options.h | 28 | ||||
-rw-r--r-- | include/grpcpp/security/tls_crl_provider.h | 39 | ||||
-rw-r--r-- | include/grpcpp/support/client_callback.h | 28 | ||||
-rw-r--r-- | include/grpcpp/support/proto_buffer_reader.h | 7 | ||||
-rw-r--r-- | include/grpcpp/support/proto_buffer_writer.h | 7 | ||||
-rw-r--r-- | include/grpcpp/test/channel_test_peer.h | 1 | ||||
-rw-r--r-- | include/grpcpp/version_info.h | 6 | ||||
-rw-r--r-- | include/grpcpp/xds_server_builder.h | 16 |
11 files changed, 243 insertions, 45 deletions
diff --git a/include/grpcpp/ext/csm_observability.h b/include/grpcpp/ext/csm_observability.h index c06783391b..a3b50a7238 100644 --- a/include/grpcpp/ext/csm_observability.h +++ b/include/grpcpp/ext/csm_observability.h @@ -28,9 +28,14 @@ #include "absl/strings/string_view.h" #include "opentelemetry/sdk/metrics/meter_provider.h" -#include "src/cpp/ext/otel/otel_plugin.h" +#include <grpcpp/ext/otel_plugin.h> namespace grpc { + +namespace internal { +class OpenTelemetryPluginBuilderImpl; +} // namespace internal + namespace experimental { // This is a no-op at present, but in the future, this object would be useful @@ -41,6 +46,8 @@ class CsmObservability {}; // for a binary running on CSM. class CsmObservabilityBuilder { public: + CsmObservabilityBuilder(); + ~CsmObservabilityBuilder(); CsmObservabilityBuilder& SetMeterProvider( std::shared_ptr<opentelemetry::sdk::metrics::MeterProvider> meter_provider); @@ -80,9 +87,19 @@ class CsmObservabilityBuilder { absl::StatusOr<CsmObservability> BuildAndRegister(); private: - internal::OpenTelemetryPluginBuilder builder_; + std::unique_ptr<grpc::internal::OpenTelemetryPluginBuilderImpl> builder_; }; +/// Creates an OpenTelemetryPluginOption that would add additional labels on +/// gRPC metrics to enhance observability for CSM users. +/// +/// Sample Usage - +/// OpenTelemetryPluginBuilder() +/// .SetMeterProvider(provider) +/// .AddPluginOption(MakeCsmOpenTelemetryPluginOption()) +/// .BuildAndRegisterGlobal(); +std::unique_ptr<OpenTelemetryPluginOption> MakeCsmOpenTelemetryPluginOption(); + } // namespace experimental } // namespace grpc diff --git a/include/grpcpp/ext/otel_plugin.h b/include/grpcpp/ext/otel_plugin.h new file mode 100644 index 0000000000..51afdaa83d --- /dev/null +++ b/include/grpcpp/ext/otel_plugin.h @@ -0,0 +1,127 @@ +// +// +// 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 GRPCPP_EXT_OTEL_PLUGIN_H +#define GRPCPP_EXT_OTEL_PLUGIN_H + +#include <grpc/support/port_platform.h> + +#include <stddef.h> +#include <stdint.h> + +#include <memory> + +#include "absl/functional/any_invocable.h" +#include "absl/status/status.h" +#include "absl/strings/string_view.h" +#include "opentelemetry/metrics/meter_provider.h" + +namespace grpc { + +namespace internal { +class OpenTelemetryPluginBuilderImpl; +} // namespace internal + +class OpenTelemetryPluginOption { + public: + virtual ~OpenTelemetryPluginOption() = default; +}; + +/// The most common way to use this API is - +/// +/// OpenTelemetryPluginBuilder().SetMeterProvider(provider).BuildAndRegister(); +/// +/// The set of instruments available are - +/// grpc.client.attempt.started +/// grpc.client.attempt.duration +/// grpc.client.attempt.sent_total_compressed_message_size +/// grpc.client.attempt.rcvd_total_compressed_message_size +/// grpc.server.call.started +/// grpc.server.call.duration +/// grpc.server.call.sent_total_compressed_message_size +/// grpc.server.call.rcvd_total_compressed_message_size +class OpenTelemetryPluginBuilder { + public: + /// Metrics + static constexpr absl::string_view kClientAttemptStartedInstrumentName = + "grpc.client.attempt.started"; + static constexpr absl::string_view kClientAttemptDurationInstrumentName = + "grpc.client.attempt.duration"; + static constexpr absl::string_view + kClientAttemptSentTotalCompressedMessageSizeInstrumentName = + "grpc.client.attempt.sent_total_compressed_message_size"; + static constexpr absl::string_view + kClientAttemptRcvdTotalCompressedMessageSizeInstrumentName = + "grpc.client.attempt.rcvd_total_compressed_message_size"; + static constexpr absl::string_view kServerCallStartedInstrumentName = + "grpc.server.call.started"; + static constexpr absl::string_view kServerCallDurationInstrumentName = + "grpc.server.call.duration"; + static constexpr absl::string_view + kServerCallSentTotalCompressedMessageSizeInstrumentName = + "grpc.server.call.sent_total_compressed_message_size"; + static constexpr absl::string_view + kServerCallRcvdTotalCompressedMessageSizeInstrumentName = + "grpc.server.call.rcvd_total_compressed_message_size"; + + OpenTelemetryPluginBuilder(); + ~OpenTelemetryPluginBuilder(); + /// If `SetMeterProvider()` is not called, no metrics are collected. + OpenTelemetryPluginBuilder& SetMeterProvider( + std::shared_ptr<opentelemetry::metrics::MeterProvider> meter_provider); + /// If set, \a target_attribute_filter is called per channel to decide whether + /// to record the target attribute on client or to replace it with "other". + /// This helps reduce the cardinality on metrics in cases where many channels + /// are created with different targets in the same binary (which might happen + /// for example, if the channel target string uses IP addresses directly). + OpenTelemetryPluginBuilder& SetTargetAttributeFilter( + absl::AnyInvocable<bool(absl::string_view /*target*/) const> + target_attribute_filter); + /// If set, \a generic_method_attribute_filter is called per call with a + /// generic method type to decide whether to record the method name or to + /// replace it with "other". Non-generic or pre-registered methods remain + /// unaffected. If not set, by default, generic method names are replaced with + /// "other" when recording metrics. + OpenTelemetryPluginBuilder& SetGenericMethodAttributeFilter( + absl::AnyInvocable<bool(absl::string_view /*generic_method*/) const> + generic_method_attribute_filter); + /// Add a plugin option to add to the opentelemetry plugin being built. At + /// present, this type is an opaque type. Ownership of \a option is + /// transferred when `AddPluginOption` is invoked. A maximum of 64 plugin + /// options can be added. + OpenTelemetryPluginBuilder& AddPluginOption( + std::unique_ptr<OpenTelemetryPluginOption> option); + /// Registers a global plugin that acts on all channels and servers running on + /// the process. + absl::Status BuildAndRegisterGlobal(); + + private: + std::unique_ptr<internal::OpenTelemetryPluginBuilderImpl> impl_; +}; + +namespace experimental { +// TODO(yashykt): Delete this after the 1.62 release. +GRPC_DEPRECATED( + "Use grpc::OpenTelemetryPluginBuilder instead. The experimental version " + "will be deleted after the 1.62 release.") +typedef grpc::OpenTelemetryPluginBuilder OpenTelemetryPluginBuilder; +} // namespace experimental + +} // namespace grpc + +#endif // GRPCPP_EXT_OTEL_PLUGIN_H diff --git a/include/grpcpp/ext/proto_server_reflection_plugin.h b/include/grpcpp/ext/proto_server_reflection_plugin.h index 2e3964c957..b1cbb5a67c 100644 --- a/include/grpcpp/ext/proto_server_reflection_plugin.h +++ b/include/grpcpp/ext/proto_server_reflection_plugin.h @@ -19,11 +19,15 @@ #ifndef GRPCPP_EXT_PROTO_SERVER_REFLECTION_PLUGIN_H #define GRPCPP_EXT_PROTO_SERVER_REFLECTION_PLUGIN_H +#include <memory> + #include <grpcpp/impl/server_builder_plugin.h> #include <grpcpp/support/config.h> namespace grpc { class ProtoServerReflection; +class ProtoServerReflectionBackend; +class ProtoServerReflectionV1; class ServerInitializer; namespace reflection { @@ -39,7 +43,9 @@ class ProtoServerReflectionPlugin : public grpc::ServerBuilderPlugin { bool has_sync_methods() const override; private: - std::shared_ptr<grpc::ProtoServerReflection> reflection_service_; + std::shared_ptr<grpc::ProtoServerReflectionBackend> backend_; + std::shared_ptr<grpc::ProtoServerReflection> reflection_service_v1alpha_; + std::shared_ptr<grpc::ProtoServerReflectionV1> reflection_service_v1_; }; /// Add proto reflection plugin to \a ServerBuilder. diff --git a/include/grpcpp/security/tls_credentials_options.h b/include/grpcpp/security/tls_credentials_options.h index da5620f805..7f5cb8208f 100644 --- a/include/grpcpp/security/tls_credentials_options.h +++ b/include/grpcpp/security/tls_credentials_options.h @@ -28,6 +28,7 @@ #include <grpc/support/log.h> #include <grpcpp/security/tls_certificate_provider.h> #include <grpcpp/security/tls_certificate_verifier.h> +#include <grpcpp/security/tls_crl_provider.h> #include <grpcpp/support/config.h> namespace grpc { @@ -43,6 +44,7 @@ class TlsCredentialsOptions { // @param certificate_provider the provider which fetches TLS credentials that // will be used in the TLS handshake TlsCredentialsOptions(); + ~TlsCredentialsOptions(); // ---- Setters for member fields ---- // Sets the certificate provider used to store root certs and identity certs. void set_certificate_provider( @@ -97,16 +99,34 @@ class TlsCredentialsOptions { // verifiers other than the host name verifier is used. void set_check_call_host(bool check_call_host); - // TODO(zhenlian): This is an experimental API is likely to change in the - // future. Before de-experiementalizing, verify the API is up to date. + // Deprecated in favor of set_crl_provider. The + // crl provider interface provides a significantly more flexible approach to + // using CRLs. See gRFC A69 for details. // If set, gRPC will read all hashed x.509 CRL files in the directory and // enforce the CRL files on all TLS handshakes. Only supported for OpenSSL // version > 1.1. void set_crl_directory(const std::string& path); + void set_crl_provider(std::shared_ptr<CrlProvider> crl_provider); + + // Sets the minimum TLS version that will be negotiated during the TLS + // handshake. If not set, the underlying SSL library will use TLS v1.2. + // @param tls_version: The minimum TLS version. + void set_min_tls_version(grpc_tls_version tls_version); + // Sets the maximum TLS version that will be negotiated during the TLS + // handshake. If not set, the underlying SSL library will use TLS v1.3. + // @param tls_version: The maximum TLS version. + void set_max_tls_version(grpc_tls_version tls_version); + // ----- Getters for member fields ---- - // Get the internal c options. This function shall be used only internally. - grpc_tls_credentials_options* c_credentials_options() const { + // Returns a deep copy of the internal c options. The caller takes ownership + // of the returned pointer. This function shall be used only internally. + grpc_tls_credentials_options* c_credentials_options() const; + + protected: + // Returns the internal c options. The caller does not take ownership of the + // returned pointer. + grpc_tls_credentials_options* mutable_c_credentials_options() { return c_credentials_options_; } diff --git a/include/grpcpp/security/tls_crl_provider.h b/include/grpcpp/security/tls_crl_provider.h new file mode 100644 index 0000000000..1408327457 --- /dev/null +++ b/include/grpcpp/security/tls_crl_provider.h @@ -0,0 +1,39 @@ +// +// +// 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 GRPCPP_SECURITY_TLS_CRL_PROVIDER_H +#define GRPCPP_SECURITY_TLS_CRL_PROVIDER_H + +#include <grpc/grpc_crl_provider.h> +#include <grpcpp/impl/sync.h> +#include <grpcpp/support/string_ref.h> + +namespace grpc { +namespace experimental { + +using grpc_core::experimental:: + CertificateInfo; // NOLINT(misc-unused-using-decls) +using grpc_core::experimental:: + CreateStaticCrlProvider; // NOLINT(misc-unused-using-decls) +using grpc_core::experimental::Crl; // NOLINT(misc-unused-using-decls) +using grpc_core::experimental::CrlProvider; // NOLINT(misc-unused-using-decls) + +} // namespace experimental +} // namespace grpc + +#endif // GRPCPP_SECURITY_TLS_CRL_PROVIDER_H diff --git a/include/grpcpp/support/client_callback.h b/include/grpcpp/support/client_callback.h index e44764d838..1c420815de 100644 --- a/include/grpcpp/support/client_callback.h +++ b/include/grpcpp/support/client_callback.h @@ -23,6 +23,7 @@ #include <functional> #include <grpc/grpc.h> +#include <grpc/impl/call.h> #include <grpc/support/log.h> #include <grpcpp/impl/call.h> #include <grpcpp/impl/call_op_set.h> @@ -123,15 +124,6 @@ class ClientReactor { /// \param[in] s The status outcome of this RPC virtual void OnDone(const grpc::Status& /*s*/) = 0; - /// InternalScheduleOnDone is not part of the API and is not meant to be - /// overridden. It is virtual to allow successful builds for certain bazel - /// build users that only want to depend on gRPC codegen headers and not the - /// full library (although this is not a generally-supported option). Although - /// the virtual call is slower than a direct call, this function is - /// heavyweight and the cost of the virtual call is not much in comparison. - /// This function may be removed or devirtualized in the future. - virtual void InternalScheduleOnDone(grpc::Status s); - /// InternalTrailersOnly is not part of the API and is not meant to be /// overridden. It is virtual to allow successful builds for certain bazel /// build users that only want to depend on gRPC codegen headers and not the @@ -649,11 +641,13 @@ class ClientCallbackReaderWriterImpl auto* reactor = reactor_; auto* call = call_.call(); this->~ClientCallbackReaderWriterImpl(); - grpc_call_unref(call); if (GPR_LIKELY(from_reaction)) { + grpc_call_unref(call); reactor->OnDone(s); } else { - reactor->InternalScheduleOnDone(std::move(s)); + grpc_call_run_in_event_engine( + call, [reactor, s = std::move(s)]() { reactor->OnDone(s); }); + grpc_call_unref(call); } } } @@ -822,11 +816,13 @@ class ClientCallbackReaderImpl : public ClientCallbackReader<Response> { auto* reactor = reactor_; auto* call = call_.call(); this->~ClientCallbackReaderImpl(); - grpc_call_unref(call); if (GPR_LIKELY(from_reaction)) { + grpc_call_unref(call); reactor->OnDone(s); } else { - reactor->InternalScheduleOnDone(std::move(s)); + grpc_call_run_in_event_engine( + call, [reactor, s = std::move(s)]() { reactor->OnDone(s); }); + grpc_call_unref(call); } } } @@ -1040,11 +1036,13 @@ class ClientCallbackWriterImpl : public ClientCallbackWriter<Request> { auto* reactor = reactor_; auto* call = call_.call(); this->~ClientCallbackWriterImpl(); - grpc_call_unref(call); if (GPR_LIKELY(from_reaction)) { + grpc_call_unref(call); reactor->OnDone(s); } else { - reactor->InternalScheduleOnDone(std::move(s)); + grpc_call_run_in_event_engine( + call, [reactor, s = std::move(s)]() { reactor->OnDone(s); }); + grpc_call_unref(call); } } } diff --git a/include/grpcpp/support/proto_buffer_reader.h b/include/grpcpp/support/proto_buffer_reader.h index 25dfd7eec3..dc0c29601e 100644 --- a/include/grpcpp/support/proto_buffer_reader.h +++ b/include/grpcpp/support/proto_buffer_reader.h @@ -126,11 +126,14 @@ class ProtoBufferReader : public grpc::protobuf::io::ZeroCopyInputStream { /// Read the next `count` bytes and append it to the given Cord. // (override is conditionally omitted here to support old Protobuf which // doesn't have ReadCord method) - // NOLINTNEXTLINE(modernize-use-override) + // NOLINTBEGIN(modernize-use-override, + // clang-diagnostic-inconsistent-missing-override) virtual bool ReadCord(absl::Cord* cord, int count) -#if PROTOBUF_VERSION >= 4022000 +#if GOOGLE_PROTOBUF_VERSION >= 4022000 override #endif + // NOLINTEND(modernize-use-override, + // clang-diagnostic-inconsistent-missing-override) { if (!status().ok()) { return false; diff --git a/include/grpcpp/support/proto_buffer_writer.h b/include/grpcpp/support/proto_buffer_writer.h index f7351ec2b7..83d81060e8 100644 --- a/include/grpcpp/support/proto_buffer_writer.h +++ b/include/grpcpp/support/proto_buffer_writer.h @@ -156,11 +156,14 @@ class ProtoBufferWriter : public grpc::protobuf::io::ZeroCopyOutputStream { /// blocks of the cord, and the slices of the byte_buffer. // (override is conditionally omitted here to support old Protobuf which // doesn't have ReadCord method) - // NOLINTNEXTLINE(modernize-use-override) + // NOLINTBEGIN(modernize-use-override, + // clang-diagnostic-inconsistent-missing-override) virtual bool WriteCord(const absl::Cord& cord) -#if PROTOBUF_VERSION >= 4022000 +#if GOOGLE_PROTOBUF_VERSION >= 4022000 override #endif + // NOLINTEND(modernize-use-override, + // clang-diagnostic-inconsistent-missing-override) { grpc_slice_buffer* buffer = slice_buffer(); size_t cur = 0; diff --git a/include/grpcpp/test/channel_test_peer.h b/include/grpcpp/test/channel_test_peer.h index b180b8feda..f4aad2a03b 100644 --- a/include/grpcpp/test/channel_test_peer.h +++ b/include/grpcpp/test/channel_test_peer.h @@ -32,7 +32,6 @@ class ChannelTestPeer { /// Provide the gRPC Core channel grpc_channel* channel() const { return channel_->c_channel_; } int registered_calls() const; - int registration_attempts() const; private: Channel* channel_; // not owned diff --git a/include/grpcpp/version_info.h b/include/grpcpp/version_info.h index 1ddb596d74..1a1e41d83d 100644 --- a/include/grpcpp/version_info.h +++ b/include/grpcpp/version_info.h @@ -19,9 +19,9 @@ #define GRPCPP_VERSION_INFO_H #define GRPC_CPP_VERSION_MAJOR 1 -#define GRPC_CPP_VERSION_MINOR 59 -#define GRPC_CPP_VERSION_PATCH 2 +#define GRPC_CPP_VERSION_MINOR 61 +#define GRPC_CPP_VERSION_PATCH 1 #define GRPC_CPP_VERSION_TAG "" -#define GRPC_CPP_VERSION_STRING "1.59.2" +#define GRPC_CPP_VERSION_STRING "1.61.1" #endif // GRPCPP_VERSION_INFO_H diff --git a/include/grpcpp/xds_server_builder.h b/include/grpcpp/xds_server_builder.h index ae560595df..f51c526078 100644 --- a/include/grpcpp/xds_server_builder.h +++ b/include/grpcpp/xds_server_builder.h @@ -23,8 +23,6 @@ #include <grpcpp/server_builder.h> -#include "src/core/ext/xds/xds_enabled_server.h" - namespace grpc { class XdsServerServingStatusNotifierInterface { @@ -81,19 +79,7 @@ class XdsServerBuilder : public grpc::ServerBuilder { private: // Called at the beginning of BuildAndStart(). - ChannelArguments BuildChannelArgs() override { - ChannelArguments args = ServerBuilder::BuildChannelArgs(); - if (drain_grace_time_ms_ >= 0) { - args.SetInt(GRPC_ARG_SERVER_CONFIG_CHANGE_DRAIN_GRACE_TIME_MS, - drain_grace_time_ms_); - } - args.SetInt(GRPC_ARG_XDS_ENABLED_SERVER, 1); - grpc_channel_args c_channel_args = args.c_channel_args(); - grpc_server_config_fetcher* fetcher = grpc_server_config_fetcher_xds_create( - {OnServingStatusUpdate, notifier_}, &c_channel_args); - if (fetcher != nullptr) set_fetcher(fetcher); - return args; - } + ChannelArguments BuildChannelArgs() override; static void OnServingStatusUpdate(void* user_data, const char* uri, grpc_serving_status_update update) { |