• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/core/lib/channel/channel_args.h"
25 #include "src/core/lib/channel/channel_stack.h"
26 #include "src/core/lib/channel/channel_trace.h"
27 #include "src/core/lib/channel/channelz.h"
28 #include "src/core/lib/gprpp/inlined_vector.h"
29 
30 typedef struct grpc_subchannel grpc_subchannel;
31 
32 namespace grpc_core {
33 
34 // TODO(ncteisen), this only contains the uuids of the children for now,
35 // since that is all that is strictly needed. In a future enhancement we will
36 // add human readable names as in the channelz.proto
37 typedef InlinedVector<intptr_t, 10> ChildRefsList;
38 
39 namespace channelz {
40 
41 // Subtype of ChannelNode that overrides and provides client_channel specific
42 // functionality like querying for connectivity_state and subchannel data.
43 class ClientChannelNode : public ChannelNode {
44  public:
45   static RefCountedPtr<ChannelNode> MakeClientChannelNode(
46       grpc_channel* channel, size_t channel_tracer_max_nodes,
47       bool is_top_level_channel);
48 
49   ClientChannelNode(grpc_channel* channel, size_t channel_tracer_max_nodes,
50                     bool is_top_level_channel);
~ClientChannelNode()51   virtual ~ClientChannelNode() {}
52 
53   // Overriding template methods from ChannelNode to render information that
54   // only ClientChannelNode knows about.
55   void PopulateConnectivityState(grpc_json* json) override;
56   void PopulateChildRefs(grpc_json* json) override;
57 
58   // Helper to create a channel arg to ensure this type of ChannelNode is
59   // created.
60   static grpc_arg CreateChannelArg();
61 
62  private:
63   grpc_channel_element* client_channel_;
64 };
65 
66 // Handles channelz bookkeeping for sockets
67 class SubchannelNode : public BaseNode {
68  public:
69   SubchannelNode(grpc_subchannel* subchannel, size_t channel_tracer_max_nodes);
70   ~SubchannelNode() override;
71 
MarkSubchannelDestroyed()72   void MarkSubchannelDestroyed() {
73     GPR_ASSERT(subchannel_ != nullptr);
74     subchannel_ = nullptr;
75   }
76 
77   grpc_json* RenderJson() override;
78 
79   // proxy methods to composed classes.
AddTraceEvent(ChannelTrace::Severity severity,grpc_slice data)80   void AddTraceEvent(ChannelTrace::Severity severity, grpc_slice data) {
81     trace_.AddTraceEvent(severity, data);
82   }
AddTraceEventWithReference(ChannelTrace::Severity severity,grpc_slice data,RefCountedPtr<BaseNode> referenced_channel)83   void AddTraceEventWithReference(ChannelTrace::Severity severity,
84                                   grpc_slice data,
85                                   RefCountedPtr<BaseNode> referenced_channel) {
86     trace_.AddTraceEventWithReference(severity, data,
87                                       std::move(referenced_channel));
88   }
RecordCallStarted()89   void RecordCallStarted() { call_counter_.RecordCallStarted(); }
RecordCallFailed()90   void RecordCallFailed() { call_counter_.RecordCallFailed(); }
RecordCallSucceeded()91   void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); }
92 
93  private:
94   grpc_subchannel* subchannel_;
95   UniquePtr<char> target_;
96   CallCountingHelper call_counter_;
97   ChannelTrace trace_;
98 
99   void PopulateConnectivityState(grpc_json* json);
100 };
101 
102 }  // namespace channelz
103 }  // namespace grpc_core
104 
105 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_CLIENT_CHANNEL_CHANNELZ_H */
106