Restrict channelz service test to x86 architecture (#2179)
This commit is contained in:
Родитель
3ec535a269
Коммит
5ea5eec711
|
@ -1,77 +0,0 @@
|
||||||
// +build !linux appengine
|
|
||||||
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Non-linux system does not support socket option. Therefore, the function
|
|
||||||
// socketProtoToStruct defined in this file skips the parsing of socket option field.
|
|
||||||
|
|
||||||
package service
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/golang/protobuf/ptypes"
|
|
||||||
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
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 := 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
|
|
||||||
}
|
|
|
@ -1,4 +1,5 @@
|
||||||
// +build linux,!appengine
|
// +build linux,!appengine
|
||||||
|
// +build 386 amd64
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -37,6 +38,12 @@ import (
|
||||||
"google.golang.org/grpc/internal/channelz"
|
"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) {
|
func convertToDuration(d *durpb.Duration) (sec int64, usec int64) {
|
||||||
if d != nil {
|
if d != nil {
|
||||||
if dur, err := ptypes.Duration(d); err == nil {
|
if dur, err := ptypes.Duration(d); err == nil {
|
||||||
|
@ -117,57 +124,6 @@ func protoToSocketOption(skopts []*channelzpb.SocketOption) *channelz.SocketOpti
|
||||||
return skdata
|
return skdata
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|
||||||
ds.socketOptions = protoToSocketOption(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 TestGetSocketOptions(t *testing.T) {
|
func TestGetSocketOptions(t *testing.T) {
|
||||||
channelz.NewChannelzStorage()
|
channelz.NewChannelzStorage()
|
||||||
ss := []*dummySocket{
|
ss := []*dummySocket{
|
|
@ -38,6 +38,13 @@ func init() {
|
||||||
channelz.TurnOn()
|
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.
|
// 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
|
// 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.
|
// with &utcLoc. However zero value of a time.Time type value loc field is nil.
|
||||||
|
@ -166,6 +173,57 @@ func serverProtoToStruct(s *channelzpb.Server) *dummyServer {
|
||||||
return ds
|
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 {
|
func protoToSecurity(protoSecurity *channelzpb.Security) credentials.ChannelzSecurityValue {
|
||||||
switch v := protoSecurity.Model.(type) {
|
switch v := protoSecurity.Model.(type) {
|
||||||
case *channelzpb.Security_Tls_:
|
case *channelzpb.Security_Tls_:
|
||||||
|
|
Загрузка…
Ссылка в новой задаче