Skip to content

Commit

Permalink
[PH2][Refactor] Creating call_tracer_wrapper.h . (grpc#37786)
Browse files Browse the repository at this point in the history
[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
tanvi-jagtap authored and copybara-github committed Oct 1, 2024
1 parent 80b57c9 commit 229de25
Show file tree
Hide file tree
Showing 23 changed files with 159 additions and 73 deletions.
2 changes: 2 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4763,6 +4763,7 @@ grpc_cc_library(
name = "grpc_transport_chttp2",
srcs = [
"//src/core:ext/transport/chttp2/transport/bin_decoder.cc",
"//src/core:ext/transport/chttp2/transport/call_tracer_wrapper.cc",
"//src/core:ext/transport/chttp2/transport/chttp2_transport.cc",
"//src/core:ext/transport/chttp2/transport/frame_data.cc",
"//src/core:ext/transport/chttp2/transport/frame_goaway.cc",
Expand All @@ -4776,6 +4777,7 @@ grpc_cc_library(
],
hdrs = [
"//src/core:ext/transport/chttp2/transport/bin_decoder.h",
"//src/core:ext/transport/chttp2/transport/call_tracer_wrapper.h",
"//src/core:ext/transport/chttp2/transport/chttp2_transport.h",
"//src/core:ext/transport/chttp2/transport/frame_data.h",
"//src/core:ext/transport/chttp2/transport/frame_goaway.h",
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Package.swift

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions build_autogenerated.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config.m4

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config.w32

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions gRPC-C++.podspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions gRPC-Core.podspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions grpc.gemspec

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions src/core/ext/transport/chttp2/transport/call_tracer_wrapper.cc
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
72 changes: 72 additions & 0 deletions src/core/ext/transport/chttp2/transport/call_tracer_wrapper.h
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
29 changes: 1 addition & 28 deletions src/core/ext/transport/chttp2/transport/chttp2_transport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <grpc/support/port_platform.h>
#include <grpc/support/time.h>

#include "src/core/ext/transport/chttp2/transport/call_tracer_wrapper.h"
#include "src/core/ext/transport/chttp2/transport/context_list_entry.h"
#include "src/core/ext/transport/chttp2/transport/flow_control.h"
#include "src/core/ext/transport/chttp2/transport/frame_data.h"
Expand Down Expand Up @@ -361,34 +362,6 @@ std::string HttpAnnotation::ToString() const {
return s;
}

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

//
Expand Down
1 change: 1 addition & 0 deletions src/core/ext/transport/chttp2/transport/frame_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <grpc/slice_buffer.h>
#include <grpc/support/port_platform.h>

#include "src/core/ext/transport/chttp2/transport/call_tracer_wrapper.h"
#include "src/core/ext/transport/chttp2/transport/internal.h"
#include "src/core/lib/experiments/experiments.h"
#include "src/core/lib/slice/slice.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <grpc/slice_buffer.h>
#include <grpc/support/port_platform.h>

#include "src/core/ext/transport/chttp2/transport/call_tracer_wrapper.h"
#include "src/core/ext/transport/chttp2/transport/internal.h"
#include "src/core/ext/transport/chttp2/transport/legacy_frame.h"
#include "src/core/ext/transport/chttp2/transport/ping_callbacks.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <grpc/support/port_platform.h>

#include "src/core/ext/transport/chttp2/transport/call_tracer_wrapper.h"
#include "src/core/ext/transport/chttp2/transport/flow_control.h"
#include "src/core/ext/transport/chttp2/transport/internal.h"
#include "src/core/ext/transport/chttp2/transport/stream_lists.h"
Expand Down
Loading

0 comments on commit 229de25

Please sign in to comment.