From 626c78cfe781a861a106869bec45134176133284 Mon Sep 17 00:00:00 2001 From: agile6v Date: Sun, 24 Mar 2019 12:44:02 +0800 Subject: [PATCH] Code improvements. --- pkg/config/config.go | 1 + pkg/pb/squeeze.pb.go | 616 +++++-------------------------- pkg/pb/squeeze.proto | 46 +-- pkg/proto/common.go | 6 +- pkg/proto/http/http.go | 106 +++--- pkg/proto/udp/udp.go | 82 ++-- pkg/proto/websocket/websocket.go | 85 ++--- pkg/server/slave_server.go | 10 +- pkg/server/work.go | 6 +- 9 files changed, 230 insertions(+), 728 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 582c759..5bf4901 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -51,6 +51,7 @@ type HttpOptions struct { BodyFile string `json:"bodyFile,omitempty"` ContentType string `json:"contentType,omitempty"` MaxResults int `json:"maxResults,omitempty"` + DisableRedirects bool `json:"disableRedirects,omitempty"` DisableKeepAlive bool `json:"disableKeepAlive,omitempty"` DisableCompression bool `json:"disableCompression,omitempty"` } diff --git a/pkg/pb/squeeze.pb.go b/pkg/pb/squeeze.pb.go index 844d34a..d6633ce 100644 --- a/pkg/pb/squeeze.pb.go +++ b/pkg/pb/squeeze.pb.go @@ -68,7 +68,7 @@ func (x Protocol) String() string { return proto.EnumName(Protocol_name, int32(x)) } func (Protocol) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{0} + return fileDescriptor_squeeze_c8f7ad5b2d33e9bc, []int{0} } type HeartBeatRequest_Task_Status int32 @@ -91,7 +91,7 @@ func (x HeartBeatRequest_Task_Status) String() string { return proto.EnumName(HeartBeatRequest_Task_Status_name, int32(x)) } func (HeartBeatRequest_Task_Status) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{0, 1, 0} + return fileDescriptor_squeeze_c8f7ad5b2d33e9bc, []int{0, 1, 0} } type ExecuteTaskRequest_Command int32 @@ -114,7 +114,7 @@ func (x ExecuteTaskRequest_Command) String() string { return proto.EnumName(ExecuteTaskRequest_Command_name, int32(x)) } func (ExecuteTaskRequest_Command) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{3, 0} + return fileDescriptor_squeeze_c8f7ad5b2d33e9bc, []int{3, 0} } type ExecuteTaskResponse_Status int32 @@ -137,7 +137,7 @@ func (x ExecuteTaskResponse_Status) String() string { return proto.EnumName(ExecuteTaskResponse_Status_name, int32(x)) } func (ExecuteTaskResponse_Status) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{4, 0} + return fileDescriptor_squeeze_c8f7ad5b2d33e9bc, []int{4, 0} } // HeartBeatRequest describes the tasks status on the slave @@ -154,7 +154,7 @@ func (m *HeartBeatRequest) Reset() { *m = HeartBeatRequest{} } func (m *HeartBeatRequest) String() string { return proto.CompactTextString(m) } func (*HeartBeatRequest) ProtoMessage() {} func (*HeartBeatRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{0} + return fileDescriptor_squeeze_c8f7ad5b2d33e9bc, []int{0} } func (m *HeartBeatRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_HeartBeatRequest.Unmarshal(m, b) @@ -199,7 +199,7 @@ func (m *HeartBeatRequest_SlaveInfo) Reset() { *m = HeartBeatRequest_Sla func (m *HeartBeatRequest_SlaveInfo) String() string { return proto.CompactTextString(m) } func (*HeartBeatRequest_SlaveInfo) ProtoMessage() {} func (*HeartBeatRequest_SlaveInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{0, 0} + return fileDescriptor_squeeze_c8f7ad5b2d33e9bc, []int{0, 0} } func (m *HeartBeatRequest_SlaveInfo) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_HeartBeatRequest_SlaveInfo.Unmarshal(m, b) @@ -238,7 +238,7 @@ func (m *HeartBeatRequest_Task) Reset() { *m = HeartBeatRequest_Task{} } func (m *HeartBeatRequest_Task) String() string { return proto.CompactTextString(m) } func (*HeartBeatRequest_Task) ProtoMessage() {} func (*HeartBeatRequest_Task) Descriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{0, 1} + return fileDescriptor_squeeze_c8f7ad5b2d33e9bc, []int{0, 1} } func (m *HeartBeatRequest_Task) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_HeartBeatRequest_Task.Unmarshal(m, b) @@ -285,7 +285,7 @@ func (m *HeartBeatResponse) Reset() { *m = HeartBeatResponse{} } func (m *HeartBeatResponse) String() string { return proto.CompactTextString(m) } func (*HeartBeatResponse) ProtoMessage() {} func (*HeartBeatResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{1} + return fileDescriptor_squeeze_c8f7ad5b2d33e9bc, []int{1} } func (m *HeartBeatResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_HeartBeatResponse.Unmarshal(m, b) @@ -313,24 +313,16 @@ func (m *HeartBeatResponse) GetTasks() []*TaskRequest { } type TaskRequest struct { - Concurrency uint32 `protobuf:"varint,1,opt,name=concurrency,proto3" json:"concurrency,omitempty"` - Requests uint32 `protobuf:"varint,2,opt,name=requests,proto3" json:"requests,omitempty"` - RateLimit uint32 `protobuf:"varint,3,opt,name=rateLimit,proto3" json:"rateLimit,omitempty"` - // Types that are valid to be assigned to Type: - // *TaskRequest_Http - // *TaskRequest_Websocket - // *TaskRequest_Udp - Type isTaskRequest_Type `protobuf_oneof:"type"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *TaskRequest) Reset() { *m = TaskRequest{} } func (m *TaskRequest) String() string { return proto.CompactTextString(m) } func (*TaskRequest) ProtoMessage() {} func (*TaskRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{2} + return fileDescriptor_squeeze_c8f7ad5b2d33e9bc, []int{2} } func (m *TaskRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_TaskRequest.Unmarshal(m, b) @@ -350,170 +342,6 @@ func (m *TaskRequest) XXX_DiscardUnknown() { var xxx_messageInfo_TaskRequest proto.InternalMessageInfo -func (m *TaskRequest) GetConcurrency() uint32 { - if m != nil { - return m.Concurrency - } - return 0 -} - -func (m *TaskRequest) GetRequests() uint32 { - if m != nil { - return m.Requests - } - return 0 -} - -func (m *TaskRequest) GetRateLimit() uint32 { - if m != nil { - return m.RateLimit - } - return 0 -} - -type isTaskRequest_Type interface { - isTaskRequest_Type() -} - -type TaskRequest_Http struct { - Http *HttpTask `protobuf:"bytes,4,opt,name=http,proto3,oneof"` -} - -type TaskRequest_Websocket struct { - Websocket *WebsocketTask `protobuf:"bytes,5,opt,name=websocket,proto3,oneof"` -} - -type TaskRequest_Udp struct { - Udp *UDPTask `protobuf:"bytes,6,opt,name=udp,proto3,oneof"` -} - -func (*TaskRequest_Http) isTaskRequest_Type() {} - -func (*TaskRequest_Websocket) isTaskRequest_Type() {} - -func (*TaskRequest_Udp) isTaskRequest_Type() {} - -func (m *TaskRequest) GetType() isTaskRequest_Type { - if m != nil { - return m.Type - } - return nil -} - -func (m *TaskRequest) GetHttp() *HttpTask { - if x, ok := m.GetType().(*TaskRequest_Http); ok { - return x.Http - } - return nil -} - -func (m *TaskRequest) GetWebsocket() *WebsocketTask { - if x, ok := m.GetType().(*TaskRequest_Websocket); ok { - return x.Websocket - } - return nil -} - -func (m *TaskRequest) GetUdp() *UDPTask { - if x, ok := m.GetType().(*TaskRequest_Udp); ok { - return x.Udp - } - return nil -} - -// XXX_OneofFuncs is for the internal use of the proto package. -func (*TaskRequest) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) { - return _TaskRequest_OneofMarshaler, _TaskRequest_OneofUnmarshaler, _TaskRequest_OneofSizer, []interface{}{ - (*TaskRequest_Http)(nil), - (*TaskRequest_Websocket)(nil), - (*TaskRequest_Udp)(nil), - } -} - -func _TaskRequest_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { - m := msg.(*TaskRequest) - // type - switch x := m.Type.(type) { - case *TaskRequest_Http: - b.EncodeVarint(4<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.Http); err != nil { - return err - } - case *TaskRequest_Websocket: - b.EncodeVarint(5<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.Websocket); err != nil { - return err - } - case *TaskRequest_Udp: - b.EncodeVarint(6<<3 | proto.WireBytes) - if err := b.EncodeMessage(x.Udp); err != nil { - return err - } - case nil: - default: - return fmt.Errorf("TaskRequest.Type has unexpected type %T", x) - } - return nil -} - -func _TaskRequest_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { - m := msg.(*TaskRequest) - switch tag { - case 4: // type.http - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(HttpTask) - err := b.DecodeMessage(msg) - m.Type = &TaskRequest_Http{msg} - return true, err - case 5: // type.websocket - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(WebsocketTask) - err := b.DecodeMessage(msg) - m.Type = &TaskRequest_Websocket{msg} - return true, err - case 6: // type.udp - if wire != proto.WireBytes { - return true, proto.ErrInternalBadWireType - } - msg := new(UDPTask) - err := b.DecodeMessage(msg) - m.Type = &TaskRequest_Udp{msg} - return true, err - default: - return false, nil - } -} - -func _TaskRequest_OneofSizer(msg proto.Message) (n int) { - m := msg.(*TaskRequest) - // type - switch x := m.Type.(type) { - case *TaskRequest_Http: - s := proto.Size(x.Http) - n += 1 // tag and wire - n += proto.SizeVarint(uint64(s)) - n += s - case *TaskRequest_Websocket: - s := proto.Size(x.Websocket) - n += 1 // tag and wire - n += proto.SizeVarint(uint64(s)) - n += s - case *TaskRequest_Udp: - s := proto.Size(x.Udp) - n += 1 // tag and wire - n += proto.SizeVarint(uint64(s)) - n += s - case nil: - default: - panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) - } - return n -} - // ExecuteTaskRequest describes the task information to be executed. type ExecuteTaskRequest struct { Cmd ExecuteTaskRequest_Command `protobuf:"varint,1,opt,name=cmd,proto3,enum=pb.ExecuteTaskRequest_Command" json:"cmd,omitempty"` @@ -521,7 +349,10 @@ type ExecuteTaskRequest struct { Callback string `protobuf:"bytes,3,opt,name=callback,proto3" json:"callback,omitempty"` Duration uint32 `protobuf:"varint,4,opt,name=duration,proto3" json:"duration,omitempty"` Id uint32 `protobuf:"varint,5,opt,name=id,proto3" json:"id,omitempty"` - Task *TaskRequest `protobuf:"bytes,6,opt,name=task,proto3" json:"task,omitempty"` + Concurrency uint32 `protobuf:"varint,6,opt,name=concurrency,proto3" json:"concurrency,omitempty"` + Requests uint32 `protobuf:"varint,7,opt,name=requests,proto3" json:"requests,omitempty"` + RateLimit uint32 `protobuf:"varint,8,opt,name=rateLimit,proto3" json:"rateLimit,omitempty"` + Data string `protobuf:"bytes,9,opt,name=data,proto3" json:"data,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -531,7 +362,7 @@ func (m *ExecuteTaskRequest) Reset() { *m = ExecuteTaskRequest{} } func (m *ExecuteTaskRequest) String() string { return proto.CompactTextString(m) } func (*ExecuteTaskRequest) ProtoMessage() {} func (*ExecuteTaskRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{3} + return fileDescriptor_squeeze_c8f7ad5b2d33e9bc, []int{3} } func (m *ExecuteTaskRequest) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ExecuteTaskRequest.Unmarshal(m, b) @@ -586,11 +417,32 @@ func (m *ExecuteTaskRequest) GetId() uint32 { return 0 } -func (m *ExecuteTaskRequest) GetTask() *TaskRequest { +func (m *ExecuteTaskRequest) GetConcurrency() uint32 { if m != nil { - return m.Task + return m.Concurrency } - return nil + return 0 +} + +func (m *ExecuteTaskRequest) GetRequests() uint32 { + if m != nil { + return m.Requests + } + return 0 +} + +func (m *ExecuteTaskRequest) GetRateLimit() uint32 { + if m != nil { + return m.RateLimit + } + return 0 +} + +func (m *ExecuteTaskRequest) GetData() string { + if m != nil { + return m.Data + } + return "" } // ExecuteTaskResponse for ExecuteTaskRequest, is used to report the results of this execution task. @@ -612,7 +464,7 @@ func (m *ExecuteTaskResponse) Reset() { *m = ExecuteTaskResponse{} } func (m *ExecuteTaskResponse) String() string { return proto.CompactTextString(m) } func (*ExecuteTaskResponse) ProtoMessage() {} func (*ExecuteTaskResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{4} + return fileDescriptor_squeeze_c8f7ad5b2d33e9bc, []int{4} } func (m *ExecuteTaskResponse) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_ExecuteTaskResponse.Unmarshal(m, b) @@ -660,280 +512,6 @@ func (m *ExecuteTaskResponse) GetData() string { return "" } -type WebsocketTask struct { - Scheme string `protobuf:"bytes,1,opt,name=scheme,proto3" json:"scheme,omitempty"` - Host string `protobuf:"bytes,2,opt,name=host,proto3" json:"host,omitempty"` - Path string `protobuf:"bytes,3,opt,name=path,proto3" json:"path,omitempty"` - Timeout uint32 `protobuf:"varint,4,opt,name=timeout,proto3" json:"timeout,omitempty"` - Body string `protobuf:"bytes,5,opt,name=body,proto3" json:"body,omitempty"` - MaxResults int32 `protobuf:"varint,6,opt,name=maxResults,proto3" json:"maxResults,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *WebsocketTask) Reset() { *m = WebsocketTask{} } -func (m *WebsocketTask) String() string { return proto.CompactTextString(m) } -func (*WebsocketTask) ProtoMessage() {} -func (*WebsocketTask) Descriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{5} -} -func (m *WebsocketTask) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_WebsocketTask.Unmarshal(m, b) -} -func (m *WebsocketTask) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_WebsocketTask.Marshal(b, m, deterministic) -} -func (dst *WebsocketTask) XXX_Merge(src proto.Message) { - xxx_messageInfo_WebsocketTask.Merge(dst, src) -} -func (m *WebsocketTask) XXX_Size() int { - return xxx_messageInfo_WebsocketTask.Size(m) -} -func (m *WebsocketTask) XXX_DiscardUnknown() { - xxx_messageInfo_WebsocketTask.DiscardUnknown(m) -} - -var xxx_messageInfo_WebsocketTask proto.InternalMessageInfo - -func (m *WebsocketTask) GetScheme() string { - if m != nil { - return m.Scheme - } - return "" -} - -func (m *WebsocketTask) GetHost() string { - if m != nil { - return m.Host - } - return "" -} - -func (m *WebsocketTask) GetPath() string { - if m != nil { - return m.Path - } - return "" -} - -func (m *WebsocketTask) GetTimeout() uint32 { - if m != nil { - return m.Timeout - } - return 0 -} - -func (m *WebsocketTask) GetBody() string { - if m != nil { - return m.Body - } - return "" -} - -func (m *WebsocketTask) GetMaxResults() int32 { - if m != nil { - return m.MaxResults - } - return 0 -} - -type UDPTask struct { - Addr string `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` - Timeout uint32 `protobuf:"varint,4,opt,name=timeout,proto3" json:"timeout,omitempty"` - MsgLength uint32 `protobuf:"varint,5,opt,name=msgLength,proto3" json:"msgLength,omitempty"` - MaxResults int32 `protobuf:"varint,6,opt,name=maxResults,proto3" json:"maxResults,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *UDPTask) Reset() { *m = UDPTask{} } -func (m *UDPTask) String() string { return proto.CompactTextString(m) } -func (*UDPTask) ProtoMessage() {} -func (*UDPTask) Descriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{6} -} -func (m *UDPTask) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_UDPTask.Unmarshal(m, b) -} -func (m *UDPTask) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_UDPTask.Marshal(b, m, deterministic) -} -func (dst *UDPTask) XXX_Merge(src proto.Message) { - xxx_messageInfo_UDPTask.Merge(dst, src) -} -func (m *UDPTask) XXX_Size() int { - return xxx_messageInfo_UDPTask.Size(m) -} -func (m *UDPTask) XXX_DiscardUnknown() { - xxx_messageInfo_UDPTask.DiscardUnknown(m) -} - -var xxx_messageInfo_UDPTask proto.InternalMessageInfo - -func (m *UDPTask) GetAddr() string { - if m != nil { - return m.Addr - } - return "" -} - -func (m *UDPTask) GetTimeout() uint32 { - if m != nil { - return m.Timeout - } - return 0 -} - -func (m *UDPTask) GetMsgLength() uint32 { - if m != nil { - return m.MsgLength - } - return 0 -} - -func (m *UDPTask) GetMaxResults() int32 { - if m != nil { - return m.MaxResults - } - return 0 -} - -type HttpTask struct { - Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"` - Method string `protobuf:"bytes,2,opt,name=method,proto3" json:"method,omitempty"` - Body string `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"` - Timeout uint32 `protobuf:"varint,7,opt,name=timeout,proto3" json:"timeout,omitempty"` - Http2 bool `protobuf:"varint,8,opt,name=http2,proto3" json:"http2,omitempty"` - DisableRedirects bool `protobuf:"varint,9,opt,name=disableRedirects,proto3" json:"disableRedirects,omitempty"` - DisableKeepalives bool `protobuf:"varint,10,opt,name=disableKeepalives,proto3" json:"disableKeepalives,omitempty"` - DisableCompression bool `protobuf:"varint,11,opt,name=disableCompression,proto3" json:"disableCompression,omitempty"` - ProxyAddr string `protobuf:"bytes,12,opt,name=proxyAddr,proto3" json:"proxyAddr,omitempty"` - MaxIdleConn uint32 `protobuf:"varint,13,opt,name=maxIdleConn,proto3" json:"maxIdleConn,omitempty"` - Headers []string `protobuf:"bytes,14,rep,name=headers,proto3" json:"headers,omitempty"` - ContentType string `protobuf:"bytes,15,opt,name=contentType,proto3" json:"contentType,omitempty"` - MaxResults int32 `protobuf:"varint,16,opt,name=maxResults,proto3" json:"maxResults,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *HttpTask) Reset() { *m = HttpTask{} } -func (m *HttpTask) String() string { return proto.CompactTextString(m) } -func (*HttpTask) ProtoMessage() {} -func (*HttpTask) Descriptor() ([]byte, []int) { - return fileDescriptor_squeeze_75a22bb21667af77, []int{7} -} -func (m *HttpTask) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_HttpTask.Unmarshal(m, b) -} -func (m *HttpTask) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_HttpTask.Marshal(b, m, deterministic) -} -func (dst *HttpTask) XXX_Merge(src proto.Message) { - xxx_messageInfo_HttpTask.Merge(dst, src) -} -func (m *HttpTask) XXX_Size() int { - return xxx_messageInfo_HttpTask.Size(m) -} -func (m *HttpTask) XXX_DiscardUnknown() { - xxx_messageInfo_HttpTask.DiscardUnknown(m) -} - -var xxx_messageInfo_HttpTask proto.InternalMessageInfo - -func (m *HttpTask) GetUrl() string { - if m != nil { - return m.Url - } - return "" -} - -func (m *HttpTask) GetMethod() string { - if m != nil { - return m.Method - } - return "" -} - -func (m *HttpTask) GetBody() string { - if m != nil { - return m.Body - } - return "" -} - -func (m *HttpTask) GetTimeout() uint32 { - if m != nil { - return m.Timeout - } - return 0 -} - -func (m *HttpTask) GetHttp2() bool { - if m != nil { - return m.Http2 - } - return false -} - -func (m *HttpTask) GetDisableRedirects() bool { - if m != nil { - return m.DisableRedirects - } - return false -} - -func (m *HttpTask) GetDisableKeepalives() bool { - if m != nil { - return m.DisableKeepalives - } - return false -} - -func (m *HttpTask) GetDisableCompression() bool { - if m != nil { - return m.DisableCompression - } - return false -} - -func (m *HttpTask) GetProxyAddr() string { - if m != nil { - return m.ProxyAddr - } - return "" -} - -func (m *HttpTask) GetMaxIdleConn() uint32 { - if m != nil { - return m.MaxIdleConn - } - return 0 -} - -func (m *HttpTask) GetHeaders() []string { - if m != nil { - return m.Headers - } - return nil -} - -func (m *HttpTask) GetContentType() string { - if m != nil { - return m.ContentType - } - return "" -} - -func (m *HttpTask) GetMaxResults() int32 { - if m != nil { - return m.MaxResults - } - return 0 -} - func init() { proto.RegisterType((*HeartBeatRequest)(nil), "pb.HeartBeatRequest") proto.RegisterType((*HeartBeatRequest_SlaveInfo)(nil), "pb.HeartBeatRequest.SlaveInfo") @@ -942,9 +520,6 @@ func init() { proto.RegisterType((*TaskRequest)(nil), "pb.TaskRequest") proto.RegisterType((*ExecuteTaskRequest)(nil), "pb.ExecuteTaskRequest") proto.RegisterType((*ExecuteTaskResponse)(nil), "pb.ExecuteTaskResponse") - proto.RegisterType((*WebsocketTask)(nil), "pb.WebsocketTask") - proto.RegisterType((*UDPTask)(nil), "pb.UDPTask") - proto.RegisterType((*HttpTask)(nil), "pb.HttpTask") proto.RegisterEnum("pb.Protocol", Protocol_name, Protocol_value) proto.RegisterEnum("pb.HeartBeatRequest_Task_Status", HeartBeatRequest_Task_Status_name, HeartBeatRequest_Task_Status_value) proto.RegisterEnum("pb.ExecuteTaskRequest_Command", ExecuteTaskRequest_Command_name, ExecuteTaskRequest_Command_value) @@ -1093,68 +668,47 @@ var _SqueezeService_serviceDesc = grpc.ServiceDesc{ Metadata: "squeeze.proto", } -func init() { proto.RegisterFile("squeeze.proto", fileDescriptor_squeeze_75a22bb21667af77) } - -var fileDescriptor_squeeze_75a22bb21667af77 = []byte{ - // 958 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x55, 0x5f, 0x6f, 0xe3, 0x44, - 0x10, 0xaf, 0xe3, 0xfc, 0xf3, 0xe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xe8, 0xfa, 0x6c, 0x57, 0x7b, 0xa7, 0xcd, 0xab, 0x72, 0x15, 0x7e, 0xf3, - 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc5, 0xdd, 0xd5, 0xb9, 0xcb, 0x07, 0x00, 0x00, +func init() { proto.RegisterFile("squeeze.proto", fileDescriptor_squeeze_c8f7ad5b2d33e9bc) } + +var fileDescriptor_squeeze_c8f7ad5b2d33e9bc = []byte{ + // 620 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x53, 0xef, 0x6e, 0xd3, 0x30, + 0x10, 0x5f, 0xd2, 0xf4, 0x4f, 0xae, 0xb4, 0x18, 0x33, 0x20, 0x54, 0xd3, 0xa8, 0x22, 0x21, 0x2a, + 0x24, 0xaa, 0xa9, 0x48, 0x08, 0xf1, 0x01, 0xb1, 0x75, 0xdd, 0x56, 0x6d, 0xa4, 0xc1, 0x49, 0x35, + 0xf1, 0xd1, 0x4d, 0x3c, 0x14, 0xad, 0x4d, 0x3a, 0x27, 0x9d, 0x18, 0x6f, 0x01, 0x6f, 0xc1, 0x9b, + 0xf0, 0x58, 0xc8, 0x76, 0x1a, 0x42, 0xb7, 0x7d, 0xbb, 0xfb, 0xdd, 0xef, 0x7c, 0x77, 0xbf, 0x3b, + 0x43, 0x2b, 0xbd, 0x5a, 0x31, 0xf6, 0x83, 0xf5, 0x97, 0x3c, 0xc9, 0x12, 0xac, 0x2f, 0x67, 0xf6, + 0x4f, 0x1d, 0xd0, 0x09, 0xa3, 0x3c, 0x3b, 0x60, 0x34, 0x23, 0xec, 0x6a, 0xc5, 0xd2, 0x0c, 0xbf, + 0x01, 0x23, 0xa3, 0xe9, 0xa5, 0xa5, 0x75, 0xb5, 0x5e, 0x73, 0xf0, 0xbc, 0xbf, 0x9c, 0xf5, 0x37, + 0x39, 0x7d, 0x9f, 0xa6, 0x97, 0x44, 0xd2, 0xf0, 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 0x3d, 0x74, 0x51, 0x45, 0x4c, 0x4d, 0x46, 0x87, 0x63, 0x0f, 0x19, + 0xc2, 0xfc, 0xfc, 0xd5, 0xfb, 0x72, 0x86, 0xaa, 0xd2, 0x9c, 0x38, 0xc7, 0x13, 0x54, 0x13, 0xc9, + 0xc7, 0xc4, 0x1d, 0xa2, 0x3a, 0x06, 0xa8, 0xf9, 0x27, 0x64, 0x7c, 0xe4, 0xa3, 0x06, 0x6e, 0x81, + 0x79, 0x3e, 0x3a, 0xf0, 0x26, 0xc3, 0xd3, 0x91, 0x8f, 0xcc, 0xc1, 0x2f, 0x0d, 0xda, 0x9e, 0xfa, + 0xe6, 0x1e, 0xe3, 0xd7, 0x51, 0xc0, 0xf0, 0x27, 0x68, 0x96, 0x66, 0xc7, 0x4f, 0xef, 0xbe, 0xb7, + 0xce, 0xb3, 0x7b, 0x44, 0xb2, 0xb7, 0xf0, 0x47, 0x30, 0x8b, 0x1f, 0x81, 0xb7, 0xef, 0xfa, 0x69, + 0x9d, 0x27, 0x1b, 0xe8, 0x3a, 0xb7, 0xa7, 0xed, 0x69, 0xb3, 0x9a, 0xbc, 0xce, 0xb7, 0x7f, 0x03, + 0x00, 0x00, 0xff, 0xff, 0x2e, 0x14, 0x00, 0x29, 0x81, 0x04, 0x00, 0x00, } diff --git a/pkg/pb/squeeze.proto b/pkg/pb/squeeze.proto index 360edd6..358384b 100644 --- a/pkg/pb/squeeze.proto +++ b/pkg/pb/squeeze.proto @@ -49,14 +49,7 @@ message HeartBeatResponse { } message TaskRequest { - uint32 concurrency = 1; - uint32 requests = 2; - uint32 rateLimit = 3; - oneof type { - HttpTask http = 4; - WebsocketTask websocket = 5; - UDPTask udp = 6; - } + } // ExecuteTaskRequest describes the task information to be executed. @@ -70,7 +63,10 @@ message ExecuteTaskRequest { string callback = 3; uint32 duration = 4; uint32 id = 5; - TaskRequest task = 6; + uint32 concurrency = 6; + uint32 requests = 7; + uint32 rateLimit = 8; + string data = 9; } // ExecuteTaskResponse for ExecuteTaskRequest, is used to report the results of this execution task. @@ -101,36 +97,4 @@ enum Protocol { GRPC = 7; THRIFT = 8; WEBSOCKET = 9; -} - -message WebsocketTask { - string scheme = 1; - string host = 2; - string path = 3; - uint32 timeout = 4; - string body = 5; - int32 maxResults = 6; -} - -message UDPTask { - string addr = 1; - uint32 timeout = 4; - uint32 msgLength = 5; - int32 maxResults = 6; -} - -message HttpTask { - string url = 1; - string method = 2; - string body = 3; - uint32 timeout = 7; - bool http2 = 8; - bool disableRedirects = 9; - bool disableKeepalives = 10; - bool disableCompression = 11; - string proxyAddr = 12; - uint32 maxIdleConn = 13; - repeated string headers = 14; - string contentType = 15; - int32 maxResults = 16; } \ No newline at end of file diff --git a/pkg/proto/common.go b/pkg/proto/common.go index 3178e6a..c00fb68 100644 --- a/pkg/proto/common.go +++ b/pkg/proto/common.go @@ -45,9 +45,9 @@ type SqueezeResult struct { type ProtoBuilder interface { // slave side // These functions are executed in the following order - Init(context.Context, *pb.TaskRequest) error - PreRequest(*pb.TaskRequest) (interface{}, interface{}) - Request(context.Context, interface{}, *pb.TaskRequest) interface{} + Init(context.Context, *pb.ExecuteTaskRequest) error + PreRequest(*pb.ExecuteTaskRequest) (interface{}, interface{}) + Request(context.Context, interface{}, *pb.ExecuteTaskRequest) interface{} PostRequest(interface{}) error Done(time.Duration) (interface{}, error) diff --git a/pkg/proto/http/http.go b/pkg/proto/http/http.go index 3372e21..b7c8f89 100644 --- a/pkg/proto/http/http.go +++ b/pkg/proto/http/http.go @@ -28,6 +28,7 @@ import ( "encoding/json" "net/http/httptrace" "golang.org/x/net/http2" + log "github.com/golang/glog" "github.com/agile6v/squeeze/pkg/config" "github.com/agile6v/squeeze/pkg/pb" "github.com/agile6v/squeeze/pkg/util" @@ -146,6 +147,7 @@ type HttpBuilder struct { report *httpReport HttpReq *http.Request HttpClient *http.Client + options *config.HttpOptions } func NewBuilder() *HttpBuilder { @@ -162,32 +164,22 @@ func (builder *HttpBuilder) CreateTask(configArgs *config.ProtoConfigArgs) (stri httpOptions.Requests = math.MaxInt32 } + data, err := json.Marshal(httpOptions) + if err != nil { + log.Errorf("could not marshal message : %v", err) + return "", err + } + req := &pb.ExecuteTaskRequest{ Id: uint32(configArgs.ID), Cmd: pb.ExecuteTaskRequest_START, Protocol: pb.Protocol_HTTP, Callback: configArgs.Callback, Duration: uint32(httpOptions.Duration), - Task: &pb.TaskRequest{ - Requests: uint32(httpOptions.Requests), - Concurrency: uint32(httpOptions.Concurrency), - RateLimit: uint32(httpOptions.RateLimit), - Type: &pb.TaskRequest_Http{ - Http: &pb.HttpTask{ - Url: httpOptions.URL, - Http2: httpOptions.HTTP2, - Method: httpOptions.Method, - Body: httpOptions.Body, - Timeout: uint32(httpOptions.Timeout), - DisableKeepalives: httpOptions.DisableKeepAlive, - DisableCompression:httpOptions.DisableCompression, - Headers: httpOptions.Headers, - ProxyAddr: httpOptions.ProxyAddr, - ContentType: httpOptions.ContentType, - MaxResults: int32(httpOptions.MaxResults), - }, - }, - }, + Requests: uint32(httpOptions.Requests), + Concurrency: uint32(httpOptions.Concurrency), + RateLimit: uint32(httpOptions.RateLimit), + Data: string(data), } m := jsonpb.Marshaler{} @@ -207,32 +199,24 @@ func (builder *HttpBuilder) CreateTask(configArgs *config.ProtoConfigArgs) (stri func (builder *HttpBuilder) Split(request *pb.ExecuteTaskRequest, count int) []*pb.ExecuteTaskRequest { var requests []*pb.ExecuteTaskRequest - if count > int(request.Task.Concurrency) { - count = int(request.Task.Concurrency) - } else if count > int(request.Task.Requests) { - count = int(request.Task.Requests) + if count > int(request.Concurrency) { + count = int(request.Concurrency) + } else if count > int(request.Requests) { + count = int(request.Requests) } for i := 1; i <= count; i++ { req := new(pb.ExecuteTaskRequest) *req = *request - task := new(pb.HttpTask) - *task = *request.Task.GetHttp() - - req.Task = &pb.TaskRequest{ - Type: &pb.TaskRequest_Http{ - Http: task, - }, - } if count != i { - req.Task.Requests = request.Task.Requests / uint32(count) - req.Task.RateLimit = request.Task.RateLimit / uint32(count) - req.Task.Concurrency = request.Task.Concurrency / uint32(count) + req.Requests = request.Requests / uint32(count) + req.RateLimit = request.RateLimit / uint32(count) + req.Concurrency = request.Concurrency / uint32(count) } else { - req.Task.Requests = request.Task.Requests/uint32(count) + request.Task.Requests%uint32(count) - req.Task.RateLimit = request.Task.RateLimit/uint32(count) + request.Task.RateLimit%uint32(count) - req.Task.Concurrency = request.Task.Concurrency/uint32(count) + request.Task.Concurrency%uint32(count) + req.Requests = request.Requests/uint32(count) + request.Requests%uint32(count) + req.RateLimit = request.RateLimit/uint32(count) + request.RateLimit%uint32(count) + req.Concurrency = request.Concurrency/uint32(count) + request.Concurrency%uint32(count) } requests = append(requests, req) @@ -241,19 +225,25 @@ func (builder *HttpBuilder) Split(request *pb.ExecuteTaskRequest, count int) []* return requests } -func (builder *HttpBuilder) Init(ctx context.Context, taskReq *pb.TaskRequest) error { - task := taskReq.GetHttp() +func (builder *HttpBuilder) Init(ctx context.Context, taskReq *pb.ExecuteTaskRequest) error { + var options config.HttpOptions + err := json.Unmarshal([]byte(taskReq.Data), &options) + if err != nil { + return err + } + + builder.options = &options - builder.report = newHttpReport(util.Min(int(taskReq.Requests), int(task.MaxResults))) - httpReq, err := http.NewRequest(task.Method, task.Url, nil) + builder.report = newHttpReport(util.Min(int(taskReq.Requests), int(options.MaxResults))) + httpReq, err := http.NewRequest(options.Method, options.URL, nil) if err != nil { return err } // copy headers header := make(http.Header) - if len(task.Headers) > 0 { - for _, h := range task.Headers { + if len(options.Headers) > 0 { + for _, h := range options.Headers { matched, err := util.ParseHTTPHeader(h) if err != nil { return fmt.Errorf("HTTP Header format is invalid, %v", err) @@ -273,10 +263,10 @@ func (builder *HttpBuilder) Init(ctx context.Context, taskReq *pb.TaskRequest) e header.Set("User-Agent", ua) // content-type - header.Set("Content-Type", task.ContentType) + header.Set("Content-Type", options.ContentType) - if len(taskReq.GetHttp().Body) > 0 { - httpReq.ContentLength = int64(len(taskReq.GetHttp().Body)) + if len(options.Body) > 0 { + httpReq.ContentLength = int64(len(options.Body)) } tr := &http.Transport{ @@ -285,26 +275,26 @@ func (builder *HttpBuilder) Init(ctx context.Context, taskReq *pb.TaskRequest) e ServerName: httpReq.Host, }, MaxIdleConnsPerHost: int(taskReq.Concurrency), - DisableCompression: task.DisableCompression, - DisableKeepAlives: task.DisableKeepalives, + DisableCompression: options.DisableCompression, + DisableKeepAlives: options.DisableKeepAlive, } - if task.ProxyAddr != "" { - proxyURL, err := url.Parse(task.ProxyAddr) + if options.ProxyAddr != "" { + proxyURL, err := url.Parse(options.ProxyAddr) if err != nil { - return fmt.Errorf("invalid argument %s: %s", task.ProxyAddr, err.Error()) + return fmt.Errorf("invalid argument %s: %s", options.ProxyAddr, err.Error()) } tr.Proxy = http.ProxyURL(proxyURL) } - if task.Http2 { + if options.HTTP2 { http2.ConfigureTransport(tr) } else { tr.TLSNextProto = make(map[string]func(string, *tls.Conn) http.RoundTripper) } - client := &http.Client{Transport: tr, Timeout: time.Duration(task.Timeout) * time.Second} + client := &http.Client{Transport: tr, Timeout: time.Duration(options.Timeout) * time.Second} - if task.DisableRedirects { + if options.DisableRedirects { client.CheckRedirect = func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse } @@ -315,17 +305,17 @@ func (builder *HttpBuilder) Init(ctx context.Context, taskReq *pb.TaskRequest) e return nil } -func (builder *HttpBuilder) PreRequest(taskReq *pb.TaskRequest) (interface{}, interface{}) { +func (builder *HttpBuilder) PreRequest(taskReq *pb.ExecuteTaskRequest) (interface{}, interface{}) { return nil, nil } -func (builder *HttpBuilder) Request(ctx context.Context, obj interface{}, taskReq *pb.TaskRequest) interface{} { +func (builder *HttpBuilder) Request(ctx context.Context, obj interface{}, taskReq *pb.ExecuteTaskRequest) interface{} { s := util.Now() var size int64 var code int var dnsStart, connStart, resStart, reqStart, delayStart time.Duration var dnsDuration, connDuration, resDuration, reqDuration, delayDuration time.Duration - req := util.CloneRequest(builder.HttpReq, []byte(taskReq.GetHttp().Body)) + req := util.CloneRequest(builder.HttpReq, []byte(builder.options.Body)) trace := &httptrace.ClientTrace{ DNSStart: func(info httptrace.DNSStartInfo) { dnsStart = util.Now() diff --git a/pkg/proto/udp/udp.go b/pkg/proto/udp/udp.go index f328536..4860712 100644 --- a/pkg/proto/udp/udp.go +++ b/pkg/proto/udp/udp.go @@ -20,6 +20,7 @@ import ( "net" "context" "encoding/json" + log "github.com/golang/glog" "github.com/gorilla/websocket" "github.com/golang/protobuf/jsonpb" "github.com/agile6v/squeeze/pkg/config" @@ -63,8 +64,9 @@ func newUDPReport(n int) *udpReport { } type UDPBuilder struct { - Conn *websocket.Conn - report *udpReport + Conn *websocket.Conn + report *udpReport + options *config.UDPOptions } func NewBuilder() *UDPBuilder { @@ -77,23 +79,22 @@ func (builder *UDPBuilder) CreateTask(configArgs *config.ProtoConfigArgs) (strin return "", fmt.Errorf("Expected udpOptions type, but got %T", configArgs.Options) } + data, err := json.Marshal(udpOptions) + if err != nil { + log.Errorf("could not marshal message : %v", err) + return "", err + } + req := &pb.ExecuteTaskRequest{ Id: uint32(configArgs.ID), Cmd: pb.ExecuteTaskRequest_START, Protocol: pb.Protocol_UDP, Callback: configArgs.Callback, Duration: uint32(udpOptions.Duration), - Task: &pb.TaskRequest{ - Requests: uint32(udpOptions.Requests), - Concurrency: uint32(udpOptions.Concurrency), - Type: &pb.TaskRequest_Udp{ - Udp: &pb.UDPTask{ - Timeout: uint32(udpOptions.Timeout), - MsgLength: uint32(udpOptions.MsgLength), - Addr: udpOptions.Addr, - }, - }, - }, + Requests: uint32(udpOptions.Requests), + Concurrency: uint32(udpOptions.Concurrency), + //RateLimit: + Data: string(data), } m := jsonpb.Marshaler{} @@ -110,52 +111,49 @@ func (builder *UDPBuilder) CreateTask(configArgs *config.ProtoConfigArgs) (strin } func (builder *UDPBuilder) Split(request *pb.ExecuteTaskRequest, count int) []*pb.ExecuteTaskRequest { - var taskRequests []*pb.ExecuteTaskRequest + var requests []*pb.ExecuteTaskRequest - if count > int(request.Task.Concurrency) { - count = int(request.Task.Concurrency) - } else if count > int(request.Task.Requests) { - count = int(request.Task.Requests) + if count > int(request.Concurrency) { + count = int(request.Concurrency) + } else if count > int(request.Requests) { + count = int(request.Requests) } for i := 1; i <= count; i++ { req := new(pb.ExecuteTaskRequest) *req = *request - task := new(pb.UDPTask) - *task = *req.Task.GetUdp() - var requests, concurrency uint32 if count != i { - requests = req.Task.Requests / uint32(count) - concurrency = req.Task.Concurrency / uint32(count) + req.Requests = request.Requests / uint32(count) + req.RateLimit = request.RateLimit / uint32(count) + req.Concurrency = request.Concurrency / uint32(count) } else { - requests = req.Task.Requests/uint32(count) + req.Task.Requests%uint32(count) - concurrency = req.Task.Concurrency/uint32(count) + req.Task.Concurrency%uint32(count) + req.Requests = request.Requests/uint32(count) + request.Requests%uint32(count) + req.RateLimit = request.RateLimit/uint32(count) + request.RateLimit%uint32(count) + req.Concurrency = request.Concurrency/uint32(count) + request.Concurrency%uint32(count) } - req.Task = &pb.TaskRequest{ - Requests: requests, - Concurrency: concurrency, - Type: &pb.TaskRequest_Udp{ - Udp: task, - }, - } - - taskRequests = append(taskRequests, req) + requests = append(requests, req) } - return taskRequests + return requests } -func (builder *UDPBuilder) Init(ctx context.Context, taskReq *pb.TaskRequest) error { +func (builder *UDPBuilder) Init(ctx context.Context, taskReq *pb.ExecuteTaskRequest) error { + var options config.UDPOptions + err := json.Unmarshal([]byte(taskReq.Data), &options) + if err != nil { + return err + } + + builder.options = &options return nil } -func (builder *UDPBuilder) PreRequest(taskReq *pb.TaskRequest) (interface{}, interface{}) { - task := taskReq.GetUdp() - builder.report = newUDPReport(util.Min(int(taskReq.Requests), int(task.MaxResults))) +func (builder *UDPBuilder) PreRequest(taskReq *pb.ExecuteTaskRequest) (interface{}, interface{}) { + builder.report = newUDPReport(util.Min(int(taskReq.Requests), int(builder.options.MaxResults))) - addr, err := net.ResolveUDPAddr("udp", task.Addr) + addr, err := net.ResolveUDPAddr("udp", builder.options.Addr) if err != nil { return nil, &udpResult{Err: err} } @@ -170,11 +168,11 @@ func (builder *UDPBuilder) PreRequest(taskReq *pb.TaskRequest) (interface{}, int return conn, nil } -func (builder *UDPBuilder) Request(ctx context.Context, obj interface{}, taskReq *pb.TaskRequest) interface{} { +func (builder *UDPBuilder) Request(ctx context.Context, obj interface{}, taskReq *pb.ExecuteTaskRequest) interface{} { s := util.Now() conn, _ := obj.(*net.UDPConn) - content := make([]byte, taskReq.GetUdp().MsgLength) + content := make([]byte, builder.options.MsgLength) _, err := conn.Write(content) if err != nil { diff --git a/pkg/proto/websocket/websocket.go b/pkg/proto/websocket/websocket.go index 2921b1e..4ae9515 100644 --- a/pkg/proto/websocket/websocket.go +++ b/pkg/proto/websocket/websocket.go @@ -64,8 +64,9 @@ func newWsReport(n int) *wsReport { } type WebSocketBuilder struct { - Conn *websocket.Conn - report *wsReport + Conn *websocket.Conn + report *wsReport + options *config.WsOptions } func NewBuilder() *WebSocketBuilder { @@ -78,25 +79,22 @@ func (builder *WebSocketBuilder) CreateTask(configArgs *config.ProtoConfigArgs) return "", fmt.Errorf("Expected WsOptions type, but got %T", configArgs.Options) } + data, err := json.Marshal(wsOptions) + if err != nil { + log.Errorf("could not marshal message : %v", err) + return "", err + } + req := &pb.ExecuteTaskRequest{ Id: uint32(configArgs.ID), Cmd: pb.ExecuteTaskRequest_START, Protocol: pb.Protocol_WEBSOCKET, Callback: configArgs.Callback, Duration: uint32(wsOptions.Duration), - Task: &pb.TaskRequest{ - Requests: uint32(wsOptions.Requests), - Concurrency: uint32(wsOptions.Concurrency), - Type: &pb.TaskRequest_Websocket{ - Websocket: &pb.WebsocketTask{ - Scheme: wsOptions.Scheme, - Host: wsOptions.Host, - Path: wsOptions.Path, - Body: wsOptions.Body, - Timeout: uint32(wsOptions.Timeout), - }, - }, - }, + Requests: uint32(wsOptions.Requests), + Concurrency: uint32(wsOptions.Concurrency), + //RateLimit: + Data: string(data), } m := jsonpb.Marshaler{} @@ -113,55 +111,52 @@ func (builder *WebSocketBuilder) CreateTask(configArgs *config.ProtoConfigArgs) } func (builder *WebSocketBuilder) Split(request *pb.ExecuteTaskRequest, count int) []*pb.ExecuteTaskRequest { - var taskRequests []*pb.ExecuteTaskRequest + var requests []*pb.ExecuteTaskRequest - if count > int(request.Task.Concurrency) { - count = int(request.Task.Concurrency) - } else if count > int(request.Task.Requests) { - count = int(request.Task.Requests) + if count > int(request.Concurrency) { + count = int(request.Concurrency) + } else if count > int(request.Requests) { + count = int(request.Requests) } for i := 1; i <= count; i++ { req := new(pb.ExecuteTaskRequest) *req = *request - task := new(pb.WebsocketTask) - *task = *req.Task.GetWebsocket() - var requests, concurrency uint32 if count != i { - requests = req.Task.Requests / uint32(count) - concurrency = req.Task.Concurrency / uint32(count) + req.Requests = request.Requests / uint32(count) + req.RateLimit = request.RateLimit / uint32(count) + req.Concurrency = request.Concurrency / uint32(count) } else { - requests = req.Task.Requests/uint32(count) + req.Task.Requests%uint32(count) - concurrency = req.Task.Concurrency/uint32(count) + req.Task.Concurrency%uint32(count) + req.Requests = request.Requests/uint32(count) + request.Requests%uint32(count) + req.RateLimit = request.RateLimit/uint32(count) + request.RateLimit%uint32(count) + req.Concurrency = request.Concurrency/uint32(count) + request.Concurrency%uint32(count) } - req.Task = &pb.TaskRequest{ - Requests: requests, - Concurrency: concurrency, - Type: &pb.TaskRequest_Websocket{ - Websocket: task, - }, - } - - taskRequests = append(taskRequests, req) + requests = append(requests, req) } - return taskRequests + return requests } -func (builder *WebSocketBuilder) Init(ctx context.Context, taskReq *pb.TaskRequest) error { +func (builder *WebSocketBuilder) Init(ctx context.Context, taskReq *pb.ExecuteTaskRequest) error { + var options config.WsOptions + err := json.Unmarshal([]byte(taskReq.Data), &options) + if err != nil { + return err + } + + builder.options = &options return nil } -func (builder *WebSocketBuilder) PreRequest(taskReq *pb.TaskRequest) (interface{}, interface{}) { - task := taskReq.GetWebsocket() - builder.report = newWsReport(util.Min(int(taskReq.Requests), int(task.MaxResults))) +func (builder *WebSocketBuilder) PreRequest(taskReq *pb.ExecuteTaskRequest) (interface{}, interface{}) { + builder.report = newWsReport(util.Min(int(taskReq.Requests), int(builder.options.MaxResults))) dialer := websocket.Dialer{ - HandshakeTimeout: time.Duration(task.Timeout) * time.Second, + HandshakeTimeout: time.Duration(builder.options.Timeout) * time.Second, } - u := url.URL{Scheme: task.Scheme, Host: task.Host, Path: task.Path} + u := url.URL{Scheme: builder.options.Scheme, Host: builder.options.Host, Path: builder.options.Path} conn, _, err := dialer.Dial(u.String(), nil) if err != nil { return nil, &wsResult{Err: err} @@ -170,12 +165,12 @@ func (builder *WebSocketBuilder) PreRequest(taskReq *pb.TaskRequest) (interface{ return conn, nil } -func (builder *WebSocketBuilder) Request(ctx context.Context, obj interface{}, taskReq *pb.TaskRequest) interface{} { +func (builder *WebSocketBuilder) Request(ctx context.Context, obj interface{}, taskReq *pb.ExecuteTaskRequest) interface{} { s := util.Now() conn, _ := obj.(*websocket.Conn) var resp []byte - err := conn.WriteMessage(websocket.TextMessage, []byte(taskReq.GetWebsocket().Body)) + err := conn.WriteMessage(websocket.TextMessage, []byte(builder.options.Body)) if err == nil { // Since our goal is to press server-side capabilities, so we only // consider synchronization scenario. If needed, we will support diff --git a/pkg/server/slave_server.go b/pkg/server/slave_server.go index f52669f..75a5daf 100644 --- a/pkg/server/slave_server.go +++ b/pkg/server/slave_server.go @@ -89,7 +89,7 @@ func (s *SlaveServer) HeartBeat(stream pb.SqueezeService_HeartBeatServer) error func (s *SlaveServer) ExecuteTask(ctx context.Context, req *pb.ExecuteTaskRequest) (*pb.ExecuteTaskResponse, error) { log.V(2).Infof("Execute Task ... %s: %v", - pb.ExecuteTaskRequest_Command_name[int32(req.Cmd)], req.Task) + pb.ExecuteTaskRequest_Command_name[int32(req.Cmd)], req) if req.Cmd == pb.ExecuteTaskRequest_STOP { if s.work != nil { @@ -99,7 +99,7 @@ func (s *SlaveServer) ExecuteTask(ctx context.Context, req *pb.ExecuteTaskReques return &pb.ExecuteTaskResponse{Status: pb.ExecuteTaskResponse_SUCC}, nil } - if req.Task.Concurrency < 1 { + if req.Concurrency < 1 { return &pb.ExecuteTaskResponse{Status: pb.ExecuteTaskResponse_FAIL, Error: fmt.Sprintf("Concurrency is invalid")}, nil } @@ -107,10 +107,10 @@ func (s *SlaveServer) ExecuteTask(ctx context.Context, req *pb.ExecuteTaskReques s.work = &Work{ Req: req, Builder: builder.NewBuilder(req.Protocol), - Requests: int(req.Task.Requests), - Workers: int(req.Task.Concurrency), + Requests: int(req.Requests), + Workers: int(req.Concurrency), ResultCapacity: s.args.ResultCapacity, - RateLimit: float64(req.Task.RateLimit), + RateLimit: float64(req.RateLimit), } if req.Duration > 0 { diff --git a/pkg/server/work.go b/pkg/server/work.go index b410cde..91cd3e5 100644 --- a/pkg/server/work.go +++ b/pkg/server/work.go @@ -58,7 +58,7 @@ type Work struct { // all work is done or receive cancel signal. func (w *Work) Run(ctx context.Context) (time.Duration, error) { // Initialization before calling the request handler - err := w.Builder.Init(ctx, w.Req.Task) + err := w.Builder.Init(ctx, w.Req) if err != nil { log.Infof("failed to execute Init: %s", err.Error()) return 0, err @@ -103,7 +103,7 @@ func (w *Work) runWorker(ctx context.Context, n int) { throttle = time.Tick(time.Duration(1e6/(w.RateLimit)) * time.Microsecond) } - obj, result := w.Builder.PreRequest(w.Req.Task) + obj, result := w.Builder.PreRequest(w.Req) if result != nil { w.results <- result return @@ -119,7 +119,7 @@ func (w *Work) runWorker(ctx context.Context, n int) { } // Initiate a request - ret := w.Builder.Request(ctx, obj, w.Req.Task) + ret := w.Builder.Request(ctx, obj, w.Req) // The result of the request will be sent to collector goroutine for summary w.results <- ret