-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
[PH2][Refactor] Creating call_tracer_wrapper.h and cc and moving code as-is into it. The content of the functions or classes has not changed. In the next few iterations, more code will come into this file. Closes grpc#37786 COPYBARA_INTEGRATE_REVIEW=grpc#37786 from tanvi-jagtap:ph2_internal_h_split_01 31af14a PiperOrigin-RevId: 680861154
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// | ||
// Copyright 2024 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 "src/core/ext/transport/chttp2/transport/call_tracer_wrapper.h" | ||
|
||
#include "src/core/ext/transport/chttp2/transport/internal.h" | ||
|
||
namespace grpc_core { | ||
|
||
void Chttp2CallTracerWrapper::RecordIncomingBytes( | ||
const CallTracerInterface::TransportByteSize& transport_byte_size) { | ||
// Update legacy API. | ||
stream_->stats.incoming.framing_bytes += transport_byte_size.framing_bytes; | ||
stream_->stats.incoming.data_bytes += transport_byte_size.data_bytes; | ||
stream_->stats.incoming.header_bytes += transport_byte_size.header_bytes; | ||
// Update new API. | ||
if (!IsCallTracerInTransportEnabled()) return; | ||
auto* call_tracer = stream_->arena->GetContext<CallTracerInterface>(); | ||
if (call_tracer != nullptr) { | ||
call_tracer->RecordIncomingBytes(transport_byte_size); | ||
} | ||
} | ||
|
||
void Chttp2CallTracerWrapper::RecordOutgoingBytes( | ||
const CallTracerInterface::TransportByteSize& transport_byte_size) { | ||
// Update legacy API. | ||
stream_->stats.outgoing.framing_bytes += transport_byte_size.framing_bytes; | ||
stream_->stats.outgoing.data_bytes += transport_byte_size.data_bytes; | ||
stream_->stats.outgoing.header_bytes += | ||
transport_byte_size.header_bytes; // Update new API. | ||
if (!IsCallTracerInTransportEnabled()) return; | ||
auto* call_tracer = stream_->arena->GetContext<CallTracerInterface>(); | ||
if (call_tracer != nullptr) { | ||
call_tracer->RecordOutgoingBytes(transport_byte_size); | ||
} | ||
} | ||
|
||
} // namespace grpc_core |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// | ||
// Copyright 2024 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_EXT_TRANSPORT_CHTTP2_TRANSPORT_CALL_TRACER_WRAPPER_H | ||
#define GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CALL_TRACER_WRAPPER_H | ||
|
||
#include "src/core/lib/transport/transport.h" | ||
#include "src/core/telemetry/call_tracer.h" | ||
|
||
struct grpc_chttp2_stream; | ||
|
||
namespace grpc_core { | ||
|
||
// A CallTracer wrapper that updates both the legacy and new APIs for | ||
// transport byte sizes. | ||
// TODO(ctiller): This can go away as part of removing the | ||
// grpc_transport_stream_stats struct. | ||
class Chttp2CallTracerWrapper final : public CallTracerInterface { | ||
public: | ||
explicit Chttp2CallTracerWrapper(grpc_chttp2_stream* stream) | ||
: stream_(stream) {} | ||
|
||
void RecordIncomingBytes( | ||
const TransportByteSize& transport_byte_size) override; | ||
void RecordOutgoingBytes( | ||
const TransportByteSize& transport_byte_size) override; | ||
|
||
// Everything else is a no-op. | ||
void RecordSendInitialMetadata( | ||
grpc_metadata_batch* /*send_initial_metadata*/) override {} | ||
void RecordSendTrailingMetadata( | ||
grpc_metadata_batch* /*send_trailing_metadata*/) override {} | ||
void RecordSendMessage(const SliceBuffer& /*send_message*/) override {} | ||
void RecordSendCompressedMessage( | ||
const SliceBuffer& /*send_compressed_message*/) override {} | ||
void RecordReceivedInitialMetadata( | ||
grpc_metadata_batch* /*recv_initial_metadata*/) override {} | ||
void RecordReceivedMessage(const SliceBuffer& /*recv_message*/) override {} | ||
void RecordReceivedDecompressedMessage( | ||
const SliceBuffer& /*recv_decompressed_message*/) override {} | ||
void RecordCancel(grpc_error_handle /*cancel_error*/) override {} | ||
std::shared_ptr<TcpTracerInterface> StartNewTcpTrace() override { | ||
return nullptr; | ||
} | ||
void RecordAnnotation(absl::string_view /*annotation*/) override {} | ||
void RecordAnnotation(const Annotation& /*annotation*/) override {} | ||
std::string TraceId() override { return ""; } | ||
std::string SpanId() override { return ""; } | ||
bool IsSampled() override { return false; } | ||
|
||
private: | ||
grpc_chttp2_stream* stream_; | ||
}; | ||
|
||
} // namespace grpc_core | ||
|
||
#endif // GRPC_SRC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CALL_TRACER_WRAPPER_H |