update vendor
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
parent
19a32db84d
commit
94d1cfbfbf
10501 changed files with 2307943 additions and 29279 deletions
105
vendor/google.golang.org/grpc/channelz/service/func_linux.go
generated
vendored
Normal file
105
vendor/google.golang.org/grpc/channelz/service/func_linux.go
generated
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
// +build !appengine,go1.7
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
"google.golang.org/grpc/internal/channelz"
|
||||
)
|
||||
|
||||
func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOption {
|
||||
var opts []*channelzpb.SocketOption
|
||||
if skopts.Linger != nil {
|
||||
additional, err := ptypes.MarshalAny(&channelzpb.SocketOptionLinger{
|
||||
Active: skopts.Linger.Onoff != 0,
|
||||
Duration: convertToPtypesDuration(int64(skopts.Linger.Linger), 0),
|
||||
})
|
||||
if err == nil {
|
||||
opts = append(opts, &channelzpb.SocketOption{
|
||||
Name: "SO_LINGER",
|
||||
Additional: additional,
|
||||
})
|
||||
}
|
||||
}
|
||||
if skopts.RecvTimeout != nil {
|
||||
additional, err := ptypes.MarshalAny(&channelzpb.SocketOptionTimeout{
|
||||
Duration: convertToPtypesDuration(int64(skopts.RecvTimeout.Sec), int64(skopts.RecvTimeout.Usec)),
|
||||
})
|
||||
if err == nil {
|
||||
opts = append(opts, &channelzpb.SocketOption{
|
||||
Name: "SO_RCVTIMEO",
|
||||
Additional: additional,
|
||||
})
|
||||
}
|
||||
}
|
||||
if skopts.SendTimeout != nil {
|
||||
additional, err := ptypes.MarshalAny(&channelzpb.SocketOptionTimeout{
|
||||
Duration: convertToPtypesDuration(int64(skopts.SendTimeout.Sec), int64(skopts.SendTimeout.Usec)),
|
||||
})
|
||||
if err == nil {
|
||||
opts = append(opts, &channelzpb.SocketOption{
|
||||
Name: "SO_SNDTIMEO",
|
||||
Additional: additional,
|
||||
})
|
||||
}
|
||||
}
|
||||
if skopts.TCPInfo != nil {
|
||||
additional, err := ptypes.MarshalAny(&channelzpb.SocketOptionTcpInfo{
|
||||
TcpiState: uint32(skopts.TCPInfo.State),
|
||||
TcpiCaState: uint32(skopts.TCPInfo.Ca_state),
|
||||
TcpiRetransmits: uint32(skopts.TCPInfo.Retransmits),
|
||||
TcpiProbes: uint32(skopts.TCPInfo.Probes),
|
||||
TcpiBackoff: uint32(skopts.TCPInfo.Backoff),
|
||||
TcpiOptions: uint32(skopts.TCPInfo.Options),
|
||||
// https://golang.org/pkg/syscall/#TCPInfo
|
||||
// TCPInfo struct does not contain info about TcpiSndWscale and TcpiRcvWscale.
|
||||
TcpiRto: skopts.TCPInfo.Rto,
|
||||
TcpiAto: skopts.TCPInfo.Ato,
|
||||
TcpiSndMss: skopts.TCPInfo.Snd_mss,
|
||||
TcpiRcvMss: skopts.TCPInfo.Rcv_mss,
|
||||
TcpiUnacked: skopts.TCPInfo.Unacked,
|
||||
TcpiSacked: skopts.TCPInfo.Sacked,
|
||||
TcpiLost: skopts.TCPInfo.Lost,
|
||||
TcpiRetrans: skopts.TCPInfo.Retrans,
|
||||
TcpiFackets: skopts.TCPInfo.Fackets,
|
||||
TcpiLastDataSent: skopts.TCPInfo.Last_data_sent,
|
||||
TcpiLastAckSent: skopts.TCPInfo.Last_ack_sent,
|
||||
TcpiLastDataRecv: skopts.TCPInfo.Last_data_recv,
|
||||
TcpiLastAckRecv: skopts.TCPInfo.Last_ack_recv,
|
||||
TcpiPmtu: skopts.TCPInfo.Pmtu,
|
||||
TcpiRcvSsthresh: skopts.TCPInfo.Rcv_ssthresh,
|
||||
TcpiRtt: skopts.TCPInfo.Rtt,
|
||||
TcpiRttvar: skopts.TCPInfo.Rttvar,
|
||||
TcpiSndSsthresh: skopts.TCPInfo.Snd_ssthresh,
|
||||
TcpiSndCwnd: skopts.TCPInfo.Snd_cwnd,
|
||||
TcpiAdvmss: skopts.TCPInfo.Advmss,
|
||||
TcpiReordering: skopts.TCPInfo.Reordering,
|
||||
})
|
||||
if err == nil {
|
||||
opts = append(opts, &channelzpb.SocketOption{
|
||||
Name: "TCP_INFO",
|
||||
Additional: additional,
|
||||
})
|
||||
}
|
||||
}
|
||||
return opts
|
||||
}
|
30
vendor/google.golang.org/grpc/channelz/service/func_nonlinux.go
generated
vendored
Normal file
30
vendor/google.golang.org/grpc/channelz/service/func_nonlinux.go
generated
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
// +build !linux appengine !go1.7
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
"google.golang.org/grpc/internal/channelz"
|
||||
)
|
||||
|
||||
func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOption {
|
||||
return nil
|
||||
}
|
33
vendor/google.golang.org/grpc/channelz/service/regenerate.sh
generated
vendored
Executable file
33
vendor/google.golang.org/grpc/channelz/service/regenerate.sh
generated
vendored
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
# Copyright 2018 gRPC authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set -eux -o pipefail
|
||||
|
||||
TMP=$(mktemp -d)
|
||||
|
||||
function finish {
|
||||
rm -rf "$TMP"
|
||||
}
|
||||
trap finish EXIT
|
||||
|
||||
pushd "$TMP"
|
||||
mkdir -p grpc/channelz/v1
|
||||
curl https://raw.githubusercontent.com/grpc/grpc-proto/master/grpc/channelz/v1/channelz.proto > grpc/channelz/v1/channelz.proto
|
||||
|
||||
protoc --go_out=plugins=grpc,paths=source_relative:. -I. grpc/channelz/v1/*.proto
|
||||
popd
|
||||
rm -f ../grpc_channelz_v1/*.pb.go
|
||||
cp "$TMP"/grpc/channelz/v1/*.pb.go ../grpc_channelz_v1/
|
||||
|
304
vendor/google.golang.org/grpc/channelz/service/service.go
generated
vendored
Normal file
304
vendor/google.golang.org/grpc/channelz/service/service.go
generated
vendored
Normal file
|
@ -0,0 +1,304 @@
|
|||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
//go:generate ./regenerate.sh
|
||||
|
||||
// Package service provides an implementation for channelz service server.
|
||||
package service
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
durpb "github.com/golang/protobuf/ptypes/duration"
|
||||
wrpb "github.com/golang/protobuf/ptypes/wrappers"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
channelzgrpc "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
"google.golang.org/grpc/connectivity"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/internal/channelz"
|
||||
)
|
||||
|
||||
func init() {
|
||||
channelz.TurnOn()
|
||||
}
|
||||
|
||||
func convertToPtypesDuration(sec int64, usec int64) *durpb.Duration {
|
||||
return ptypes.DurationProto(time.Duration(sec*1e9 + usec*1e3))
|
||||
}
|
||||
|
||||
// RegisterChannelzServiceToServer registers the channelz service to the given server.
|
||||
func RegisterChannelzServiceToServer(s *grpc.Server) {
|
||||
channelzgrpc.RegisterChannelzServer(s, newCZServer())
|
||||
}
|
||||
|
||||
func newCZServer() channelzgrpc.ChannelzServer {
|
||||
return &serverImpl{}
|
||||
}
|
||||
|
||||
type serverImpl struct{}
|
||||
|
||||
func connectivityStateToProto(s connectivity.State) *channelzpb.ChannelConnectivityState {
|
||||
switch s {
|
||||
case connectivity.Idle:
|
||||
return &channelzpb.ChannelConnectivityState{State: channelzpb.ChannelConnectivityState_IDLE}
|
||||
case connectivity.Connecting:
|
||||
return &channelzpb.ChannelConnectivityState{State: channelzpb.ChannelConnectivityState_CONNECTING}
|
||||
case connectivity.Ready:
|
||||
return &channelzpb.ChannelConnectivityState{State: channelzpb.ChannelConnectivityState_READY}
|
||||
case connectivity.TransientFailure:
|
||||
return &channelzpb.ChannelConnectivityState{State: channelzpb.ChannelConnectivityState_TRANSIENT_FAILURE}
|
||||
case connectivity.Shutdown:
|
||||
return &channelzpb.ChannelConnectivityState{State: channelzpb.ChannelConnectivityState_SHUTDOWN}
|
||||
default:
|
||||
return &channelzpb.ChannelConnectivityState{State: channelzpb.ChannelConnectivityState_UNKNOWN}
|
||||
}
|
||||
}
|
||||
|
||||
func channelMetricToProto(cm *channelz.ChannelMetric) *channelzpb.Channel {
|
||||
c := &channelzpb.Channel{}
|
||||
c.Ref = &channelzpb.ChannelRef{ChannelId: cm.ID, Name: cm.RefName}
|
||||
|
||||
c.Data = &channelzpb.ChannelData{
|
||||
State: connectivityStateToProto(cm.ChannelData.State),
|
||||
Target: cm.ChannelData.Target,
|
||||
CallsStarted: cm.ChannelData.CallsStarted,
|
||||
CallsSucceeded: cm.ChannelData.CallsSucceeded,
|
||||
CallsFailed: cm.ChannelData.CallsFailed,
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(cm.ChannelData.LastCallStartedTimestamp); err == nil {
|
||||
c.Data.LastCallStartedTimestamp = ts
|
||||
}
|
||||
nestedChans := make([]*channelzpb.ChannelRef, 0, len(cm.NestedChans))
|
||||
for id, ref := range cm.NestedChans {
|
||||
nestedChans = append(nestedChans, &channelzpb.ChannelRef{ChannelId: id, Name: ref})
|
||||
}
|
||||
c.ChannelRef = nestedChans
|
||||
|
||||
subChans := make([]*channelzpb.SubchannelRef, 0, len(cm.SubChans))
|
||||
for id, ref := range cm.SubChans {
|
||||
subChans = append(subChans, &channelzpb.SubchannelRef{SubchannelId: id, Name: ref})
|
||||
}
|
||||
c.SubchannelRef = subChans
|
||||
|
||||
sockets := make([]*channelzpb.SocketRef, 0, len(cm.Sockets))
|
||||
for id, ref := range cm.Sockets {
|
||||
sockets = append(sockets, &channelzpb.SocketRef{SocketId: id, Name: ref})
|
||||
}
|
||||
c.SocketRef = sockets
|
||||
return c
|
||||
}
|
||||
|
||||
func subChannelMetricToProto(cm *channelz.SubChannelMetric) *channelzpb.Subchannel {
|
||||
sc := &channelzpb.Subchannel{}
|
||||
sc.Ref = &channelzpb.SubchannelRef{SubchannelId: cm.ID, Name: cm.RefName}
|
||||
|
||||
sc.Data = &channelzpb.ChannelData{
|
||||
State: connectivityStateToProto(cm.ChannelData.State),
|
||||
Target: cm.ChannelData.Target,
|
||||
CallsStarted: cm.ChannelData.CallsStarted,
|
||||
CallsSucceeded: cm.ChannelData.CallsSucceeded,
|
||||
CallsFailed: cm.ChannelData.CallsFailed,
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(cm.ChannelData.LastCallStartedTimestamp); err == nil {
|
||||
sc.Data.LastCallStartedTimestamp = ts
|
||||
}
|
||||
nestedChans := make([]*channelzpb.ChannelRef, 0, len(cm.NestedChans))
|
||||
for id, ref := range cm.NestedChans {
|
||||
nestedChans = append(nestedChans, &channelzpb.ChannelRef{ChannelId: id, Name: ref})
|
||||
}
|
||||
sc.ChannelRef = nestedChans
|
||||
|
||||
subChans := make([]*channelzpb.SubchannelRef, 0, len(cm.SubChans))
|
||||
for id, ref := range cm.SubChans {
|
||||
subChans = append(subChans, &channelzpb.SubchannelRef{SubchannelId: id, Name: ref})
|
||||
}
|
||||
sc.SubchannelRef = subChans
|
||||
|
||||
sockets := make([]*channelzpb.SocketRef, 0, len(cm.Sockets))
|
||||
for id, ref := range cm.Sockets {
|
||||
sockets = append(sockets, &channelzpb.SocketRef{SocketId: id, Name: ref})
|
||||
}
|
||||
sc.SocketRef = sockets
|
||||
return sc
|
||||
}
|
||||
|
||||
func securityToProto(se credentials.ChannelzSecurityValue) *channelzpb.Security {
|
||||
switch v := se.(type) {
|
||||
case *credentials.TLSChannelzSecurityValue:
|
||||
return &channelzpb.Security{Model: &channelzpb.Security_Tls_{Tls: &channelzpb.Security_Tls{
|
||||
CipherSuite: &channelzpb.Security_Tls_StandardName{StandardName: v.StandardName},
|
||||
LocalCertificate: v.LocalCertificate,
|
||||
RemoteCertificate: v.RemoteCertificate,
|
||||
}}}
|
||||
case *credentials.OtherChannelzSecurityValue:
|
||||
otherSecurity := &channelzpb.Security_OtherSecurity{
|
||||
Name: v.Name,
|
||||
}
|
||||
if anyval, err := ptypes.MarshalAny(v.Value); err == nil {
|
||||
otherSecurity.Value = anyval
|
||||
}
|
||||
return &channelzpb.Security{Model: &channelzpb.Security_Other{Other: otherSecurity}}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func addrToProto(a net.Addr) *channelzpb.Address {
|
||||
switch a.Network() {
|
||||
case "udp":
|
||||
// TODO: Address_OtherAddress{}. Need proto def for Value.
|
||||
case "ip":
|
||||
// Note zone info is discarded through the conversion.
|
||||
return &channelzpb.Address{Address: &channelzpb.Address_TcpipAddress{TcpipAddress: &channelzpb.Address_TcpIpAddress{IpAddress: a.(*net.IPAddr).IP}}}
|
||||
case "ip+net":
|
||||
// Note mask info is discarded through the conversion.
|
||||
return &channelzpb.Address{Address: &channelzpb.Address_TcpipAddress{TcpipAddress: &channelzpb.Address_TcpIpAddress{IpAddress: a.(*net.IPNet).IP}}}
|
||||
case "tcp":
|
||||
// Note zone info is discarded through the conversion.
|
||||
return &channelzpb.Address{Address: &channelzpb.Address_TcpipAddress{TcpipAddress: &channelzpb.Address_TcpIpAddress{IpAddress: a.(*net.TCPAddr).IP, Port: int32(a.(*net.TCPAddr).Port)}}}
|
||||
case "unix", "unixgram", "unixpacket":
|
||||
return &channelzpb.Address{Address: &channelzpb.Address_UdsAddress_{UdsAddress: &channelzpb.Address_UdsAddress{Filename: a.String()}}}
|
||||
default:
|
||||
}
|
||||
return &channelzpb.Address{}
|
||||
}
|
||||
|
||||
func socketMetricToProto(sm *channelz.SocketMetric) *channelzpb.Socket {
|
||||
s := &channelzpb.Socket{}
|
||||
s.Ref = &channelzpb.SocketRef{SocketId: sm.ID, Name: sm.RefName}
|
||||
|
||||
s.Data = &channelzpb.SocketData{
|
||||
StreamsStarted: sm.SocketData.StreamsStarted,
|
||||
StreamsSucceeded: sm.SocketData.StreamsSucceeded,
|
||||
StreamsFailed: sm.SocketData.StreamsFailed,
|
||||
MessagesSent: sm.SocketData.MessagesSent,
|
||||
MessagesReceived: sm.SocketData.MessagesReceived,
|
||||
KeepAlivesSent: sm.SocketData.KeepAlivesSent,
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(sm.SocketData.LastLocalStreamCreatedTimestamp); err == nil {
|
||||
s.Data.LastLocalStreamCreatedTimestamp = ts
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(sm.SocketData.LastRemoteStreamCreatedTimestamp); err == nil {
|
||||
s.Data.LastRemoteStreamCreatedTimestamp = ts
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(sm.SocketData.LastMessageSentTimestamp); err == nil {
|
||||
s.Data.LastMessageSentTimestamp = ts
|
||||
}
|
||||
if ts, err := ptypes.TimestampProto(sm.SocketData.LastMessageReceivedTimestamp); err == nil {
|
||||
s.Data.LastMessageReceivedTimestamp = ts
|
||||
}
|
||||
s.Data.LocalFlowControlWindow = &wrpb.Int64Value{Value: sm.SocketData.LocalFlowControlWindow}
|
||||
s.Data.RemoteFlowControlWindow = &wrpb.Int64Value{Value: sm.SocketData.RemoteFlowControlWindow}
|
||||
|
||||
if sm.SocketData.SocketOptions != nil {
|
||||
s.Data.Option = sockoptToProto(sm.SocketData.SocketOptions)
|
||||
}
|
||||
if sm.SocketData.Security != nil {
|
||||
s.Security = securityToProto(sm.SocketData.Security)
|
||||
}
|
||||
|
||||
if sm.SocketData.LocalAddr != nil {
|
||||
s.Local = addrToProto(sm.SocketData.LocalAddr)
|
||||
}
|
||||
if sm.SocketData.RemoteAddr != nil {
|
||||
s.Remote = addrToProto(sm.SocketData.RemoteAddr)
|
||||
}
|
||||
s.RemoteName = sm.SocketData.RemoteName
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *serverImpl) GetTopChannels(ctx context.Context, req *channelzpb.GetTopChannelsRequest) (*channelzpb.GetTopChannelsResponse, error) {
|
||||
metrics, end := channelz.GetTopChannels(req.GetStartChannelId())
|
||||
resp := &channelzpb.GetTopChannelsResponse{}
|
||||
for _, m := range metrics {
|
||||
resp.Channel = append(resp.Channel, channelMetricToProto(m))
|
||||
}
|
||||
resp.End = end
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func serverMetricToProto(sm *channelz.ServerMetric) *channelzpb.Server {
|
||||
s := &channelzpb.Server{}
|
||||
s.Ref = &channelzpb.ServerRef{ServerId: sm.ID, Name: sm.RefName}
|
||||
|
||||
s.Data = &channelzpb.ServerData{
|
||||
CallsStarted: sm.ServerData.CallsStarted,
|
||||
CallsSucceeded: sm.ServerData.CallsSucceeded,
|
||||
CallsFailed: sm.ServerData.CallsFailed,
|
||||
}
|
||||
|
||||
if ts, err := ptypes.TimestampProto(sm.ServerData.LastCallStartedTimestamp); err == nil {
|
||||
s.Data.LastCallStartedTimestamp = ts
|
||||
}
|
||||
sockets := make([]*channelzpb.SocketRef, 0, len(sm.ListenSockets))
|
||||
for id, ref := range sm.ListenSockets {
|
||||
sockets = append(sockets, &channelzpb.SocketRef{SocketId: id, Name: ref})
|
||||
}
|
||||
s.ListenSocket = sockets
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *serverImpl) GetServers(ctx context.Context, req *channelzpb.GetServersRequest) (*channelzpb.GetServersResponse, error) {
|
||||
metrics, end := channelz.GetServers(req.GetStartServerId())
|
||||
resp := &channelzpb.GetServersResponse{}
|
||||
for _, m := range metrics {
|
||||
resp.Server = append(resp.Server, serverMetricToProto(m))
|
||||
}
|
||||
resp.End = end
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *serverImpl) GetServerSockets(ctx context.Context, req *channelzpb.GetServerSocketsRequest) (*channelzpb.GetServerSocketsResponse, error) {
|
||||
metrics, end := channelz.GetServerSockets(req.GetServerId(), req.GetStartSocketId())
|
||||
resp := &channelzpb.GetServerSocketsResponse{}
|
||||
for _, m := range metrics {
|
||||
resp.SocketRef = append(resp.SocketRef, &channelzpb.SocketRef{SocketId: m.ID, Name: m.RefName})
|
||||
}
|
||||
resp.End = end
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *serverImpl) GetChannel(ctx context.Context, req *channelzpb.GetChannelRequest) (*channelzpb.GetChannelResponse, error) {
|
||||
var metric *channelz.ChannelMetric
|
||||
if metric = channelz.GetChannel(req.GetChannelId()); metric == nil {
|
||||
return &channelzpb.GetChannelResponse{}, nil
|
||||
}
|
||||
resp := &channelzpb.GetChannelResponse{Channel: channelMetricToProto(metric)}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *serverImpl) GetSubchannel(ctx context.Context, req *channelzpb.GetSubchannelRequest) (*channelzpb.GetSubchannelResponse, error) {
|
||||
var metric *channelz.SubChannelMetric
|
||||
if metric = channelz.GetSubChannel(req.GetSubchannelId()); metric == nil {
|
||||
return &channelzpb.GetSubchannelResponse{}, nil
|
||||
}
|
||||
resp := &channelzpb.GetSubchannelResponse{Subchannel: subChannelMetricToProto(metric)}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (s *serverImpl) GetSocket(ctx context.Context, req *channelzpb.GetSocketRequest) (*channelzpb.GetSocketResponse, error) {
|
||||
var metric *channelz.SocketMetric
|
||||
if metric = channelz.GetSocket(req.GetSocketId()); metric == nil {
|
||||
return &channelzpb.GetSocketResponse{}, nil
|
||||
}
|
||||
resp := &channelzpb.GetSocketResponse{Socket: socketMetricToProto(metric)}
|
||||
return resp, nil
|
||||
}
|
152
vendor/google.golang.org/grpc/channelz/service/service_sktopt_test.go
generated
vendored
Normal file
152
vendor/google.golang.org/grpc/channelz/service/service_sktopt_test.go
generated
vendored
Normal file
|
@ -0,0 +1,152 @@
|
|||
// +build linux,!appengine,go1.7
|
||||
// +build 386 amd64
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
// SocketOptions is only supported on linux system. The functions defined in
|
||||
// this file are to parse the socket option field and the test is specifically
|
||||
// to verify the behavior of socket option parsing.
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
durpb "github.com/golang/protobuf/ptypes/duration"
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/sys/unix"
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
"google.golang.org/grpc/internal/channelz"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Assign protoToSocketOption to protoToSocketOpt in order to enable socket option
|
||||
// data conversion from proto message to channelz defined struct.
|
||||
protoToSocketOpt = protoToSocketOption
|
||||
}
|
||||
|
||||
func convertToDuration(d *durpb.Duration) (sec int64, usec int64) {
|
||||
if d != nil {
|
||||
if dur, err := ptypes.Duration(d); err == nil {
|
||||
sec = int64(int64(dur) / 1e9)
|
||||
usec = (int64(dur) - sec*1e9) / 1e3
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func protoToLinger(protoLinger *channelzpb.SocketOptionLinger) *unix.Linger {
|
||||
linger := &unix.Linger{}
|
||||
if protoLinger.GetActive() {
|
||||
linger.Onoff = 1
|
||||
}
|
||||
lv, _ := convertToDuration(protoLinger.GetDuration())
|
||||
linger.Linger = int32(lv)
|
||||
return linger
|
||||
}
|
||||
|
||||
func protoToSocketOption(skopts []*channelzpb.SocketOption) *channelz.SocketOptionData {
|
||||
skdata := &channelz.SocketOptionData{}
|
||||
for _, opt := range skopts {
|
||||
switch opt.GetName() {
|
||||
case "SO_LINGER":
|
||||
protoLinger := &channelzpb.SocketOptionLinger{}
|
||||
err := ptypes.UnmarshalAny(opt.GetAdditional(), protoLinger)
|
||||
if err == nil {
|
||||
skdata.Linger = protoToLinger(protoLinger)
|
||||
}
|
||||
case "SO_RCVTIMEO":
|
||||
protoTimeout := &channelzpb.SocketOptionTimeout{}
|
||||
err := ptypes.UnmarshalAny(opt.GetAdditional(), protoTimeout)
|
||||
if err == nil {
|
||||
skdata.RecvTimeout = protoToTime(protoTimeout)
|
||||
}
|
||||
case "SO_SNDTIMEO":
|
||||
protoTimeout := &channelzpb.SocketOptionTimeout{}
|
||||
err := ptypes.UnmarshalAny(opt.GetAdditional(), protoTimeout)
|
||||
if err == nil {
|
||||
skdata.SendTimeout = protoToTime(protoTimeout)
|
||||
}
|
||||
case "TCP_INFO":
|
||||
tcpi := &channelzpb.SocketOptionTcpInfo{}
|
||||
err := ptypes.UnmarshalAny(opt.GetAdditional(), tcpi)
|
||||
if err == nil {
|
||||
skdata.TCPInfo = &unix.TCPInfo{
|
||||
State: uint8(tcpi.TcpiState),
|
||||
Ca_state: uint8(tcpi.TcpiCaState),
|
||||
Retransmits: uint8(tcpi.TcpiRetransmits),
|
||||
Probes: uint8(tcpi.TcpiProbes),
|
||||
Backoff: uint8(tcpi.TcpiBackoff),
|
||||
Options: uint8(tcpi.TcpiOptions),
|
||||
Rto: tcpi.TcpiRto,
|
||||
Ato: tcpi.TcpiAto,
|
||||
Snd_mss: tcpi.TcpiSndMss,
|
||||
Rcv_mss: tcpi.TcpiRcvMss,
|
||||
Unacked: tcpi.TcpiUnacked,
|
||||
Sacked: tcpi.TcpiSacked,
|
||||
Lost: tcpi.TcpiLost,
|
||||
Retrans: tcpi.TcpiRetrans,
|
||||
Fackets: tcpi.TcpiFackets,
|
||||
Last_data_sent: tcpi.TcpiLastDataSent,
|
||||
Last_ack_sent: tcpi.TcpiLastAckSent,
|
||||
Last_data_recv: tcpi.TcpiLastDataRecv,
|
||||
Last_ack_recv: tcpi.TcpiLastAckRecv,
|
||||
Pmtu: tcpi.TcpiPmtu,
|
||||
Rcv_ssthresh: tcpi.TcpiRcvSsthresh,
|
||||
Rtt: tcpi.TcpiRtt,
|
||||
Rttvar: tcpi.TcpiRttvar,
|
||||
Snd_ssthresh: tcpi.TcpiSndSsthresh,
|
||||
Snd_cwnd: tcpi.TcpiSndCwnd,
|
||||
Advmss: tcpi.TcpiAdvmss,
|
||||
Reordering: tcpi.TcpiReordering}
|
||||
}
|
||||
}
|
||||
}
|
||||
return skdata
|
||||
}
|
||||
|
||||
func TestGetSocketOptions(t *testing.T) {
|
||||
channelz.NewChannelzStorage()
|
||||
ss := []*dummySocket{
|
||||
{
|
||||
socketOptions: &channelz.SocketOptionData{
|
||||
Linger: &unix.Linger{Onoff: 1, Linger: 2},
|
||||
RecvTimeout: &unix.Timeval{Sec: 10, Usec: 1},
|
||||
SendTimeout: &unix.Timeval{},
|
||||
TCPInfo: &unix.TCPInfo{State: 1},
|
||||
},
|
||||
},
|
||||
}
|
||||
svr := newCZServer()
|
||||
ids := make([]int64, len(ss))
|
||||
svrID := channelz.RegisterServer(&dummyServer{}, "")
|
||||
for i, s := range ss {
|
||||
ids[i] = channelz.RegisterNormalSocket(s, svrID, strconv.Itoa(i))
|
||||
}
|
||||
for i, s := range ss {
|
||||
resp, _ := svr.GetSocket(context.Background(), &channelzpb.GetSocketRequest{SocketId: ids[i]})
|
||||
metrics := resp.GetSocket()
|
||||
if !reflect.DeepEqual(metrics.GetRef(), &channelzpb.SocketRef{SocketId: ids[i], Name: strconv.Itoa(i)}) || !reflect.DeepEqual(socketProtoToStruct(metrics), s) {
|
||||
t.Fatalf("resp.GetSocket() want: metrics.GetRef() = %#v and %#v, got: metrics.GetRef() = %#v and %#v", &channelzpb.SocketRef{SocketId: ids[i], Name: strconv.Itoa(i)}, s, metrics.GetRef(), socketProtoToStruct(metrics))
|
||||
}
|
||||
}
|
||||
}
|
538
vendor/google.golang.org/grpc/channelz/service/service_test.go
generated
vendored
Normal file
538
vendor/google.golang.org/grpc/channelz/service/service_test.go
generated
vendored
Normal file
|
@ -0,0 +1,538 @@
|
|||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"net"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"golang.org/x/net/context"
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
"google.golang.org/grpc/connectivity"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/internal/channelz"
|
||||
)
|
||||
|
||||
func init() {
|
||||
channelz.TurnOn()
|
||||
}
|
||||
|
||||
type protoToSocketOptFunc func([]*channelzpb.SocketOption) *channelz.SocketOptionData
|
||||
|
||||
// protoToSocketOpt is used in function socketProtoToStruct to extract socket option
|
||||
// data from unmarshaled proto message.
|
||||
// It is only defined under linux, non-appengine environment on x86 architecture.
|
||||
var protoToSocketOpt protoToSocketOptFunc
|
||||
|
||||
// emptyTime is used for detecting unset value of time.Time type.
|
||||
// For go1.7 and earlier, ptypes.Timestamp will fill in the loc field of time.Time
|
||||
// with &utcLoc. However zero value of a time.Time type value loc field is nil.
|
||||
// This behavior will make reflect.DeepEqual fail upon unset time.Time field,
|
||||
// and cause false positive fatal error.
|
||||
var emptyTime time.Time
|
||||
|
||||
type dummyChannel struct {
|
||||
state connectivity.State
|
||||
target string
|
||||
callsStarted int64
|
||||
callsSucceeded int64
|
||||
callsFailed int64
|
||||
lastCallStartedTimestamp time.Time
|
||||
}
|
||||
|
||||
func (d *dummyChannel) ChannelzMetric() *channelz.ChannelInternalMetric {
|
||||
return &channelz.ChannelInternalMetric{
|
||||
State: d.state,
|
||||
Target: d.target,
|
||||
CallsStarted: d.callsStarted,
|
||||
CallsSucceeded: d.callsSucceeded,
|
||||
CallsFailed: d.callsFailed,
|
||||
LastCallStartedTimestamp: d.lastCallStartedTimestamp,
|
||||
}
|
||||
}
|
||||
|
||||
type dummyServer struct {
|
||||
callsStarted int64
|
||||
callsSucceeded int64
|
||||
callsFailed int64
|
||||
lastCallStartedTimestamp time.Time
|
||||
}
|
||||
|
||||
func (d *dummyServer) ChannelzMetric() *channelz.ServerInternalMetric {
|
||||
return &channelz.ServerInternalMetric{
|
||||
CallsStarted: d.callsStarted,
|
||||
CallsSucceeded: d.callsSucceeded,
|
||||
CallsFailed: d.callsFailed,
|
||||
LastCallStartedTimestamp: d.lastCallStartedTimestamp,
|
||||
}
|
||||
}
|
||||
|
||||
type dummySocket struct {
|
||||
streamsStarted int64
|
||||
streamsSucceeded int64
|
||||
streamsFailed int64
|
||||
messagesSent int64
|
||||
messagesReceived int64
|
||||
keepAlivesSent int64
|
||||
lastLocalStreamCreatedTimestamp time.Time
|
||||
lastRemoteStreamCreatedTimestamp time.Time
|
||||
lastMessageSentTimestamp time.Time
|
||||
lastMessageReceivedTimestamp time.Time
|
||||
localFlowControlWindow int64
|
||||
remoteFlowControlWindow int64
|
||||
socketOptions *channelz.SocketOptionData
|
||||
localAddr net.Addr
|
||||
remoteAddr net.Addr
|
||||
security credentials.ChannelzSecurityValue
|
||||
remoteName string
|
||||
}
|
||||
|
||||
func (d *dummySocket) ChannelzMetric() *channelz.SocketInternalMetric {
|
||||
return &channelz.SocketInternalMetric{
|
||||
StreamsStarted: d.streamsStarted,
|
||||
StreamsSucceeded: d.streamsSucceeded,
|
||||
StreamsFailed: d.streamsFailed,
|
||||
MessagesSent: d.messagesSent,
|
||||
MessagesReceived: d.messagesReceived,
|
||||
KeepAlivesSent: d.keepAlivesSent,
|
||||
LastLocalStreamCreatedTimestamp: d.lastLocalStreamCreatedTimestamp,
|
||||
LastRemoteStreamCreatedTimestamp: d.lastRemoteStreamCreatedTimestamp,
|
||||
LastMessageSentTimestamp: d.lastMessageSentTimestamp,
|
||||
LastMessageReceivedTimestamp: d.lastMessageReceivedTimestamp,
|
||||
LocalFlowControlWindow: d.localFlowControlWindow,
|
||||
RemoteFlowControlWindow: d.remoteFlowControlWindow,
|
||||
SocketOptions: d.socketOptions,
|
||||
LocalAddr: d.localAddr,
|
||||
RemoteAddr: d.remoteAddr,
|
||||
Security: d.security,
|
||||
RemoteName: d.remoteName,
|
||||
}
|
||||
}
|
||||
|
||||
func channelProtoToStruct(c *channelzpb.Channel) *dummyChannel {
|
||||
dc := &dummyChannel{}
|
||||
pdata := c.GetData()
|
||||
switch pdata.GetState().GetState() {
|
||||
case channelzpb.ChannelConnectivityState_UNKNOWN:
|
||||
// TODO: what should we set here?
|
||||
case channelzpb.ChannelConnectivityState_IDLE:
|
||||
dc.state = connectivity.Idle
|
||||
case channelzpb.ChannelConnectivityState_CONNECTING:
|
||||
dc.state = connectivity.Connecting
|
||||
case channelzpb.ChannelConnectivityState_READY:
|
||||
dc.state = connectivity.Ready
|
||||
case channelzpb.ChannelConnectivityState_TRANSIENT_FAILURE:
|
||||
dc.state = connectivity.TransientFailure
|
||||
case channelzpb.ChannelConnectivityState_SHUTDOWN:
|
||||
dc.state = connectivity.Shutdown
|
||||
}
|
||||
dc.target = pdata.GetTarget()
|
||||
dc.callsStarted = pdata.CallsStarted
|
||||
dc.callsSucceeded = pdata.CallsSucceeded
|
||||
dc.callsFailed = pdata.CallsFailed
|
||||
if t, err := ptypes.Timestamp(pdata.GetLastCallStartedTimestamp()); err == nil {
|
||||
if !t.Equal(emptyTime) {
|
||||
dc.lastCallStartedTimestamp = t
|
||||
}
|
||||
}
|
||||
return dc
|
||||
}
|
||||
|
||||
func serverProtoToStruct(s *channelzpb.Server) *dummyServer {
|
||||
ds := &dummyServer{}
|
||||
pdata := s.GetData()
|
||||
ds.callsStarted = pdata.CallsStarted
|
||||
ds.callsSucceeded = pdata.CallsSucceeded
|
||||
ds.callsFailed = pdata.CallsFailed
|
||||
if t, err := ptypes.Timestamp(pdata.GetLastCallStartedTimestamp()); err == nil {
|
||||
if !t.Equal(emptyTime) {
|
||||
ds.lastCallStartedTimestamp = t
|
||||
}
|
||||
}
|
||||
return ds
|
||||
}
|
||||
|
||||
func socketProtoToStruct(s *channelzpb.Socket) *dummySocket {
|
||||
ds := &dummySocket{}
|
||||
pdata := s.GetData()
|
||||
ds.streamsStarted = pdata.GetStreamsStarted()
|
||||
ds.streamsSucceeded = pdata.GetStreamsSucceeded()
|
||||
ds.streamsFailed = pdata.GetStreamsFailed()
|
||||
ds.messagesSent = pdata.GetMessagesSent()
|
||||
ds.messagesReceived = pdata.GetMessagesReceived()
|
||||
ds.keepAlivesSent = pdata.GetKeepAlivesSent()
|
||||
if t, err := ptypes.Timestamp(pdata.GetLastLocalStreamCreatedTimestamp()); err == nil {
|
||||
if !t.Equal(emptyTime) {
|
||||
ds.lastLocalStreamCreatedTimestamp = t
|
||||
}
|
||||
}
|
||||
if t, err := ptypes.Timestamp(pdata.GetLastRemoteStreamCreatedTimestamp()); err == nil {
|
||||
if !t.Equal(emptyTime) {
|
||||
ds.lastRemoteStreamCreatedTimestamp = t
|
||||
}
|
||||
}
|
||||
if t, err := ptypes.Timestamp(pdata.GetLastMessageSentTimestamp()); err == nil {
|
||||
if !t.Equal(emptyTime) {
|
||||
ds.lastMessageSentTimestamp = t
|
||||
}
|
||||
}
|
||||
if t, err := ptypes.Timestamp(pdata.GetLastMessageReceivedTimestamp()); err == nil {
|
||||
if !t.Equal(emptyTime) {
|
||||
ds.lastMessageReceivedTimestamp = t
|
||||
}
|
||||
}
|
||||
if v := pdata.GetLocalFlowControlWindow(); v != nil {
|
||||
ds.localFlowControlWindow = v.Value
|
||||
}
|
||||
if v := pdata.GetRemoteFlowControlWindow(); v != nil {
|
||||
ds.remoteFlowControlWindow = v.Value
|
||||
}
|
||||
if v := pdata.GetOption(); v != nil && protoToSocketOpt != nil {
|
||||
ds.socketOptions = protoToSocketOpt(v)
|
||||
}
|
||||
if v := s.GetSecurity(); v != nil {
|
||||
ds.security = protoToSecurity(v)
|
||||
}
|
||||
if local := s.GetLocal(); local != nil {
|
||||
ds.localAddr = protoToAddr(local)
|
||||
}
|
||||
if remote := s.GetRemote(); remote != nil {
|
||||
ds.remoteAddr = protoToAddr(remote)
|
||||
}
|
||||
ds.remoteName = s.GetRemoteName()
|
||||
return ds
|
||||
}
|
||||
|
||||
func protoToSecurity(protoSecurity *channelzpb.Security) credentials.ChannelzSecurityValue {
|
||||
switch v := protoSecurity.Model.(type) {
|
||||
case *channelzpb.Security_Tls_:
|
||||
return &credentials.TLSChannelzSecurityValue{StandardName: v.Tls.GetStandardName(), LocalCertificate: v.Tls.GetLocalCertificate(), RemoteCertificate: v.Tls.GetRemoteCertificate()}
|
||||
case *channelzpb.Security_Other:
|
||||
sv := &credentials.OtherChannelzSecurityValue{Name: v.Other.GetName()}
|
||||
var x ptypes.DynamicAny
|
||||
if err := ptypes.UnmarshalAny(v.Other.GetValue(), &x); err == nil {
|
||||
sv.Value = x.Message
|
||||
}
|
||||
return sv
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func protoToAddr(a *channelzpb.Address) net.Addr {
|
||||
switch v := a.Address.(type) {
|
||||
case *channelzpb.Address_TcpipAddress:
|
||||
if port := v.TcpipAddress.GetPort(); port != 0 {
|
||||
return &net.TCPAddr{IP: v.TcpipAddress.GetIpAddress(), Port: int(port)}
|
||||
}
|
||||
return &net.IPAddr{IP: v.TcpipAddress.GetIpAddress()}
|
||||
case *channelzpb.Address_UdsAddress_:
|
||||
return &net.UnixAddr{Name: v.UdsAddress.GetFilename(), Net: "unix"}
|
||||
case *channelzpb.Address_OtherAddress_:
|
||||
// TODO:
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func convertSocketRefSliceToMap(sktRefs []*channelzpb.SocketRef) map[int64]string {
|
||||
m := make(map[int64]string)
|
||||
for _, sr := range sktRefs {
|
||||
m[sr.SocketId] = sr.Name
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
type OtherSecurityValue struct {
|
||||
LocalCertificate []byte `protobuf:"bytes,1,opt,name=local_certificate,json=localCertificate,proto3" json:"local_certificate,omitempty"`
|
||||
RemoteCertificate []byte `protobuf:"bytes,2,opt,name=remote_certificate,json=remoteCertificate,proto3" json:"remote_certificate,omitempty"`
|
||||
}
|
||||
|
||||
func (m *OtherSecurityValue) Reset() { *m = OtherSecurityValue{} }
|
||||
func (m *OtherSecurityValue) String() string { return proto.CompactTextString(m) }
|
||||
func (*OtherSecurityValue) ProtoMessage() {}
|
||||
|
||||
func init() {
|
||||
// Ad-hoc registering the proto type here to facilitate UnmarshalAny of OtherSecurityValue.
|
||||
proto.RegisterType((*OtherSecurityValue)(nil), "grpc.credentials.OtherChannelzSecurityValue")
|
||||
}
|
||||
|
||||
func TestGetTopChannels(t *testing.T) {
|
||||
tcs := []*dummyChannel{
|
||||
{
|
||||
state: connectivity.Connecting,
|
||||
target: "test.channelz:1234",
|
||||
callsStarted: 6,
|
||||
callsSucceeded: 2,
|
||||
callsFailed: 3,
|
||||
lastCallStartedTimestamp: time.Now().UTC(),
|
||||
},
|
||||
{
|
||||
state: connectivity.Connecting,
|
||||
target: "test.channelz:1234",
|
||||
callsStarted: 1,
|
||||
callsSucceeded: 2,
|
||||
callsFailed: 3,
|
||||
lastCallStartedTimestamp: time.Now().UTC(),
|
||||
},
|
||||
{
|
||||
state: connectivity.Shutdown,
|
||||
target: "test.channelz:8888",
|
||||
callsStarted: 0,
|
||||
callsSucceeded: 0,
|
||||
callsFailed: 0,
|
||||
},
|
||||
{},
|
||||
}
|
||||
channelz.NewChannelzStorage()
|
||||
for _, c := range tcs {
|
||||
channelz.RegisterChannel(c, 0, "")
|
||||
}
|
||||
s := newCZServer()
|
||||
resp, _ := s.GetTopChannels(context.Background(), &channelzpb.GetTopChannelsRequest{StartChannelId: 0})
|
||||
if !resp.GetEnd() {
|
||||
t.Fatalf("resp.GetEnd() want true, got %v", resp.GetEnd())
|
||||
}
|
||||
for i, c := range resp.GetChannel() {
|
||||
if !reflect.DeepEqual(channelProtoToStruct(c), tcs[i]) {
|
||||
t.Fatalf("dummyChannel: %d, want: %#v, got: %#v", i, tcs[i], channelProtoToStruct(c))
|
||||
}
|
||||
}
|
||||
for i := 0; i < 50; i++ {
|
||||
channelz.RegisterChannel(tcs[0], 0, "")
|
||||
}
|
||||
resp, _ = s.GetTopChannels(context.Background(), &channelzpb.GetTopChannelsRequest{StartChannelId: 0})
|
||||
if resp.GetEnd() {
|
||||
t.Fatalf("resp.GetEnd() want false, got %v", resp.GetEnd())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetServers(t *testing.T) {
|
||||
ss := []*dummyServer{
|
||||
{
|
||||
callsStarted: 6,
|
||||
callsSucceeded: 2,
|
||||
callsFailed: 3,
|
||||
lastCallStartedTimestamp: time.Now().UTC(),
|
||||
},
|
||||
{
|
||||
callsStarted: 1,
|
||||
callsSucceeded: 2,
|
||||
callsFailed: 3,
|
||||
lastCallStartedTimestamp: time.Now().UTC(),
|
||||
},
|
||||
{
|
||||
callsStarted: 1,
|
||||
callsSucceeded: 0,
|
||||
callsFailed: 0,
|
||||
lastCallStartedTimestamp: time.Now().UTC(),
|
||||
},
|
||||
}
|
||||
channelz.NewChannelzStorage()
|
||||
for _, s := range ss {
|
||||
channelz.RegisterServer(s, "")
|
||||
}
|
||||
svr := newCZServer()
|
||||
resp, _ := svr.GetServers(context.Background(), &channelzpb.GetServersRequest{StartServerId: 0})
|
||||
if !resp.GetEnd() {
|
||||
t.Fatalf("resp.GetEnd() want true, got %v", resp.GetEnd())
|
||||
}
|
||||
for i, s := range resp.GetServer() {
|
||||
if !reflect.DeepEqual(serverProtoToStruct(s), ss[i]) {
|
||||
t.Fatalf("dummyServer: %d, want: %#v, got: %#v", i, ss[i], serverProtoToStruct(s))
|
||||
}
|
||||
}
|
||||
for i := 0; i < 50; i++ {
|
||||
channelz.RegisterServer(ss[0], "")
|
||||
}
|
||||
resp, _ = svr.GetServers(context.Background(), &channelzpb.GetServersRequest{StartServerId: 0})
|
||||
if resp.GetEnd() {
|
||||
t.Fatalf("resp.GetEnd() want false, got %v", resp.GetEnd())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetServerSockets(t *testing.T) {
|
||||
channelz.NewChannelzStorage()
|
||||
svrID := channelz.RegisterServer(&dummyServer{}, "")
|
||||
refNames := []string{"listen socket 1", "normal socket 1", "normal socket 2"}
|
||||
ids := make([]int64, 3)
|
||||
ids[0] = channelz.RegisterListenSocket(&dummySocket{}, svrID, refNames[0])
|
||||
ids[1] = channelz.RegisterNormalSocket(&dummySocket{}, svrID, refNames[1])
|
||||
ids[2] = channelz.RegisterNormalSocket(&dummySocket{}, svrID, refNames[2])
|
||||
svr := newCZServer()
|
||||
resp, _ := svr.GetServerSockets(context.Background(), &channelzpb.GetServerSocketsRequest{ServerId: svrID, StartSocketId: 0})
|
||||
if !resp.GetEnd() {
|
||||
t.Fatalf("resp.GetEnd() want: true, got: %v", resp.GetEnd())
|
||||
}
|
||||
// GetServerSockets only return normal sockets.
|
||||
want := map[int64]string{
|
||||
ids[1]: refNames[1],
|
||||
ids[2]: refNames[2],
|
||||
}
|
||||
if !reflect.DeepEqual(convertSocketRefSliceToMap(resp.GetSocketRef()), want) {
|
||||
t.Fatalf("GetServerSockets want: %#v, got: %#v", want, resp.GetSocketRef())
|
||||
}
|
||||
|
||||
for i := 0; i < 50; i++ {
|
||||
channelz.RegisterNormalSocket(&dummySocket{}, svrID, "")
|
||||
}
|
||||
resp, _ = svr.GetServerSockets(context.Background(), &channelzpb.GetServerSocketsRequest{ServerId: svrID, StartSocketId: 0})
|
||||
if resp.GetEnd() {
|
||||
t.Fatalf("resp.GetEnd() want false, got %v", resp.GetEnd())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetChannel(t *testing.T) {
|
||||
channelz.NewChannelzStorage()
|
||||
refNames := []string{"top channel 1", "nested channel 1", "nested channel 2", "nested channel 3"}
|
||||
ids := make([]int64, 4)
|
||||
ids[0] = channelz.RegisterChannel(&dummyChannel{}, 0, refNames[0])
|
||||
ids[1] = channelz.RegisterChannel(&dummyChannel{}, ids[0], refNames[1])
|
||||
ids[2] = channelz.RegisterSubChannel(&dummyChannel{}, ids[0], refNames[2])
|
||||
ids[3] = channelz.RegisterChannel(&dummyChannel{}, ids[1], refNames[3])
|
||||
svr := newCZServer()
|
||||
resp, _ := svr.GetChannel(context.Background(), &channelzpb.GetChannelRequest{ChannelId: ids[0]})
|
||||
metrics := resp.GetChannel()
|
||||
subChans := metrics.GetSubchannelRef()
|
||||
if len(subChans) != 1 || subChans[0].GetName() != refNames[2] || subChans[0].GetSubchannelId() != ids[2] {
|
||||
t.Fatalf("GetSubChannelRef() want %#v, got %#v", []*channelzpb.SubchannelRef{{SubchannelId: ids[2], Name: refNames[2]}}, subChans)
|
||||
}
|
||||
nestedChans := metrics.GetChannelRef()
|
||||
if len(nestedChans) != 1 || nestedChans[0].GetName() != refNames[1] || nestedChans[0].GetChannelId() != ids[1] {
|
||||
t.Fatalf("GetChannelRef() want %#v, got %#v", []*channelzpb.ChannelRef{{ChannelId: ids[1], Name: refNames[1]}}, nestedChans)
|
||||
}
|
||||
|
||||
resp, _ = svr.GetChannel(context.Background(), &channelzpb.GetChannelRequest{ChannelId: ids[1]})
|
||||
metrics = resp.GetChannel()
|
||||
nestedChans = metrics.GetChannelRef()
|
||||
if len(nestedChans) != 1 || nestedChans[0].GetName() != refNames[3] || nestedChans[0].GetChannelId() != ids[3] {
|
||||
t.Fatalf("GetChannelRef() want %#v, got %#v", []*channelzpb.ChannelRef{{ChannelId: ids[3], Name: refNames[3]}}, nestedChans)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetSubChannel(t *testing.T) {
|
||||
channelz.NewChannelzStorage()
|
||||
refNames := []string{"top channel 1", "sub channel 1", "socket 1", "socket 2"}
|
||||
ids := make([]int64, 4)
|
||||
ids[0] = channelz.RegisterChannel(&dummyChannel{}, 0, refNames[0])
|
||||
ids[1] = channelz.RegisterSubChannel(&dummyChannel{}, ids[0], refNames[1])
|
||||
ids[2] = channelz.RegisterNormalSocket(&dummySocket{}, ids[1], refNames[2])
|
||||
ids[3] = channelz.RegisterNormalSocket(&dummySocket{}, ids[1], refNames[3])
|
||||
svr := newCZServer()
|
||||
resp, _ := svr.GetSubchannel(context.Background(), &channelzpb.GetSubchannelRequest{SubchannelId: ids[1]})
|
||||
metrics := resp.GetSubchannel()
|
||||
want := map[int64]string{
|
||||
ids[2]: refNames[2],
|
||||
ids[3]: refNames[3],
|
||||
}
|
||||
if !reflect.DeepEqual(convertSocketRefSliceToMap(metrics.GetSocketRef()), want) {
|
||||
t.Fatalf("GetSocketRef() want %#v: got: %#v", want, metrics.GetSocketRef())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetSocket(t *testing.T) {
|
||||
channelz.NewChannelzStorage()
|
||||
ss := []*dummySocket{
|
||||
{
|
||||
streamsStarted: 10,
|
||||
streamsSucceeded: 2,
|
||||
streamsFailed: 3,
|
||||
messagesSent: 20,
|
||||
messagesReceived: 10,
|
||||
keepAlivesSent: 2,
|
||||
lastLocalStreamCreatedTimestamp: time.Now().UTC(),
|
||||
lastRemoteStreamCreatedTimestamp: time.Now().UTC(),
|
||||
lastMessageSentTimestamp: time.Now().UTC(),
|
||||
lastMessageReceivedTimestamp: time.Now().UTC(),
|
||||
localFlowControlWindow: 65536,
|
||||
remoteFlowControlWindow: 1024,
|
||||
localAddr: &net.TCPAddr{IP: net.ParseIP("1.0.0.1"), Port: 10001},
|
||||
remoteAddr: &net.TCPAddr{IP: net.ParseIP("12.0.0.1"), Port: 10002},
|
||||
remoteName: "remote.remote",
|
||||
},
|
||||
{
|
||||
streamsStarted: 10,
|
||||
streamsSucceeded: 2,
|
||||
streamsFailed: 3,
|
||||
messagesSent: 20,
|
||||
messagesReceived: 10,
|
||||
keepAlivesSent: 2,
|
||||
lastRemoteStreamCreatedTimestamp: time.Now().UTC(),
|
||||
lastMessageSentTimestamp: time.Now().UTC(),
|
||||
lastMessageReceivedTimestamp: time.Now().UTC(),
|
||||
localFlowControlWindow: 65536,
|
||||
remoteFlowControlWindow: 1024,
|
||||
localAddr: &net.UnixAddr{Name: "file.path", Net: "unix"},
|
||||
remoteAddr: &net.UnixAddr{Name: "another.path", Net: "unix"},
|
||||
remoteName: "remote.remote",
|
||||
},
|
||||
{
|
||||
streamsStarted: 5,
|
||||
streamsSucceeded: 2,
|
||||
streamsFailed: 3,
|
||||
messagesSent: 20,
|
||||
messagesReceived: 10,
|
||||
keepAlivesSent: 2,
|
||||
lastLocalStreamCreatedTimestamp: time.Now().UTC(),
|
||||
lastMessageSentTimestamp: time.Now().UTC(),
|
||||
lastMessageReceivedTimestamp: time.Now().UTC(),
|
||||
localFlowControlWindow: 65536,
|
||||
remoteFlowControlWindow: 10240,
|
||||
localAddr: &net.IPAddr{IP: net.ParseIP("1.0.0.1")},
|
||||
remoteAddr: &net.IPAddr{IP: net.ParseIP("9.0.0.1")},
|
||||
remoteName: "",
|
||||
},
|
||||
{
|
||||
localAddr: &net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 10001},
|
||||
},
|
||||
{
|
||||
security: &credentials.TLSChannelzSecurityValue{
|
||||
StandardName: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
|
||||
RemoteCertificate: []byte{48, 130, 2, 156, 48, 130, 2, 5, 160},
|
||||
},
|
||||
},
|
||||
{
|
||||
security: &credentials.OtherChannelzSecurityValue{
|
||||
Name: "XXXX",
|
||||
},
|
||||
},
|
||||
{
|
||||
security: &credentials.OtherChannelzSecurityValue{
|
||||
Name: "YYYY",
|
||||
Value: &OtherSecurityValue{LocalCertificate: []byte{1, 2, 3}, RemoteCertificate: []byte{4, 5, 6}},
|
||||
},
|
||||
},
|
||||
}
|
||||
svr := newCZServer()
|
||||
ids := make([]int64, len(ss))
|
||||
svrID := channelz.RegisterServer(&dummyServer{}, "")
|
||||
for i, s := range ss {
|
||||
ids[i] = channelz.RegisterNormalSocket(s, svrID, strconv.Itoa(i))
|
||||
}
|
||||
for i, s := range ss {
|
||||
resp, _ := svr.GetSocket(context.Background(), &channelzpb.GetSocketRequest{SocketId: ids[i]})
|
||||
metrics := resp.GetSocket()
|
||||
if !reflect.DeepEqual(metrics.GetRef(), &channelzpb.SocketRef{SocketId: ids[i], Name: strconv.Itoa(i)}) || !reflect.DeepEqual(socketProtoToStruct(metrics), s) {
|
||||
t.Fatalf("resp.GetSocket() want: metrics.GetRef() = %#v and %#v, got: metrics.GetRef() = %#v and %#v", &channelzpb.SocketRef{SocketId: ids[i], Name: strconv.Itoa(i)}, s, metrics.GetRef(), socketProtoToStruct(metrics))
|
||||
}
|
||||
}
|
||||
}
|
33
vendor/google.golang.org/grpc/channelz/service/util_sktopt_386_test.go
generated
vendored
Normal file
33
vendor/google.golang.org/grpc/channelz/service/util_sktopt_386_test.go
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
// +build 386,linux,!appengine,go1.7
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
)
|
||||
|
||||
func protoToTime(protoTime *channelzpb.SocketOptionTimeout) *unix.Timeval {
|
||||
timeout := &unix.Timeval{}
|
||||
sec, usec := convertToDuration(protoTime.GetDuration())
|
||||
timeout.Sec, timeout.Usec = int32(sec), int32(usec)
|
||||
return timeout
|
||||
}
|
32
vendor/google.golang.org/grpc/channelz/service/util_sktopt_amd64_test.go
generated
vendored
Normal file
32
vendor/google.golang.org/grpc/channelz/service/util_sktopt_amd64_test.go
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
// +build amd64,linux,!appengine,go1.7
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright 2018 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
||||
)
|
||||
|
||||
func protoToTime(protoTime *channelzpb.SocketOptionTimeout) *unix.Timeval {
|
||||
timeout := &unix.Timeval{}
|
||||
timeout.Sec, timeout.Usec = convertToDuration(protoTime.GetDuration())
|
||||
return timeout
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue