ncteisen | c3c6e06 | 2018-05-09 11:10:21 -0700 | [diff] [blame] | 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_LIB_CHANNEL_CHANNELZ_H |
| 20 | #define GRPC_CORE_LIB_CHANNEL_CHANNELZ_H |
| 21 | |
| 22 | #include <grpc/impl/codegen/port_platform.h> |
| 23 | |
| 24 | #include <grpc/grpc.h> |
| 25 | |
ncteisen | 23c50fd | 2018-05-18 16:38:29 -0700 | [diff] [blame] | 26 | #include "src/core/lib/channel/channel_trace.h" |
| 27 | #include "src/core/lib/gprpp/manual_constructor.h" |
ncteisen | c3c6e06 | 2018-05-09 11:10:21 -0700 | [diff] [blame] | 28 | #include "src/core/lib/gprpp/ref_counted.h" |
| 29 | #include "src/core/lib/gprpp/ref_counted_ptr.h" |
| 30 | #include "src/core/lib/iomgr/error.h" |
ncteisen | c845ba6 | 2018-06-07 10:14:55 -0700 | [diff] [blame] | 31 | #include "src/core/lib/iomgr/exec_ctx.h" |
ncteisen | c3c6e06 | 2018-05-09 11:10:21 -0700 | [diff] [blame] | 32 | #include "src/core/lib/json/json.h" |
| 33 | |
ncteisen | afb9829 | 2018-06-28 18:04:24 -0700 | [diff] [blame] | 34 | // Channel arg key for client channel factory. |
| 35 | #define GRPC_ARG_CHANNELZ_CHANNEL_NODE_CREATION_FUNC \ |
| 36 | "grpc.channelz_channel_node_creation_func" |
| 37 | |
ncteisen | 97066fd | 2018-07-13 14:05:27 -0700 | [diff] [blame] | 38 | // Channel arg key to signal that the channel is an internal channel. |
| 39 | #define GRPC_ARG_CHANNELZ_CHANNEL_IS_INTERNAL_CHANNEL \ |
| 40 | "grpc.channelz_channel_is_internal_channel" |
| 41 | |
ncteisen | c3c6e06 | 2018-05-09 11:10:21 -0700 | [diff] [blame] | 42 | namespace grpc_core { |
| 43 | namespace channelz { |
| 44 | |
ncteisen | c845ba6 | 2018-06-07 10:14:55 -0700 | [diff] [blame] | 45 | namespace testing { |
ncteisen | 6c987cb | 2018-06-08 09:30:12 -0700 | [diff] [blame] | 46 | class ChannelNodePeer; |
ncteisen | c845ba6 | 2018-06-07 10:14:55 -0700 | [diff] [blame] | 47 | } |
| 48 | |
ncteisen | 6c987cb | 2018-06-08 09:30:12 -0700 | [diff] [blame] | 49 | class ChannelNode : public RefCounted<ChannelNode> { |
ncteisen | c3c6e06 | 2018-05-09 11:10:21 -0700 | [diff] [blame] | 50 | public: |
ncteisen | caa85b2 | 2018-07-03 11:25:41 -0700 | [diff] [blame] | 51 | static RefCountedPtr<ChannelNode> MakeChannelNode( |
ncteisen | 5d373c4 | 2018-07-17 11:57:31 -0700 | [diff] [blame] | 52 | grpc_channel* channel, size_t channel_tracer_max_nodes, |
| 53 | bool is_top_level_channel); |
ncteisen | c3c6e06 | 2018-05-09 11:10:21 -0700 | [diff] [blame] | 54 | |
ncteisen | c845ba6 | 2018-06-07 10:14:55 -0700 | [diff] [blame] | 55 | void RecordCallStarted(); |
| 56 | void RecordCallFailed() { |
ncteisen | a871704 | 2018-06-05 08:26:34 -0700 | [diff] [blame] | 57 | gpr_atm_no_barrier_fetch_add(&calls_failed_, (gpr_atm(1))); |
| 58 | } |
ncteisen | c845ba6 | 2018-06-07 10:14:55 -0700 | [diff] [blame] | 59 | void RecordCallSucceeded() { |
ncteisen | a871704 | 2018-06-05 08:26:34 -0700 | [diff] [blame] | 60 | gpr_atm_no_barrier_fetch_add(&calls_succeeded_, (gpr_atm(1))); |
| 61 | } |
ncteisen | c3c6e06 | 2018-05-09 11:10:21 -0700 | [diff] [blame] | 62 | |
ncteisen | 97066fd | 2018-07-13 14:05:27 -0700 | [diff] [blame] | 63 | grpc_json* RenderJson(); |
| 64 | char* RenderJsonString(); |
ncteisen | c3c6e06 | 2018-05-09 11:10:21 -0700 | [diff] [blame] | 65 | |
ncteisen | 2300351 | 2018-06-29 12:00:15 -0700 | [diff] [blame] | 66 | // helper for getting and populating connectivity state. It is virtual |
| 67 | // because it allows the client_channel specific code to live in ext/ |
| 68 | // instead of lib/ |
| 69 | virtual void PopulateConnectivityState(grpc_json* json); |
ncteisen | afb9829 | 2018-06-28 18:04:24 -0700 | [diff] [blame] | 70 | |
ncteisen | 018498a | 2018-06-29 14:48:05 -0700 | [diff] [blame] | 71 | virtual void PopulateChildRefs(grpc_json* json); |
| 72 | |
ncteisen | c845ba6 | 2018-06-07 10:14:55 -0700 | [diff] [blame] | 73 | ChannelTrace* trace() { return trace_.get(); } |
ncteisen | 23c50fd | 2018-05-18 16:38:29 -0700 | [diff] [blame] | 74 | |
ncteisen | c9c1fef | 2018-06-29 12:32:45 -0700 | [diff] [blame] | 75 | void MarkChannelDestroyed() { |
ncteisen | d23739e | 2018-06-07 12:55:15 -0700 | [diff] [blame] | 76 | GPR_ASSERT(channel_ != nullptr); |
| 77 | channel_ = nullptr; |
ncteisen | c3c6e06 | 2018-05-09 11:10:21 -0700 | [diff] [blame] | 78 | } |
| 79 | |
ncteisen | c9c1fef | 2018-06-29 12:32:45 -0700 | [diff] [blame] | 80 | bool ChannelIsDestroyed() { return channel_ == nullptr; } |
ncteisen | 23c50fd | 2018-05-18 16:38:29 -0700 | [diff] [blame] | 81 | |
ncteisen | c9c1fef | 2018-06-29 12:32:45 -0700 | [diff] [blame] | 82 | intptr_t channel_uuid() { return channel_uuid_; } |
ncteisen | 97066fd | 2018-07-13 14:05:27 -0700 | [diff] [blame] | 83 | bool is_top_level_channel() { return is_top_level_channel_; } |
ncteisen | afb9829 | 2018-06-28 18:04:24 -0700 | [diff] [blame] | 84 | |
ncteisen | caa85b2 | 2018-07-03 11:25:41 -0700 | [diff] [blame] | 85 | protected: |
| 86 | GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE |
| 87 | GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW |
ncteisen | 5d373c4 | 2018-07-17 11:57:31 -0700 | [diff] [blame] | 88 | ChannelNode(grpc_channel* channel, size_t channel_tracer_max_nodes, |
| 89 | bool is_top_level_channel); |
ncteisen | caa85b2 | 2018-07-03 11:25:41 -0700 | [diff] [blame] | 90 | virtual ~ChannelNode(); |
| 91 | |
ncteisen | c3c6e06 | 2018-05-09 11:10:21 -0700 | [diff] [blame] | 92 | private: |
ncteisen | c845ba6 | 2018-06-07 10:14:55 -0700 | [diff] [blame] | 93 | // testing peer friend. |
ncteisen | 6c987cb | 2018-06-08 09:30:12 -0700 | [diff] [blame] | 94 | friend class testing::ChannelNodePeer; |
ncteisen | a871704 | 2018-06-05 08:26:34 -0700 | [diff] [blame] | 95 | |
ncteisen | c7166ae | 2018-06-15 11:04:37 -0400 | [diff] [blame] | 96 | grpc_channel* channel_ = nullptr; |
ncteisen | d23739e | 2018-06-07 12:55:15 -0700 | [diff] [blame] | 97 | UniquePtr<char> target_; |
ncteisen | a871704 | 2018-06-05 08:26:34 -0700 | [diff] [blame] | 98 | gpr_atm calls_started_ = 0; |
| 99 | gpr_atm calls_succeeded_ = 0; |
| 100 | gpr_atm calls_failed_ = 0; |
ncteisen | c7166ae | 2018-06-15 11:04:37 -0400 | [diff] [blame] | 101 | gpr_atm last_call_started_millis_ = 0; |
| 102 | intptr_t channel_uuid_; |
ncteisen | 97066fd | 2018-07-13 14:05:27 -0700 | [diff] [blame] | 103 | bool is_top_level_channel_ = true; |
ncteisen | 23c50fd | 2018-05-18 16:38:29 -0700 | [diff] [blame] | 104 | ManualConstructor<ChannelTrace> trace_; |
ncteisen | c3c6e06 | 2018-05-09 11:10:21 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
ncteisen | 1e6c0b4 | 2018-07-13 11:22:08 -0700 | [diff] [blame] | 107 | // Placeholds channelz class for subchannels. All this can do now is track its |
ncteisen | 0f6e4dd | 2018-07-17 11:26:55 -0700 | [diff] [blame] | 108 | // uuid (this information is needed by the parent channelz class). |
| 109 | // TODO(ncteisen): build this out to support the GetSubchannel channelz request. |
ncteisen | 1e6c0b4 | 2018-07-13 11:22:08 -0700 | [diff] [blame] | 110 | class SubchannelNode : public RefCounted<SubchannelNode> { |
| 111 | public: |
| 112 | SubchannelNode(); |
| 113 | virtual ~SubchannelNode(); |
| 114 | |
| 115 | intptr_t subchannel_uuid() { return subchannel_uuid_; } |
| 116 | |
| 117 | protected: |
| 118 | GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE |
| 119 | GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW |
| 120 | |
| 121 | private: |
| 122 | intptr_t subchannel_uuid_; |
| 123 | }; |
| 124 | |
ncteisen | afb9829 | 2018-06-28 18:04:24 -0700 | [diff] [blame] | 125 | // Creation functions |
| 126 | |
| 127 | typedef RefCountedPtr<ChannelNode> (*ChannelNodeCreationFunc)(grpc_channel*, |
ncteisen | 5d373c4 | 2018-07-17 11:57:31 -0700 | [diff] [blame] | 128 | size_t, bool); |
ncteisen | afb9829 | 2018-06-28 18:04:24 -0700 | [diff] [blame] | 129 | |
ncteisen | c3c6e06 | 2018-05-09 11:10:21 -0700 | [diff] [blame] | 130 | } // namespace channelz |
| 131 | } // namespace grpc_core |
| 132 | |
| 133 | #endif /* GRPC_CORE_LIB_CHANNEL_CHANNELZ_H */ |