client_channel_channelz.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
22 
23 #include <map>
24 
26 
27 // IWYU pragma: no_include <type_traits>
28 
29 namespace grpc_core {
30 namespace channelz {
31 
33  size_t channel_tracer_max_nodes)
34  : BaseNode(EntityType::kSubchannel, target_address),
35  target_(std::move(target_address)),
36  trace_(channel_tracer_max_nodes) {}
37 
39 
41  connectivity_state_.store(state, std::memory_order_relaxed);
42 }
43 
45  MutexLock lock(&socket_mu_);
46  child_socket_ = std::move(socket);
47 }
48 
50  // Create and fill the data child.
52  connectivity_state_.load(std::memory_order_relaxed);
53  Json::Object data = {
54  {"state",
56  {"state", ConnectivityStateName(state)},
57  }},
58  {"target", target_},
59  };
60 
61  // Fill in the channel trace if applicable
62  Json trace_json = trace_.RenderJson();
63  if (trace_json.type() != Json::Type::JSON_NULL) {
64  data["trace"] = std::move(trace_json);
65  }
66  // Ask CallCountingHelper to populate call count data.
68  // Construct top-level object.
69  Json::Object object{
70  {"ref",
72  {"subchannelId", std::to_string(uuid())},
73  }},
74  {"data", std::move(data)},
75  };
76  // Populate the child socket.
77  RefCountedPtr<SocketNode> child_socket;
78  {
79  MutexLock lock(&socket_mu_);
80  child_socket = child_socket_;
81  }
82  if (child_socket != nullptr && child_socket->uuid() != 0) {
83  object["socketRef"] = Json::Array{
85  {"socketId", std::to_string(child_socket->uuid())},
86  {"name", child_socket->name()},
87  },
88  };
89  }
90  return object;
91 }
92 
93 } // namespace channelz
94 } // namespace grpc_core
grpc_core::Json::Array
std::vector< Json > Array
Definition: src/core/lib/json/json.h:55
grpc_core::channelz::SubchannelNode::call_counter_
CallCountingHelper call_counter_
Definition: client_channel_channelz.h:78
grpc_core::Json::type
Type type() const
Definition: src/core/lib/json/json.h:174
connectivity_state.h
client_channel_channelz.h
grpc_core::channelz::ChannelTrace::RenderJson
Json RenderJson() const
Definition: channel_trace.cc:162
grpc_core::channelz::SubchannelNode::SubchannelNode
SubchannelNode(std::string target_address, size_t channel_tracer_max_nodes)
Definition: client_channel_channelz.cc:32
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::MutexLock
Definition: src/core/lib/gprpp/sync.h:88
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_core::channelz::SubchannelNode::trace_
ChannelTrace trace_
Definition: client_channel_channelz.h:79
grpc_core::channelz::SubchannelNode::RenderJson
Json RenderJson() override
Definition: client_channel_channelz.cc:49
grpc_core::channelz::SubchannelNode::socket_mu_
Mutex socket_mu_
Definition: client_channel_channelz.h:75
grpc_core::channelz::SubchannelNode::SetChildSocket
void SetChildSocket(RefCountedPtr< SocketNode > socket)
Definition: client_channel_channelz.cc:44
grpc_core::channelz::CallCountingHelper::PopulateCallCounts
void PopulateCallCounts(Json::Object *json)
Definition: src/core/lib/channel/channelz.cc:121
grpc_connectivity_state
grpc_connectivity_state
Definition: include/grpc/impl/codegen/connectivity_state.h:30
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
Json
JSON (JavaScript Object Notation).
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:227
grpc_core::channelz::BaseNode::EntityType
EntityType
Definition: channelz.h:83
grpc_core::channelz::BaseNode
Definition: channelz.h:78
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
grpc_core::channelz::BaseNode::uuid
intptr_t uuid() const
Definition: channelz.h:105
grpc_core::Json::Object
std::map< std::string, Json > Object
Definition: src/core/lib/json/json.h:54
grpc_core::ConnectivityStateName
const char * ConnectivityStateName(grpc_connectivity_state state)
Definition: connectivity_state.cc:38
grpc_core::channelz::SubchannelNode::target_
std::string target_
Definition: client_channel_channelz.h:77
grpc_core::Json::Type::JSON_NULL
@ JSON_NULL
std
Definition: grpcpp/impl/codegen/async_unary_call.h:407
state
Definition: bloaty/third_party/zlib/contrib/blast/blast.c:41
channelz
void channelz(grpc_end2end_test_config config)
Definition: test/core/end2end/tests/channelz.cc:318
grpc_core::channelz::SubchannelNode::~SubchannelNode
~SubchannelNode() override
Definition: client_channel_channelz.cc:38
test_server.socket
socket
Definition: test_server.py:65
grpc_core::channelz::SubchannelNode::UpdateConnectivityState
void UpdateConnectivityState(grpc_connectivity_state state)
Definition: client_channel_channelz.cc:40
to_string
static bool to_string(zval *from)
Definition: protobuf/php/ext/google/protobuf/convert.c:333
grpc_core::channelz::SubchannelNode::connectivity_state_
std::atomic< grpc_connectivity_state > connectivity_state_
Definition: client_channel_channelz.h:74
target_
std::string target_
Definition: rls.cc:342
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:55