From 296f596a96bb4721c47a618aa4c41a143416bffc Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Fri, 5 Nov 2021 13:13:10 -0700 Subject: [PATCH] OpenCensus: Move metadata storage to arena (#27948) --- src/cpp/ext/filters/census/client_filter.cc | 23 +++++++------------ .../filters/census/open_census_call_tracer.h | 6 ----- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/src/cpp/ext/filters/census/client_filter.cc b/src/cpp/ext/filters/census/client_filter.cc index e1ae787fd63..7fec2fa1568 100644 --- a/src/cpp/ext/filters/census/client_filter.cc +++ b/src/cpp/ext/filters/census/client_filter.cc @@ -91,35 +91,28 @@ OpenCensusCallTracer::OpenCensusCallAttemptTracer::OpenCensusCallAttemptTracer( start_time_(absl::Now()) { context_.AddSpanAttribute("previous-rpc-attempts", attempt_num); context_.AddSpanAttribute("transparent-retry", is_transparent_retry); - memset(&stats_bin_, 0, sizeof(grpc_linked_mdelem)); - memset(&tracing_bin_, 0, sizeof(grpc_linked_mdelem)); } void OpenCensusCallTracer::OpenCensusCallAttemptTracer:: RecordSendInitialMetadata(grpc_metadata_batch* send_initial_metadata, uint32_t /* flags */) { - size_t tracing_len = TraceContextSerialize(context_.Context(), tracing_buf_, + char tracing_buf[kMaxTraceContextLen]; + size_t tracing_len = TraceContextSerialize(context_.Context(), tracing_buf, kMaxTraceContextLen); if (tracing_len > 0) { GRPC_LOG_IF_ERROR( "census grpc_filter", - grpc_metadata_batch_add_tail( - send_initial_metadata, &tracing_bin_, - grpc_mdelem_from_slices( - GRPC_MDSTR_GRPC_TRACE_BIN, - grpc_core::UnmanagedMemorySlice(tracing_buf_, tracing_len)), - GRPC_BATCH_GRPC_TRACE_BIN)); + send_initial_metadata->Append(grpc_mdelem_from_slices( + GRPC_MDSTR_GRPC_TRACE_BIN, + grpc_core::UnmanagedMemorySlice(tracing_buf, tracing_len)))); } grpc_slice tags = grpc_empty_slice(); // TODO(unknown): Add in tagging serialization. size_t encoded_tags_len = StatsContextSerialize(kMaxTagsLen, &tags); if (encoded_tags_len > 0) { - GRPC_LOG_IF_ERROR( - "census grpc_filter", - grpc_metadata_batch_add_tail( - send_initial_metadata, &stats_bin_, - grpc_mdelem_from_slices(GRPC_MDSTR_GRPC_TAGS_BIN, tags), - GRPC_BATCH_GRPC_TAGS_BIN)); + GRPC_LOG_IF_ERROR("census grpc_filter", + send_initial_metadata->Append(grpc_mdelem_from_slices( + GRPC_MDSTR_GRPC_TAGS_BIN, tags))); } } diff --git a/src/cpp/ext/filters/census/open_census_call_tracer.h b/src/cpp/ext/filters/census/open_census_call_tracer.h index 7886ae4f0d2..8ef85a29fc0 100644 --- a/src/cpp/ext/filters/census/open_census_call_tracer.h +++ b/src/cpp/ext/filters/census/open_census_call_tracer.h @@ -63,9 +63,6 @@ class OpenCensusCallTracer : public grpc_core::CallTracer { OpenCensusCallTracer* parent_; const bool arena_allocated_; CensusContext context_; - // Metadata elements for tracing and census stats data. - grpc_linked_mdelem stats_bin_; - grpc_linked_mdelem tracing_bin_; // Start time (for measuring latency). absl::Time start_time_; // Server elapsed time in nanoseconds. @@ -75,9 +72,6 @@ class OpenCensusCallTracer : public grpc_core::CallTracer { uint64_t sent_message_count_ = 0; // End status code absl::StatusCode status_code_; - // Buffer needed for grpc_slice to reference when adding trace context - // metatdata to outgoing message. - char tracing_buf_[kMaxTraceContextLen]; }; explicit OpenCensusCallTracer(const grpc_call_element_args* args);