diff --git a/interop/grpc_testing/test.pb.go b/interop/grpc_testing/test.pb.go index f1b522c8..30453cb2 100644 --- a/interop/grpc_testing/test.pb.go +++ b/interop/grpc_testing/test.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-go. DO NOT EDIT. -// source: grpc_testing/test.proto +// source: test.proto package grpc_testing @@ -53,7 +53,7 @@ func (x PayloadType) String() string { } func (PayloadType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_e1cda82041fed8bf, []int{0} + return fileDescriptor_c161fcfdc0c3ff1e, []int{0} } // The type of route that a client took to reach a server w.r.t. gRPCLB. @@ -90,7 +90,7 @@ func (x GrpclbRouteType) String() string { } func (GrpclbRouteType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_e1cda82041fed8bf, []int{1} + return fileDescriptor_c161fcfdc0c3ff1e, []int{1} } type Empty struct { @@ -103,7 +103,7 @@ func (m *Empty) Reset() { *m = Empty{} } func (m *Empty) String() string { return proto.CompactTextString(m) } func (*Empty) ProtoMessage() {} func (*Empty) Descriptor() ([]byte, []int) { - return fileDescriptor_e1cda82041fed8bf, []int{0} + return fileDescriptor_c161fcfdc0c3ff1e, []int{0} } func (m *Empty) XXX_Unmarshal(b []byte) error { @@ -139,7 +139,7 @@ func (m *Payload) Reset() { *m = Payload{} } func (m *Payload) String() string { return proto.CompactTextString(m) } func (*Payload) ProtoMessage() {} func (*Payload) Descriptor() ([]byte, []int) { - return fileDescriptor_e1cda82041fed8bf, []int{1} + return fileDescriptor_c161fcfdc0c3ff1e, []int{1} } func (m *Payload) XXX_Unmarshal(b []byte) error { @@ -188,7 +188,7 @@ func (m *EchoStatus) Reset() { *m = EchoStatus{} } func (m *EchoStatus) String() string { return proto.CompactTextString(m) } func (*EchoStatus) ProtoMessage() {} func (*EchoStatus) Descriptor() ([]byte, []int) { - return fileDescriptor_e1cda82041fed8bf, []int{2} + return fileDescriptor_c161fcfdc0c3ff1e, []int{2} } func (m *EchoStatus) XXX_Unmarshal(b []byte) error { @@ -252,7 +252,7 @@ func (m *SimpleRequest) Reset() { *m = SimpleRequest{} } func (m *SimpleRequest) String() string { return proto.CompactTextString(m) } func (*SimpleRequest) ProtoMessage() {} func (*SimpleRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_e1cda82041fed8bf, []int{3} + return fileDescriptor_c161fcfdc0c3ff1e, []int{3} } func (m *SimpleRequest) XXX_Unmarshal(b []byte) error { @@ -342,17 +342,19 @@ type SimpleResponse struct { // but the same across all RPC's made to a particular server instance. ServerId string `protobuf:"bytes,4,opt,name=server_id,json=serverId,proto3" json:"server_id,omitempty"` // gRPCLB Path. - GrpclbRouteType GrpclbRouteType `protobuf:"varint,5,opt,name=grpclb_route_type,json=grpclbRouteType,proto3,enum=grpc.testing.GrpclbRouteType" json:"grpclb_route_type,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + GrpclbRouteType GrpclbRouteType `protobuf:"varint,5,opt,name=grpclb_route_type,json=grpclbRouteType,proto3,enum=grpc.testing.GrpclbRouteType" json:"grpclb_route_type,omitempty"` + // Server hostname. + Hostname string `protobuf:"bytes,6,opt,name=hostname,proto3" json:"hostname,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *SimpleResponse) Reset() { *m = SimpleResponse{} } func (m *SimpleResponse) String() string { return proto.CompactTextString(m) } func (*SimpleResponse) ProtoMessage() {} func (*SimpleResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_e1cda82041fed8bf, []int{4} + return fileDescriptor_c161fcfdc0c3ff1e, []int{4} } func (m *SimpleResponse) XXX_Unmarshal(b []byte) error { @@ -408,6 +410,13 @@ func (m *SimpleResponse) GetGrpclbRouteType() GrpclbRouteType { return GrpclbRouteType_GRPCLB_ROUTE_TYPE_UNKNOWN } +func (m *SimpleResponse) GetHostname() string { + if m != nil { + return m.Hostname + } + return "" +} + // Client-streaming request. type StreamingInputCallRequest struct { // Optional input payload sent along with the request. @@ -421,7 +430,7 @@ func (m *StreamingInputCallRequest) Reset() { *m = StreamingInputCallReq func (m *StreamingInputCallRequest) String() string { return proto.CompactTextString(m) } func (*StreamingInputCallRequest) ProtoMessage() {} func (*StreamingInputCallRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_e1cda82041fed8bf, []int{5} + return fileDescriptor_c161fcfdc0c3ff1e, []int{5} } func (m *StreamingInputCallRequest) XXX_Unmarshal(b []byte) error { @@ -462,7 +471,7 @@ func (m *StreamingInputCallResponse) Reset() { *m = StreamingInputCallRe func (m *StreamingInputCallResponse) String() string { return proto.CompactTextString(m) } func (*StreamingInputCallResponse) ProtoMessage() {} func (*StreamingInputCallResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_e1cda82041fed8bf, []int{6} + return fileDescriptor_c161fcfdc0c3ff1e, []int{6} } func (m *StreamingInputCallResponse) XXX_Unmarshal(b []byte) error { @@ -507,7 +516,7 @@ func (m *ResponseParameters) Reset() { *m = ResponseParameters{} } func (m *ResponseParameters) String() string { return proto.CompactTextString(m) } func (*ResponseParameters) ProtoMessage() {} func (*ResponseParameters) Descriptor() ([]byte, []int) { - return fileDescriptor_e1cda82041fed8bf, []int{7} + return fileDescriptor_c161fcfdc0c3ff1e, []int{7} } func (m *ResponseParameters) XXX_Unmarshal(b []byte) error { @@ -564,7 +573,7 @@ func (m *StreamingOutputCallRequest) Reset() { *m = StreamingOutputCallR func (m *StreamingOutputCallRequest) String() string { return proto.CompactTextString(m) } func (*StreamingOutputCallRequest) ProtoMessage() {} func (*StreamingOutputCallRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_e1cda82041fed8bf, []int{8} + return fileDescriptor_c161fcfdc0c3ff1e, []int{8} } func (m *StreamingOutputCallRequest) XXX_Unmarshal(b []byte) error { @@ -626,7 +635,7 @@ func (m *StreamingOutputCallResponse) Reset() { *m = StreamingOutputCall func (m *StreamingOutputCallResponse) String() string { return proto.CompactTextString(m) } func (*StreamingOutputCallResponse) ProtoMessage() {} func (*StreamingOutputCallResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_e1cda82041fed8bf, []int{9} + return fileDescriptor_c161fcfdc0c3ff1e, []int{9} } func (m *StreamingOutputCallResponse) XXX_Unmarshal(b []byte) error { @@ -654,6 +663,104 @@ func (m *StreamingOutputCallResponse) GetPayload() *Payload { return nil } +type LoadBalancerStatsRequest struct { + // Request stats for the next num_rpcs sent by client. + NumRpcs int32 `protobuf:"varint,1,opt,name=num_rpcs,json=numRpcs,proto3" json:"num_rpcs,omitempty"` + // If num_rpcs have not completed within timeout_sec, return partial results. + TimeoutSec int32 `protobuf:"varint,2,opt,name=timeout_sec,json=timeoutSec,proto3" json:"timeout_sec,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *LoadBalancerStatsRequest) Reset() { *m = LoadBalancerStatsRequest{} } +func (m *LoadBalancerStatsRequest) String() string { return proto.CompactTextString(m) } +func (*LoadBalancerStatsRequest) ProtoMessage() {} +func (*LoadBalancerStatsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_c161fcfdc0c3ff1e, []int{10} +} + +func (m *LoadBalancerStatsRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_LoadBalancerStatsRequest.Unmarshal(m, b) +} +func (m *LoadBalancerStatsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_LoadBalancerStatsRequest.Marshal(b, m, deterministic) +} +func (m *LoadBalancerStatsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_LoadBalancerStatsRequest.Merge(m, src) +} +func (m *LoadBalancerStatsRequest) XXX_Size() int { + return xxx_messageInfo_LoadBalancerStatsRequest.Size(m) +} +func (m *LoadBalancerStatsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_LoadBalancerStatsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_LoadBalancerStatsRequest proto.InternalMessageInfo + +func (m *LoadBalancerStatsRequest) GetNumRpcs() int32 { + if m != nil { + return m.NumRpcs + } + return 0 +} + +func (m *LoadBalancerStatsRequest) GetTimeoutSec() int32 { + if m != nil { + return m.TimeoutSec + } + return 0 +} + +type LoadBalancerStatsResponse struct { + // The number of completed RPCs for each peer. + RpcsByPeer map[string]int32 `protobuf:"bytes,1,rep,name=rpcs_by_peer,json=rpcsByPeer,proto3" json:"rpcs_by_peer,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + // The number of RPCs that failed to record a remote peer. + NumFailures int32 `protobuf:"varint,2,opt,name=num_failures,json=numFailures,proto3" json:"num_failures,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *LoadBalancerStatsResponse) Reset() { *m = LoadBalancerStatsResponse{} } +func (m *LoadBalancerStatsResponse) String() string { return proto.CompactTextString(m) } +func (*LoadBalancerStatsResponse) ProtoMessage() {} +func (*LoadBalancerStatsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_c161fcfdc0c3ff1e, []int{11} +} + +func (m *LoadBalancerStatsResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_LoadBalancerStatsResponse.Unmarshal(m, b) +} +func (m *LoadBalancerStatsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_LoadBalancerStatsResponse.Marshal(b, m, deterministic) +} +func (m *LoadBalancerStatsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_LoadBalancerStatsResponse.Merge(m, src) +} +func (m *LoadBalancerStatsResponse) XXX_Size() int { + return xxx_messageInfo_LoadBalancerStatsResponse.Size(m) +} +func (m *LoadBalancerStatsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_LoadBalancerStatsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_LoadBalancerStatsResponse proto.InternalMessageInfo + +func (m *LoadBalancerStatsResponse) GetRpcsByPeer() map[string]int32 { + if m != nil { + return m.RpcsByPeer + } + return nil +} + +func (m *LoadBalancerStatsResponse) GetNumFailures() int32 { + if m != nil { + return m.NumFailures + } + return 0 +} + func init() { proto.RegisterEnum("grpc.testing.PayloadType", PayloadType_name, PayloadType_value) proto.RegisterEnum("grpc.testing.GrpclbRouteType", GrpclbRouteType_name, GrpclbRouteType_value) @@ -667,63 +774,77 @@ func init() { proto.RegisterType((*ResponseParameters)(nil), "grpc.testing.ResponseParameters") proto.RegisterType((*StreamingOutputCallRequest)(nil), "grpc.testing.StreamingOutputCallRequest") proto.RegisterType((*StreamingOutputCallResponse)(nil), "grpc.testing.StreamingOutputCallResponse") + proto.RegisterType((*LoadBalancerStatsRequest)(nil), "grpc.testing.LoadBalancerStatsRequest") + proto.RegisterType((*LoadBalancerStatsResponse)(nil), "grpc.testing.LoadBalancerStatsResponse") + proto.RegisterMapType((map[string]int32)(nil), "grpc.testing.LoadBalancerStatsResponse.RpcsByPeerEntry") } -func init() { proto.RegisterFile("grpc_testing/test.proto", fileDescriptor_e1cda82041fed8bf) } +func init() { proto.RegisterFile("test.proto", fileDescriptor_c161fcfdc0c3ff1e) } -var fileDescriptor_e1cda82041fed8bf = []byte{ - // 801 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0xdd, 0x4e, 0xdb, 0x48, - 0x14, 0xc6, 0xf9, 0x21, 0xe4, 0x24, 0x84, 0x30, 0x59, 0x16, 0x13, 0x96, 0xdd, 0xc8, 0xbb, 0xd2, - 0x7a, 0x91, 0x36, 0xac, 0x82, 0xb6, 0x17, 0x95, 0xda, 0x2a, 0x84, 0x40, 0x23, 0x42, 0x92, 0xda, - 0xb1, 0xaa, 0x5e, 0x59, 0x43, 0x32, 0x18, 0x4b, 0x8e, 0xed, 0xda, 0x63, 0x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 0x98, 0x41, 0x4c, 0x56, 0x04, 0x39, 0x57, 0xdb, 0x59, 0x99, 0x5e, 0x89, - 0x51, 0x2c, 0xeb, 0xb5, 0x69, 0x59, 0x7a, 0xe0, 0x13, 0xcf, 0xc6, 0x23, 0x22, 0xa6, 0x2a, 0x82, - 0xbc, 0xa1, 0xe4, 0x99, 0x51, 0x8b, 0x6c, 0x48, 0x86, 0x22, 0x07, 0x39, 0x38, 0xa0, 0x37, 0xba, - 0x3f, 0x70, 0x5c, 0x22, 0xa6, 0x39, 0xae, 0xc0, 0xec, 0x5d, 0x66, 0x56, 0x99, 0x15, 0xd5, 0x61, - 0x6b, 0xda, 0x24, 0xd7, 0x4d, 0xcc, 0xf0, 0x3e, 0xc4, 0xf9, 0x3e, 0xa6, 0xba, 0x2a, 0x85, 0x09, - 0x81, 0x50, 0xe7, 0xbf, 0x80, 0x27, 0xd5, 0x7d, 0xe2, 0xdd, 0x12, 0x4f, 0x37, 0x87, 0x62, 0x76, - 0xda, 0x92, 0xca, 0x8d, 0xad, 0x21, 0x3a, 0x86, 0x5f, 0x39, 0x8a, 0x65, 0xb5, 0xae, 0x74, 0xcf, - 0x09, 0x68, 0x24, 0x2b, 0x70, 0x74, 0x89, 0x79, 0xcf, 0xb9, 0x53, 0x61, 0x3e, 0x26, 0xa1, 0xf4, - 0x45, 0x80, 0x42, 0x7c, 0x29, 0x61, 0xcd, 0x59, 0xc1, 0x84, 0x07, 0x09, 0x56, 0x86, 0x8d, 0x89, - 0x56, 0xe1, 0x9d, 0x4f, 0xce, 0xe8, 0x0f, 0xc8, 0xcd, 0x4a, 0x94, 0xe4, 0x6e, 0x70, 0xa6, 0xf2, - 0xec, 0x43, 0x76, 0x4a, 0x2b, 0x15, 0x46, 0xfb, 0x31, 0xa5, 0x16, 0x6c, 0x2f, 0xb3, 0x49, 0xf3, - 0x21, 0x39, 0x98, 0x6f, 0x6a, 0x81, 0x97, 0xb2, 0x65, 0x2c, 0x10, 0x6d, 0xc3, 0x9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3, 0xf6, 0xdc, 0x4c, 0xec, 0x08, 0x00, - 0x00, +var fileDescriptor_c161fcfdc0c3ff1e = []byte{ + // 983 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x56, 0x6d, 0x6f, 0x1b, 0x45, + 0x10, 0xce, 0x39, 0x71, 0x1c, 0x8f, 0x5d, 0xc7, 0xdd, 0xb4, 0x70, 0x76, 0x28, 0x98, 0x03, 0xd1, + 0xa3, 0x12, 0x06, 0xb9, 0xe2, 0x45, 0x95, 0x0a, 0xb2, 0x1d, 0x27, 0x44, 0x75, 0x6d, 0x73, 0xb6, + 0x41, 0xfd, 0x74, 0xda, 0x9c, 0x27, 0xce, 0x89, 0x7b, 0x63, 0x6f, 0x2f, 0xc2, 0xfd, 0x82, 0xc4, + 0x4f, 0xe0, 0x2f, 0xf0, 0x33, 0xf8, 0x23, 0xfc, 0x1c, 0xb4, 0x7b, 0x77, 0x7e, 0x8f, 0x9a, 0x50, + 0xc1, 0xb7, 0xdb, 0x67, 0x66, 0x9e, 0x9d, 0x79, 0x66, 0x76, 0x6c, 0x00, 0x8e, 0x21, 0xaf, 0x07, + 0xcc, 0xe7, 0x3e, 0x29, 0x4e, 0x59, 0x60, 0xd5, 0x05, 0x60, 0x7b, 0x53, 0x2d, 0x07, 0xd9, 0x8e, + 0x1b, 0xf0, 0x99, 0xd6, 0x85, 0xdc, 0x80, 0xce, 0x1c, 0x9f, 0x4e, 0xc8, 0x67, 0xb0, 0xc7, 0x67, + 0x01, 0xaa, 0x4a, 0x4d, 0xd1, 0x4b, 0x8d, 0x4a, 0x7d, 0x39, 0xa0, 0x9e, 0x38, 0x8d, 0x66, 0x01, + 0x1a, 0xd2, 0x8d, 0x10, 0xd8, 0xbb, 0xf0, 0x27, 0x33, 0x35, 0x53, 0x53, 0xf4, 0xa2, 0x21, 0xbf, + 0xb5, 0x67, 0x00, 0x1d, 0xeb, 0x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df, 0xf6, 0x55, 0xfe, 0x00, 0x47, 0xf3, 0xf8, 0x60, 0x9e, 0xaa, 0x9a, 0xa9, 0xed, 0xea, + 0x85, 0x46, 0x6d, 0x95, 0x65, 0xb3, 0x24, 0x83, 0xb0, 0xcd, 0x32, 0xef, 0xfc, 0x86, 0xdf, 0xfe, + 0xd1, 0x69, 0x3d, 0x38, 0xde, 0x2a, 0xd2, 0xbf, 0x7c, 0x25, 0xda, 0x8f, 0xa0, 0x76, 0x7d, 0x3a, + 0x69, 0x51, 0x87, 0x7a, 0x16, 0x32, 0x71, 0x4b, 0x98, 0x4a, 0x5e, 0x81, 0x03, 0x2f, 0x72, 0x4d, + 0x16, 0x58, 0x61, 0xd2, 0xca, 0x9c, 0x17, 0xb9, 0x46, 0x60, 0x85, 0xa2, 0x9b, 0xdc, 0x76, 0xd1, + 0x8f, 0xb8, 0x19, 0xa2, 0x95, 0x76, 0x33, 0x81, 0x86, 0x68, 0x69, 0x7f, 0x2b, 0x50, 0xd9, 0x42, + 0x9c, 0xa4, 0xf9, 0x0a, 0x8a, 0x82, 0xd5, 0xbc, 0x98, 0x99, 0x01, 0x22, 0x53, 0x15, 0xd9, 0x85, + 0xaf, 0x57, 0x73, 0xbd, 0x31, 0xbc, 0x2e, 0x52, 0x68, 0xcd, 0x06, 0x88, 0xac, 0xe3, 0x71, 0x36, + 0x33, 0x80, 0xcd, 0x01, 0xf2, 0x21, 0x14, 0x45, 0xd2, 0x97, 0xd4, 0x76, 0x22, 0x86, 0xe9, 0xa0, + 0x15, 0xbc, 0xc8, 0x3d, 0x4d, 0xa0, 0xea, 0x73, 0x38, 0x5c, 0x63, 0x20, 0x65, 0xd8, 0xfd, 0x19, + 0x67, 0xb2, 0xca, 0xbc, 0x21, 0x3e, 0xc9, 0x03, 0xc8, 0x5e, 0x53, 0x27, 0x4a, 0xb7, 0x77, 0x7c, + 0x78, 0x96, 0xf9, 0x46, 0x79, 0xf2, 0x1d, 0x14, 0x96, 0xc6, 0x8c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0xa2, + 0xc0, 0xc1, 0x5f, 0xff, 0xb3, 0x9a, 0x74, 0x45, 0x56, 0x55, 0xfa, 0x9e, 0x3a, 0x97, 0xff, 0xc3, + 0x55, 0x8d, 0x31, 0x3c, 0x18, 0x7b, 0xb2, 0x83, 0x2e, 0x7a, 0x1c, 0x27, 0xe9, 0x14, 0x3d, 0x87, + 0xfb, 0x2b, 0xf8, 0xdd, 0xa6, 0xa9, 0xf1, 0xdb, 0x96, 0xcd, 0x93, 0x52, 0x5b, 0x50, 0x3a, 0x43, + 0xde, 0x76, 0x6c, 0xf4, 0xb8, 0x34, 0x90, 0x4f, 0xde, 0xb8, 0x1b, 0xe2, 0xda, 0x1e, 0xdf, 0x72, + 0x87, 0x68, 0x3b, 0x17, 0xfb, 0xf2, 0x1f, 0xea, 0xd3, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x28, + 0xec, 0x5c, 0x9c, 0xaf, 0x0a, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1137,7 +1258,7 @@ var _TestService_serviceDesc = grpc.ServiceDesc{ ClientStreams: true, }, }, - Metadata: "grpc_testing/test.proto", + Metadata: "test.proto", } // UnimplementedServiceClient is the client API for UnimplementedService service. @@ -1211,5 +1332,79 @@ var _UnimplementedService_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "grpc_testing/test.proto", + Metadata: "test.proto", +} + +// LoadBalancerStatsServiceClient is the client API for LoadBalancerStatsService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type LoadBalancerStatsServiceClient interface { + // Gets the backend distribution for RPCs sent by a test client. + GetClientStats(ctx context.Context, in *LoadBalancerStatsRequest, opts ...grpc.CallOption) (*LoadBalancerStatsResponse, error) +} + +type loadBalancerStatsServiceClient struct { + cc *grpc.ClientConn +} + +func NewLoadBalancerStatsServiceClient(cc *grpc.ClientConn) LoadBalancerStatsServiceClient { + return &loadBalancerStatsServiceClient{cc} +} + +func (c *loadBalancerStatsServiceClient) GetClientStats(ctx context.Context, in *LoadBalancerStatsRequest, opts ...grpc.CallOption) (*LoadBalancerStatsResponse, error) { + out := new(LoadBalancerStatsResponse) + err := c.cc.Invoke(ctx, "/grpc.testing.LoadBalancerStatsService/GetClientStats", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// LoadBalancerStatsServiceServer is the server API for LoadBalancerStatsService service. +type LoadBalancerStatsServiceServer interface { + // Gets the backend distribution for RPCs sent by a test client. + GetClientStats(context.Context, *LoadBalancerStatsRequest) (*LoadBalancerStatsResponse, error) +} + +// UnimplementedLoadBalancerStatsServiceServer can be embedded to have forward compatible implementations. +type UnimplementedLoadBalancerStatsServiceServer struct { +} + +func (*UnimplementedLoadBalancerStatsServiceServer) GetClientStats(ctx context.Context, req *LoadBalancerStatsRequest) (*LoadBalancerStatsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetClientStats not implemented") +} + +func RegisterLoadBalancerStatsServiceServer(s *grpc.Server, srv LoadBalancerStatsServiceServer) { + s.RegisterService(&_LoadBalancerStatsService_serviceDesc, srv) +} + +func _LoadBalancerStatsService_GetClientStats_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(LoadBalancerStatsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LoadBalancerStatsServiceServer).GetClientStats(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/grpc.testing.LoadBalancerStatsService/GetClientStats", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LoadBalancerStatsServiceServer).GetClientStats(ctx, req.(*LoadBalancerStatsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _LoadBalancerStatsService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "grpc.testing.LoadBalancerStatsService", + HandlerType: (*LoadBalancerStatsServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetClientStats", + Handler: _LoadBalancerStatsService_GetClientStats_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "test.proto", } diff --git a/interop/grpc_testing/test.proto b/interop/grpc_testing/test.proto index 5d6e0a17..b9eaa64b 100644 --- a/interop/grpc_testing/test.proto +++ b/interop/grpc_testing/test.proto @@ -109,6 +109,9 @@ message SimpleResponse { // gRPCLB Path. GrpclbRouteType grpclb_route_type = 5; + + // Server hostname. + string hostname = 6; } // Client-streaming request. @@ -200,3 +203,24 @@ service UnimplementedService { // A call that no server should implement rpc UnimplementedCall(grpc.testing.Empty) returns (grpc.testing.Empty); } + +message LoadBalancerStatsRequest { + // Request stats for the next num_rpcs sent by client. + int32 num_rpcs = 1; + // If num_rpcs have not completed within timeout_sec, return partial results. + int32 timeout_sec = 2; +} + +message LoadBalancerStatsResponse { + // The number of completed RPCs for each peer. + map rpcs_by_peer = 1; + // The number of RPCs that failed to record a remote peer. + int32 num_failures = 2; +} + +// A service used to obtain stats for verifying LB behavior. +service LoadBalancerStatsService { + // Gets the backend distribution for RPCs sent by a test client. + rpc GetClientStats(LoadBalancerStatsRequest) + returns (LoadBalancerStatsResponse) {} +} diff --git a/interop/xds/client/client.go b/interop/xds/client/client.go new file mode 100644 index 00000000..a7226fe8 --- /dev/null +++ b/interop/xds/client/client.go @@ -0,0 +1,169 @@ +/* + * + * Copyright 2020 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. + * + */ + +// Binary client for xDS interop tests. +package main + +import ( + "context" + "flag" + "fmt" + "net" + "sync" + "time" + + "google.golang.org/grpc" + "google.golang.org/grpc/grpclog" + testpb "google.golang.org/grpc/interop/grpc_testing" + "google.golang.org/grpc/peer" +) + +type statsWatcherKey struct { + startID int32 + endID int32 +} + +type statsWatcher struct { + rpcsByPeer map[string]int32 + numFailures int32 + remainingRpcs int32 + c chan *testpb.SimpleResponse +} + +var ( + numChannels = flag.Int("num_channels", 1, "Num of channels") + printResponse = flag.Bool("print_response", false, "Write RPC response to stdout") + qps = flag.Int("qps", 1, "QPS per channel") + rpcTimeout = flag.Duration("rpc_timeout", 10*time.Second, "Per RPC timeout") + server = flag.String("server", "localhost:8080", "Address of server to connect to") + statsPort = flag.Int("stats_port", 8081, "Port to expose peer distribution stats service") + + mu sync.Mutex + currentRequestID int32 + watchers = make(map[statsWatcherKey]*statsWatcher) +) + +type statsService struct{} + +// Wait for the next LoadBalancerStatsRequest.GetNumRpcs to start and complete, +// and return the distribution of remote peers. This is essentially a clientside +// LB reporting mechanism that is designed to be queried by an external test +// driver when verifying that the client is distributing RPCs as expected. +func (s *statsService) GetClientStats(ctx context.Context, in *testpb.LoadBalancerStatsRequest) (*testpb.LoadBalancerStatsResponse, error) { + mu.Lock() + watcherKey := statsWatcherKey{currentRequestID, currentRequestID + in.GetNumRpcs()} + watcher, ok := watchers[watcherKey] + if !ok { + watcher = &statsWatcher{ + rpcsByPeer: make(map[string]int32), + numFailures: 0, + remainingRpcs: in.GetNumRpcs(), + c: make(chan *testpb.SimpleResponse), + } + watchers[watcherKey] = watcher + } + mu.Unlock() + + ctx, cancel := context.WithTimeout(ctx, time.Duration(in.GetTimeoutSec())*time.Second) + defer cancel() + + defer func() { + mu.Lock() + delete(watchers, watcherKey) + mu.Unlock() + }() + + // Wait until the requested RPCs have all been recorded or timeout occurs. + for { + select { + case r := <-watcher.c: + if r != nil { + watcher.rpcsByPeer[(*r).GetServerId()]++ + } else { + watcher.numFailures++ + } + watcher.remainingRpcs-- + if watcher.remainingRpcs == 0 { + return &testpb.LoadBalancerStatsResponse{NumFailures: watcher.numFailures + watcher.remainingRpcs, RpcsByPeer: watcher.rpcsByPeer}, nil + } + case <-ctx.Done(): + grpclog.Info("Timed out, returning partial stats") + return &testpb.LoadBalancerStatsResponse{NumFailures: watcher.numFailures + watcher.remainingRpcs, RpcsByPeer: watcher.rpcsByPeer}, nil + } + } +} + +func main() { + flag.Parse() + + lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *statsPort)) + if err != nil { + grpclog.Fatalf("failed to listen: %v", err) + } + s := grpc.NewServer() + defer s.Stop() + testpb.RegisterLoadBalancerStatsServiceServer(s, &statsService{}) + go s.Serve(lis) + + clients := make([]testpb.TestServiceClient, *numChannels) + for i := 0; i < *numChannels; i++ { + conn, err := grpc.DialContext(context.Background(), *server, grpc.WithInsecure(), grpc.WithBlock()) + if err != nil { + grpclog.Fatalf("Fail to dial: %v", err) + } + defer conn.Close() + clients[i] = testpb.NewTestServiceClient(conn) + } + ticker := time.NewTicker(time.Second / time.Duration(*qps**numChannels)) + defer ticker.Stop() + sendRPCs(clients, ticker) +} + +func sendRPCs(clients []testpb.TestServiceClient, ticker *time.Ticker) { + var i int + for range ticker.C { + go func(i int) { + c := clients[i] + ctx, cancel := context.WithTimeout(context.Background(), *rpcTimeout) + p := new(peer.Peer) + mu.Lock() + savedRequestID := currentRequestID + currentRequestID++ + savedWatchers := []*statsWatcher{} + for key, value := range watchers { + if key.startID <= savedRequestID && savedRequestID < key.endID { + savedWatchers = append(savedWatchers, value) + } + } + mu.Unlock() + r, err := c.UnaryCall(ctx, &testpb.SimpleRequest{FillServerId: true}, grpc.Peer(p)) + + success := err == nil + cancel() + + for _, watcher := range savedWatchers { + watcher.c <- r + } + + if success && *printResponse { + fmt.Printf("Greeting: Hello world, this is %s, from %v\n", r.GetHostname(), p.Addr) + } + }(i) + i = (i + 1) % len(clients) + } +} diff --git a/interop/xds/server/server.go b/interop/xds/server/server.go new file mode 100644 index 00000000..34ada6b5 --- /dev/null +++ b/interop/xds/server/server.go @@ -0,0 +1,67 @@ +/* + * + * Copyright 2020 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. + * + */ + +// Binary server for xDS interop tests. +package main + +import ( + "context" + "flag" + "log" + "net" + "os" + "strconv" + + "google.golang.org/grpc" + "google.golang.org/grpc/grpclog" + testpb "google.golang.org/grpc/interop/grpc_testing" +) + +var ( + port = flag.Int("port", 8080, "The server port") + serverID = flag.String("server_id", "go_server", "Server ID included in response") + hostname = getHostname() +) + +func getHostname() string { + hostname, err := os.Hostname() + if err != nil { + log.Fatalf("failed to get hostname: %v", err) + } + return hostname +} + +type server struct { + testpb.UnimplementedTestServiceServer +} + +func (s *server) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { + return &testpb.SimpleResponse{ServerId: *serverID, Hostname: hostname}, nil +} + +func main() { + flag.Parse() + p := strconv.Itoa(*port) + lis, err := net.Listen("tcp", ":"+p) + if err != nil { + grpclog.Fatalf("failed to listen: %v", err) + } + s := grpc.NewServer() + testpb.RegisterTestServiceServer(s, &server{}) + s.Serve(lis) +}