const ( SocketTypeNormal = "NormalSocket" SocketTypeListen = "ListenSocket" )
func AddTraceEvent(l grpclog.DepthLoggerV2, e Entity, depth int, desc *TraceEvent)
AddTraceEvent adds trace related to the entity with specified id, using the provided TraceEventDesc.
If channelz is not turned ON, this will simply log the event descriptions.
func Error(l grpclog.DepthLoggerV2, e Entity, args ...any)
Error logs and adds a trace event if channelz is on.
func Errorf(l grpclog.DepthLoggerV2, e Entity, format string, args ...any)
Errorf logs and adds a trace event if channelz is on.
func Info(l grpclog.DepthLoggerV2, e Entity, args ...any)
Info logs and adds a trace event if channelz is on.
func Infof(l grpclog.DepthLoggerV2, e Entity, format string, args ...any)
Infof logs and adds a trace event if channelz is on.
func IsOn() bool
IsOn returns whether channelz data collection is on.
func RemoveEntry(id int64)
RemoveEntry removes an entry with unique channelz tracking id to be id from channelz database.
If channelz is not turned ON, this function is a no-op.
func ResetMaxTraceEntryToDefault()
ResetMaxTraceEntryToDefault resets the maximum number of trace entries per entity to default.
func SetMaxTraceEntry(i int32)
SetMaxTraceEntry sets maximum number of trace entries per entity (i.e. channel/subchannel). Setting it to 0 will disable channel tracing.
func TurnOn()
TurnOn turns on channelz data collection.
func Warning(l grpclog.DepthLoggerV2, e Entity, args ...any)
Warning logs and adds a trace event if channelz is on.
func Warningf(l grpclog.DepthLoggerV2, e Entity, format string, args ...any)
Warningf logs and adds a trace event if channelz is on.
Channel represents a channel within channelz, which includes metrics and internal channelz data, such as channelz id, child list, etc.
type Channel struct { Entity // ID is the channelz id of this channel. ID int64 // RefName is the human readable reference string of this channel. RefName string Parent *Channel ChannelMetrics ChannelMetrics // contains filtered or unexported fields }
func GetChannel(id int64) *Channel
GetChannel returns the Channel for the channel (identified by id).
func GetTopChannels(id int64, maxResults int) ([]*Channel, bool)
GetTopChannels returns a slice of top channel's ChannelMetric, along with a boolean indicating whether there's more top channels to be queried for.
The arg id specifies that only top channel with id at or above it will be included in the result. The returned slice is up to a length of the arg maxResults or EntriesPerPage if maxResults is zero, and is sorted in ascending id order.
func RegisterChannel(parent *Channel, target string) *Channel
RegisterChannel registers the given channel c in the channelz database with target as its target and reference name, and adds it to the child list of its parent. parent == nil means no parent.
Returns a unique channelz identifier assigned to this channel.
If channelz is not turned ON, the channelz database is not mutated.
func (c *Channel) NestedChans() map[int64]string
func (c *Channel) String() string
func (c *Channel) SubChans() map[int64]string
func (c *Channel) Trace() *ChannelTrace
type ChannelMetrics struct { // The current connectivity state of the channel. State atomic.Pointer[connectivity.State] // The target this channel originally tried to connect to. May be absent Target atomic.Pointer[string] // The number of calls started on the channel. CallsStarted atomic.Int64 // The number of calls that have completed with an OK status. CallsSucceeded atomic.Int64 // The number of calls that have a completed with a non-OK status. CallsFailed atomic.Int64 // The last time a call was started on the channel. LastCallStartedTimestamp atomic.Int64 }
func NewChannelMetricForTesting(state connectivity.State, target string, started, succeeded, failed, timestamp int64) *ChannelMetrics
func (c *ChannelMetrics) CopyFrom(o *ChannelMetrics)
CopyFrom copies the metrics in o to c. For testing only.
func (c *ChannelMetrics) Equal(o any) bool
Equal returns true iff the metrics of c are the same as the metrics of o. For testing only.
func (c *ChannelMetrics) String() string
type ChannelTrace struct { CreationTime time.Time EventNum int64 Events []*traceEvent // contains filtered or unexported fields }
Entity is implemented by all channelz types.
type Entity interface { fmt.Stringer // contains filtered or unexported methods }
EphemeralSocketMetrics are metrics that change rapidly and are tracked outside of channelz.
type EphemeralSocketMetrics struct { // The amount of window, granted to the local endpoint by the remote endpoint. // This may be slightly out of date due to network latency. This does NOT // include stream level or TCP level flow control info. LocalFlowControlWindow int64 // The amount of window, granted to the remote endpoint by the local endpoint. // This may be slightly out of date due to network latency. This does NOT // include stream level or TCP level flow control info. RemoteFlowControlWindow int64 }
IDGenerator is an incrementing atomic that tracks IDs for channelz entities.
type IDGenerator struct {
// contains filtered or unexported fields
}
var ( // IDGen is the global channelz entity ID generator. It should not be used // outside this package except by tests. IDGen IDGenerator // EntriesPerPage defines the number of channelz entries to be shown on a web page. EntriesPerPage = 50 )
func (i *IDGenerator) Reset()
Reset resets the generated ID back to zero. Should only be used at initialization or by tests sensitive to the ID number.
Identifier is an opaque channelz identifier used to expose channelz symbols outside of grpc. Currently only implemented by Channel since no other types require exposure outside grpc.
type Identifier interface { Entity // contains filtered or unexported methods }
RefChannelType is the type of the entity being referenced in a trace event.
type RefChannelType int
const ( // RefUnknown indicates an unknown entity type, the zero value for this type. RefUnknown RefChannelType = iota // RefChannel indicates the referenced entity is a Channel. RefChannel // RefSubChannel indicates the referenced entity is a SubChannel. RefSubChannel // RefServer indicates the referenced entity is a Server. RefServer // RefListenSocket indicates the referenced entity is a ListenSocket. RefListenSocket // RefNormalSocket indicates the referenced entity is a NormalSocket. RefNormalSocket )
func (r RefChannelType) String() string
Server is the channelz representation of a server.
type Server struct { Entity ID int64 RefName string ServerMetrics ServerMetrics // contains filtered or unexported fields }
func GetServer(id int64) *Server
GetServer returns the ServerMetric for the server (identified by id).
func GetServers(id int64, maxResults int) ([]*Server, bool)
GetServers returns a slice of server's ServerMetric, along with a boolean indicating whether there's more servers to be queried for.
The arg id specifies that only server with id at or above it will be included in the result. The returned slice is up to a length of the arg maxResults or EntriesPerPage if maxResults is zero, and is sorted in ascending id order.
func RegisterServer(ref string) *Server
RegisterServer registers the given server s in channelz database. It returns the unique channelz tracking id assigned to this server.
If channelz is not turned ON, the channelz database is not mutated.
func (s *Server) ListenSockets() map[int64]string
ListenSockets returns the listening sockets for s.
func (s *Server) String() string
String returns a printable description of s.
ServerMetrics defines a struct containing metrics for servers.
type ServerMetrics struct { // The number of incoming calls started on the server. CallsStarted atomic.Int64 // The number of incoming calls that have completed with an OK status. CallsSucceeded atomic.Int64 // The number of incoming calls that have a completed with a non-OK status. CallsFailed atomic.Int64 // The last time a call was started on the server. LastCallStartedTimestamp atomic.Int64 }
func NewServerMetricsForTesting(started, succeeded, failed, timestamp int64) *ServerMetrics
NewServerMetricsForTesting returns an initialized ServerMetrics.
func (sm *ServerMetrics) CopyFrom(o *ServerMetrics)
Severity is the severity level of a trace event. The canonical enumeration of all valid values is here: https://github.com/grpc/grpc-proto/blob/9b13d199cc0d4703c7ea26c9c330ba695866eb23/grpc/channelz/v1/channelz.proto#L126.
type Severity int
const ( // CtUnknown indicates unknown severity of a trace event. CtUnknown Severity = iota // CtInfo indicates info level severity of a trace event. CtInfo // CtWarning indicates warning level severity of a trace event. CtWarning // CtError indicates error level severity of a trace event. CtError )
type Socket struct { Entity SocketType SocketType ID int64 Parent Entity SocketMetrics SocketMetrics EphemeralMetrics func() *EphemeralSocketMetrics RefName string // The locally bound address. Immutable. LocalAddr net.Addr // The remote bound address. May be absent. Immutable. RemoteAddr net.Addr // Optional, represents the name of the remote endpoint, if different than // the original target name. Immutable. RemoteName string // Immutable. SocketOptions *SocketOptionData // Immutable. Security credentials.ChannelzSecurityValue // contains filtered or unexported fields }
func GetServerSockets(id int64, startID int64, maxResults int) ([]*Socket, bool)
GetServerSockets returns a slice of server's (identified by id) normal socket's SocketMetrics, along with a boolean indicating whether there's more sockets to be queried for.
The arg startID specifies that only sockets with id at or above it will be included in the result. The returned slice is up to a length of the arg maxResults or EntriesPerPage if maxResults is zero, and is sorted in ascending id order.
func GetSocket(id int64) *Socket
GetSocket returns the Socket for the socket (identified by id).
func RegisterSocket(skt *Socket) *Socket
RegisterSocket registers the given normal socket s in channelz database with ref as its reference name, and adds it to the child list of its parent (identified by skt.Parent, which must be set). It returns the unique channelz tracking id assigned to this normal socket.
If channelz is not turned ON, the channelz database is not mutated.
func (ls *Socket) String() string
SocketMetrics defines the struct that the implementor of Socket interface should return from ChannelzMetric().
type SocketMetrics struct { // The number of streams that have been started. StreamsStarted atomic.Int64 // The number of streams that have ended successfully: // On client side, receiving frame with eos bit set. // On server side, sending frame with eos bit set. StreamsSucceeded atomic.Int64 // The number of streams that have ended unsuccessfully: // On client side, termination without receiving frame with eos bit set. // On server side, termination without sending frame with eos bit set. StreamsFailed atomic.Int64 // The number of messages successfully sent on this socket. MessagesSent atomic.Int64 MessagesReceived atomic.Int64 // The number of keep alives sent. This is typically implemented with HTTP/2 // ping messages. KeepAlivesSent atomic.Int64 // The last time a stream was created by this endpoint. Usually unset for // servers. LastLocalStreamCreatedTimestamp atomic.Int64 // The last time a stream was created by the remote endpoint. Usually unset // for clients. LastRemoteStreamCreatedTimestamp atomic.Int64 // The last time a message was sent by this endpoint. LastMessageSentTimestamp atomic.Int64 // The last time a message was received by this endpoint. LastMessageReceivedTimestamp atomic.Int64 }
SocketOptionData defines the struct to hold socket option data, and related getter function to obtain info from fd.
type SocketOptionData struct { Linger *unix.Linger RecvTimeout *unix.Timeval SendTimeout *unix.Timeval TCPInfo *unix.TCPInfo }
func GetSocketOption(socket any) *SocketOptionData
GetSocketOption gets the socket option info of the conn.
func (s *SocketOptionData) Getsockopt(fd uintptr)
Getsockopt defines the function to get socket options requested by channelz. It is to be passed to syscall.RawConn.Control().
type SocketType string
SubChannel is the channelz representation of a subchannel.
type SubChannel struct { Entity // ID is the channelz id of this subchannel. ID int64 // RefName is the human readable reference string of this subchannel. RefName string ChannelMetrics ChannelMetrics // contains filtered or unexported fields }
func GetSubChannel(id int64) *SubChannel
GetSubChannel returns the SubChannel for the subchannel (identified by id).
func RegisterSubChannel(parent *Channel, ref string) *SubChannel
RegisterSubChannel registers the given subChannel c in the channelz database with ref as its reference name, and adds it to the child list of its parent (identified by pid).
Returns a unique channelz identifier assigned to this subChannel.
If channelz is not turned ON, the channelz database is not mutated.
func (sc *SubChannel) Sockets() map[int64]string
func (sc *SubChannel) String() string
func (sc *SubChannel) Trace() *ChannelTrace
TraceEvent is what the caller of AddTraceEvent should provide to describe the event to be added to the channel trace.
The Parent field is optional. It is used for an event that will be recorded in the entity's parent trace.
type TraceEvent struct { Desc string Severity Severity Parent *TraceEvent }