aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/grpc/src/cpp
diff options
context:
space:
mode:
authorleonidlazarev <leonidlazarev@yandex-team.com>2023-08-01 12:39:29 +0300
committerleonidlazarev <leonidlazarev@yandex-team.com>2023-08-01 12:39:29 +0300
commita3b63938a35abe460ed6b601e55e57bb44449c83 (patch)
treeb6a8b6b9a486f68bf4dd1627fca351e9513897b2 /contrib/libs/grpc/src/cpp
parent1ab00fd81ce534b158e55f27450d5559833cb70a (diff)
downloadydb-a3b63938a35abe460ed6b601e55e57bb44449c83.tar.gz
feat grpc: update to grpc 1.54.2
update grpc to 1.54.2 update grpcio to 1.54.2 Added patches: pr33239_fix_use_after_free.patch Removed patches: pr32547-fix-race.patch - exists in upstream
Diffstat (limited to 'contrib/libs/grpc/src/cpp')
-rw-r--r--contrib/libs/grpc/src/cpp/client/client_interceptor.cc3
-rw-r--r--contrib/libs/grpc/src/cpp/client/client_stats_interceptor.cc40
-rw-r--r--contrib/libs/grpc/src/cpp/common/channel_filter.h13
-rw-r--r--contrib/libs/grpc/src/cpp/common/tls_certificate_verifier.cc7
-rw-r--r--contrib/libs/grpc/src/cpp/server/backend_metric_recorder.cc85
-rw-r--r--contrib/libs/grpc/src/cpp/server/backend_metric_recorder.h5
6 files changed, 127 insertions, 26 deletions
diff --git a/contrib/libs/grpc/src/cpp/client/client_interceptor.cc b/contrib/libs/grpc/src/cpp/client/client_interceptor.cc
index 93181b825cb..dfa30d6fe41 100644
--- a/contrib/libs/grpc/src/cpp/client/client_interceptor.cc
+++ b/contrib/libs/grpc/src/cpp/client/client_interceptor.cc
@@ -25,7 +25,8 @@ namespace grpc {
namespace internal {
experimental::ClientInterceptorFactoryInterface*
g_global_client_interceptor_factory = nullptr;
-}
+
+} // namespace internal
namespace experimental {
void RegisterGlobalClientInterceptorFactory(
diff --git a/contrib/libs/grpc/src/cpp/client/client_stats_interceptor.cc b/contrib/libs/grpc/src/cpp/client/client_stats_interceptor.cc
new file mode 100644
index 00000000000..84c017ddbcf
--- /dev/null
+++ b/contrib/libs/grpc/src/cpp/client/client_stats_interceptor.cc
@@ -0,0 +1,40 @@
+//
+//
+// 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.
+//
+//
+
+#include <grpcpp/support/client_interceptor.h>
+
+#include "src/core/lib/gprpp/crash.h"
+
+namespace grpc {
+namespace internal {
+
+experimental::ClientInterceptorFactoryInterface*
+ g_global_client_stats_interceptor_factory = nullptr;
+
+void RegisterGlobalClientStatsInterceptorFactory(
+ grpc::experimental::ClientInterceptorFactoryInterface* factory) {
+ if (internal::g_global_client_stats_interceptor_factory != nullptr) {
+ grpc_core::Crash(
+ "It is illegal to call RegisterGlobalClientStatsInterceptorFactory "
+ "multiple times.");
+ }
+ internal::g_global_client_interceptor_factory = factory;
+}
+
+} // namespace internal
+} // namespace grpc
diff --git a/contrib/libs/grpc/src/cpp/common/channel_filter.h b/contrib/libs/grpc/src/cpp/common/channel_filter.h
index 9a5eb7dc94a..abc3051fde2 100644
--- a/contrib/libs/grpc/src/cpp/common/channel_filter.h
+++ b/contrib/libs/grpc/src/cpp/common/channel_filter.h
@@ -31,7 +31,6 @@
#include "y_absl/types/optional.h"
#include <grpc/grpc.h>
-#include <grpc/support/atm.h>
#include <grpcpp/support/config.h>
#include "src/core/lib/channel/channel_args.h"
@@ -172,18 +171,6 @@ class TransportStreamOpBatch {
op_->payload->context[GRPC_CONTEXT_TRACING].value);
}
- const gpr_atm* get_peer_string() const {
- if (op_->send_initial_metadata &&
- op_->payload->send_initial_metadata.peer_string != nullptr) {
- return op_->payload->send_initial_metadata.peer_string;
- } else if (op_->recv_initial_metadata &&
- op_->payload->recv_initial_metadata.peer_string != nullptr) {
- return op_->payload->recv_initial_metadata.peer_string;
- } else {
- return nullptr;
- }
- }
-
private:
grpc_transport_stream_op_batch* op_; // Not owned.
MetadataBatch send_initial_metadata_;
diff --git a/contrib/libs/grpc/src/cpp/common/tls_certificate_verifier.cc b/contrib/libs/grpc/src/cpp/common/tls_certificate_verifier.cc
index 313116de6d0..9d0c86b1c5d 100644
--- a/contrib/libs/grpc/src/cpp/common/tls_certificate_verifier.cc
+++ b/contrib/libs/grpc/src/cpp/common/tls_certificate_verifier.cc
@@ -66,6 +66,13 @@ grpc::string_ref TlsCustomVerificationCheckRequest::common_name() const {
: "";
}
+grpc::string_ref TlsCustomVerificationCheckRequest::verified_root_cert_subject()
+ const {
+ return c_request_->peer_info.verified_root_cert_subject != nullptr
+ ? c_request_->peer_info.verified_root_cert_subject
+ : "";
+}
+
std::vector<grpc::string_ref> TlsCustomVerificationCheckRequest::uri_names()
const {
std::vector<grpc::string_ref> uri_names;
diff --git a/contrib/libs/grpc/src/cpp/server/backend_metric_recorder.cc b/contrib/libs/grpc/src/cpp/server/backend_metric_recorder.cc
index f45ef4b6b8f..e76ad18f287 100644
--- a/contrib/libs/grpc/src/cpp/server/backend_metric_recorder.cc
+++ b/contrib/libs/grpc/src/cpp/server/backend_metric_recorder.cc
@@ -40,8 +40,8 @@ bool IsUtilizationValid(double utilization) {
return utilization >= 0.0 && utilization <= 1.0;
}
-// QPS must be in [0, infy).
-bool IsQpsValid(double qps) { return qps >= 0.0; }
+// Rate values (qps and eps) must be in [0, infy).
+bool IsRateValid(double rate) { return rate >= 0.0; }
grpc_core::TraceFlag grpc_backend_metric_trace(false, "backend_metric");
} // namespace
@@ -94,7 +94,7 @@ void ServerMetricRecorder::SetMemoryUtilization(double value) {
}
void ServerMetricRecorder::SetQps(double value) {
- if (!IsQpsValid(value)) {
+ if (!IsRateValid(value)) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_trace)) {
gpr_log(GPR_INFO, "[%p] QPS rejected: %f", this, value);
}
@@ -107,6 +107,20 @@ void ServerMetricRecorder::SetQps(double value) {
}
}
+void ServerMetricRecorder::SetEps(double value) {
+ if (!IsRateValid(value)) {
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_trace)) {
+ gpr_log(GPR_INFO, "[%p] EPS rejected: %f", this, value);
+ }
+ return;
+ }
+ UpdateBackendMetricDataState(
+ [value](BackendMetricData* data) { data->eps = value; });
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_trace)) {
+ gpr_log(GPR_INFO, "[%p] EPS set: %f", this, value);
+ }
+}
+
void ServerMetricRecorder::SetNamedUtilization(string_ref name, double value) {
if (!IsUtilizationValid(value)) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_trace)) {
@@ -163,6 +177,13 @@ void ServerMetricRecorder::ClearQps() {
}
}
+void ServerMetricRecorder::ClearEps() {
+ UpdateBackendMetricDataState([](BackendMetricData* data) { data->eps = -1; });
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_trace)) {
+ gpr_log(GPR_INFO, "[%p] EPS utilization cleared.", this);
+ }
+}
+
void ServerMetricRecorder::ClearNamedUtilization(string_ref name) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_trace)) {
gpr_log(GPR_INFO, "[%p] Named utilization cleared. name: %s", this,
@@ -189,9 +210,9 @@ ServerMetricRecorder::GetMetricsIfChanged() const {
const auto& data = result->data;
gpr_log(GPR_INFO,
"[%p] GetMetrics() returned: seq:%" PRIu64
- " cpu:%f mem:%f qps:%f utilization size: %" PRIuPTR,
+ " cpu:%f mem:%f qps:%f eps:%f utilization size: %" PRIuPTR,
this, result->sequence_number, data.cpu_utilization,
- data.mem_utilization, data.qps, data.utilization.size());
+ data.mem_utilization, data.qps, data.eps, data.utilization.size());
}
return result;
}
@@ -230,7 +251,7 @@ BackendMetricState::RecordMemoryUtilizationMetric(double value) {
experimental::CallMetricRecorder& BackendMetricState::RecordQpsMetric(
double value) {
- if (!IsQpsValid(value)) {
+ if (!IsRateValid(value)) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_trace)) {
gpr_log(GPR_INFO, "[%p] QPS value rejected: %f", this, value);
}
@@ -243,6 +264,21 @@ experimental::CallMetricRecorder& BackendMetricState::RecordQpsMetric(
return *this;
}
+experimental::CallMetricRecorder& BackendMetricState::RecordEpsMetric(
+ double value) {
+ if (!IsRateValid(value)) {
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_trace)) {
+ gpr_log(GPR_INFO, "[%p] EPS value rejected: %f", this, value);
+ }
+ return *this;
+ }
+ eps_.store(value, std::memory_order_relaxed);
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_trace)) {
+ gpr_log(GPR_INFO, "[%p] EPS recorded: %f", this, value);
+ }
+ return *this;
+}
+
experimental::CallMetricRecorder& BackendMetricState::RecordUtilizationMetric(
string_ref name, double value) {
if (!IsUtilizationValid(value)) {
@@ -274,6 +310,18 @@ experimental::CallMetricRecorder& BackendMetricState::RecordRequestCostMetric(
return *this;
}
+experimental::CallMetricRecorder& BackendMetricState::RecordNamedMetric(
+ string_ref name, double value) {
+ internal::MutexLock lock(&mu_);
+ y_absl::string_view name_sv(name.data(), name.length());
+ named_metrics_[name_sv] = value;
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_trace)) {
+ gpr_log(GPR_INFO, "[%p] Named metric recorded: %s %f", this,
+ TString(name_sv).c_str(), value);
+ }
+ return *this;
+}
+
BackendMetricData BackendMetricState::GetBackendMetricData() {
// Merge metrics from the ServerMetricRecorder first since metrics recorded
// to CallMetricRecorder takes a higher precedence.
@@ -291,20 +339,33 @@ BackendMetricData BackendMetricState::GetBackendMetricData() {
data.mem_utilization = mem;
}
const double qps = qps_.load(std::memory_order_relaxed);
- if (IsQpsValid(qps)) {
+ if (IsRateValid(qps)) {
data.qps = qps;
}
+ const double eps = eps_.load(std::memory_order_relaxed);
+ if (IsRateValid(eps)) {
+ data.eps = eps;
+ }
{
internal::MutexLock lock(&mu_);
- data.utilization = std::move(utilization_);
- data.request_cost = std::move(request_cost_);
+ for (const auto& u : utilization_) {
+ data.utilization[u.first] = u.second;
+ }
+ for (const auto& r : request_cost_) {
+ data.request_cost[r.first] = r.second;
+ }
+ for (const auto& r : named_metrics_) {
+ data.named_metrics[r.first] = r.second;
+ }
}
if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_trace)) {
gpr_log(GPR_INFO,
- "[%p] Backend metric data returned: cpu:%f mem:%f qps:%f "
- "utilization size:%" PRIuPTR " request_cost size:%" PRIuPTR,
+ "[%p] Backend metric data returned: cpu:%f mem:%f qps:%f eps:%f "
+ "utilization size:%" PRIuPTR " request_cost size:%" PRIuPTR
+ "named_metrics size:%" PRIuPTR,
this, data.cpu_utilization, data.mem_utilization, data.qps,
- data.utilization.size(), data.request_cost.size());
+ data.eps, data.utilization.size(), data.request_cost.size(),
+ data.named_metrics.size());
}
return data;
}
diff --git a/contrib/libs/grpc/src/cpp/server/backend_metric_recorder.h b/contrib/libs/grpc/src/cpp/server/backend_metric_recorder.h
index 7634b61ad8a..6de0a084698 100644
--- a/contrib/libs/grpc/src/cpp/server/backend_metric_recorder.h
+++ b/contrib/libs/grpc/src/cpp/server/backend_metric_recorder.h
@@ -59,10 +59,13 @@ class BackendMetricState : public grpc_core::BackendMetricProvider,
experimental::CallMetricRecorder& RecordMemoryUtilizationMetric(
double value) override;
experimental::CallMetricRecorder& RecordQpsMetric(double value) override;
+ experimental::CallMetricRecorder& RecordEpsMetric(double value) override;
experimental::CallMetricRecorder& RecordUtilizationMetric(
string_ref name, double value) override;
experimental::CallMetricRecorder& RecordRequestCostMetric(
string_ref name, double value) override;
+ experimental::CallMetricRecorder& RecordNamedMetric(string_ref name,
+ double value) override;
// This clears metrics currently recorded. Don't call twice.
grpc_core::BackendMetricData GetBackendMetricData() override;
@@ -71,9 +74,11 @@ class BackendMetricState : public grpc_core::BackendMetricProvider,
std::atomic<double> cpu_utilization_{-1.0};
std::atomic<double> mem_utilization_{-1.0};
std::atomic<double> qps_{-1.0};
+ std::atomic<double> eps_{-1.0};
internal::Mutex mu_;
std::map<y_absl::string_view, double> utilization_ Y_ABSL_GUARDED_BY(mu_);
std::map<y_absl::string_view, double> request_cost_ Y_ABSL_GUARDED_BY(mu_);
+ std::map<y_absl::string_view, double> named_metrics_ Y_ABSL_GUARDED_BY(mu_);
};
} // namespace grpc