[context] Move backend metric provider to arena based context (#36781)

Closes #36781

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36781 from ctiller:ctx7 06f44a31d1
PiperOrigin-RevId: 639185505
pull/36789/head^2
Craig Tiller 6 months ago committed by Copybara-Service
parent 0c37233892
commit d26a878e83
  1. 1
      src/core/BUILD
  2. 6
      src/core/ext/filters/backend_metrics/backend_metric_filter.cc
  3. 7
      src/core/ext/filters/backend_metrics/backend_metric_provider.h
  4. 4
      src/core/lib/channel/context.h
  5. 3
      src/cpp/server/server_context.cc

@ -5032,6 +5032,7 @@ grpc_cc_library(
"ext/filters/backend_metrics/backend_metric_provider.h",
],
language = "c++",
deps = ["arena"],
)
grpc_cc_library(

@ -130,16 +130,14 @@ BackendMetricFilter::Create(const ChannelArgs&, ChannelFilter::Args) {
void BackendMetricFilter::Call::OnServerTrailingMetadata(ServerMetadata& md) {
if (md.get(GrpcCallWasCancelled()).value_or(false)) return;
auto* ctx = &GetContext<
grpc_call_context_element>()[GRPC_CONTEXT_BACKEND_METRIC_PROVIDER];
auto* ctx = MaybeGetContext<BackendMetricProvider>();
if (ctx == nullptr) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_filter_trace)) {
gpr_log(GPR_INFO, "[%p] No BackendMetricProvider.", this);
}
return;
}
absl::optional<std::string> serialized = MaybeSerializeBackendMetrics(
reinterpret_cast<BackendMetricProvider*>(ctx->value));
absl::optional<std::string> serialized = MaybeSerializeBackendMetrics(ctx);
if (serialized.has_value() && !serialized->empty()) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_backend_metric_filter_trace)) {
gpr_log(GPR_INFO, "[%p] Backend metrics serialized. size: %" PRIuPTR,

@ -15,6 +15,8 @@
#ifndef GRPC_SRC_CORE_EXT_FILTERS_BACKEND_METRICS_BACKEND_METRIC_PROVIDER_H
#define GRPC_SRC_CORE_EXT_FILTERS_BACKEND_METRICS_BACKEND_METRIC_PROVIDER_H
#include "src/core/lib/resource_quota/arena.h"
namespace grpc_core {
struct BackendMetricData;
@ -24,6 +26,11 @@ class BackendMetricProvider {
virtual BackendMetricData GetBackendMetricData() = 0;
};
template <>
struct ArenaContextType<BackendMetricProvider> {
static void Destroy(BackendMetricProvider*) {}
};
} // namespace grpc_core
#endif // GRPC_SRC_CORE_EXT_FILTERS_BACKEND_METRICS_BACKEND_METRIC_PROVIDER_H

@ -32,10 +32,6 @@ typedef enum {
/// Holds a pointer to ServiceConfigCallData associated with this call.
GRPC_CONTEXT_SERVICE_CONFIG_CALL_DATA,
/// Holds a pointer to BackendMetricProvider associated with this call on
/// the server.
GRPC_CONTEXT_BACKEND_METRIC_PROVIDER,
GRPC_CONTEXT_COUNT
} grpc_context_index;

@ -410,8 +410,7 @@ void ServerContextBase::CreateCallMetricRecorder(
auto* backend_metric_state =
arena->New<BackendMetricState>(server_metric_recorder);
call_metric_recorder_ = backend_metric_state;
grpc_call_context_set(call_.call, GRPC_CONTEXT_BACKEND_METRIC_PROVIDER,
backend_metric_state, nullptr);
arena->SetContext<grpc_core::BackendMetricProvider>(backend_metric_state);
}
grpc::string_ref ServerContextBase::ExperimentalGetAuthority() const {

Loading…
Cancel
Save