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 19 #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_CHANNELZ_H 20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_CHANNELZ_H 21 22 #include <grpc/support/port_platform.h> 23 24 #include <string> 25 26 #include "src/core/lib/channel/channel_args.h" 27 #include "src/core/lib/channel/channel_stack.h" 28 #include "src/core/lib/channel/channel_trace.h" 29 #include "src/core/lib/channel/channelz.h" 30 31 namespace grpc_core { 32 namespace channelz { 33 34 class SubchannelNode : public BaseNode { 35 public: 36 SubchannelNode(std::string target_address, size_t channel_tracer_max_nodes); 37 ~SubchannelNode() override; 38 39 // Sets the subchannel's connectivity state without health checking. 40 void UpdateConnectivityState(grpc_connectivity_state state); 41 42 // Used when the subchannel's child socket changes. This should be set when 43 // the subchannel's transport is created and set to nullptr when the 44 // subchannel unrefs the transport. 45 void SetChildSocket(RefCountedPtr<SocketNode> socket); 46 47 Json RenderJson() override; 48 49 // proxy methods to composed classes. AddTraceEvent(ChannelTrace::Severity severity,const grpc_slice & data)50 void AddTraceEvent(ChannelTrace::Severity severity, const grpc_slice& data) { 51 trace_.AddTraceEvent(severity, data); 52 } AddTraceEventWithReference(ChannelTrace::Severity severity,const grpc_slice & data,RefCountedPtr<BaseNode> referenced_channel)53 void AddTraceEventWithReference(ChannelTrace::Severity severity, 54 const grpc_slice& data, 55 RefCountedPtr<BaseNode> referenced_channel) { 56 trace_.AddTraceEventWithReference(severity, data, 57 std::move(referenced_channel)); 58 } RecordCallStarted()59 void RecordCallStarted() { call_counter_.RecordCallStarted(); } RecordCallFailed()60 void RecordCallFailed() { call_counter_.RecordCallFailed(); } RecordCallSucceeded()61 void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); } 62 63 private: 64 Atomic<grpc_connectivity_state> connectivity_state_{GRPC_CHANNEL_IDLE}; 65 Mutex socket_mu_; 66 RefCountedPtr<SocketNode> child_socket_; 67 std::string target_; 68 CallCountingHelper call_counter_; 69 ChannelTrace trace_; 70 }; 71 72 } // namespace channelz 73 } // namespace grpc_core 74 75 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_CHANNELZ_H */ 76