Documentation ¶
Overview ¶
Package golo is a framework for running and writing distributed loadtests with go.
It does this by wrapping a special function, with the signature:
func(*golo.Context, *golo.Response) (*golo.Response, error)
This function can then perform whatever tests it needs, returning loadtest run data which is then used to report and chart on test runs.
A simple go-lo loadtest binary could be as simple as:
package main import ( "net/http" "github.com/go-lo/go-lo" ) var ( url = "https://example.com" ) func Trigger(c *golo.Context, r *golo.Response) (*golo.Response, error) { resp, err := http.Get(url) if err != nil { r.Error = true r.Output = err.Error() } // Set the Job ID for this run r.Id = golo.NewSequenceID() // Add some tags r.Tags = golo.Tagify(map[string]interface{}{ "status": resp.Status, "size": resp.ContentLength, "url": url, }) return r, nil } func main() { loadtest, err := golo.New(Trigger) if err != nil { panic(err) } err = loadtest.Start() if err != nil { panic(err) } }
This loadtest can be uplaoded to a go-lo agent, with a schedule, and you should see results.
Index ¶
- Constants
- func NewSequenceID() string
- func RegisterJobServer(s *grpc.Server, srv JobServer)
- type Context
- func (*Context) Descriptor() ([]byte, []int)
- func (m *Context) GetJobName() string
- func (*Context) ProtoMessage()
- func (m *Context) Reset()
- func (m *Context) String() string
- func (m *Context) XXX_DiscardUnknown()
- func (m *Context) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Context) XXX_Merge(src proto.Message)
- func (m *Context) XXX_Size() int
- func (m *Context) XXX_Unmarshal(b []byte) error
- type JobClient
- type JobServer
- type Loadtest
- type Response
- func (*Response) Descriptor() ([]byte, []int)
- func (m *Response) GetDuration() uint64
- func (m *Response) GetError() bool
- func (m *Response) GetId() string
- func (m *Response) GetJobName() string
- func (m *Response) GetOutput() string
- func (m *Response) GetTags() []*ResponseTag
- func (*Response) ProtoMessage()
- func (m *Response) Reset()
- func (m *Response) String() string
- func (m *Response) XXX_DiscardUnknown()
- func (m *Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Response) XXX_Merge(src proto.Message)
- func (m *Response) XXX_Size() int
- func (m *Response) XXX_Unmarshal(b []byte) error
- type ResponseTag
- func (*ResponseTag) Descriptor() ([]byte, []int)
- func (m *ResponseTag) GetKey() string
- func (m *ResponseTag) GetValue() string
- func (*ResponseTag) ProtoMessage()
- func (m *ResponseTag) Reset()
- func (m *ResponseTag) String() string
- func (m *ResponseTag) XXX_DiscardUnknown()
- func (m *ResponseTag) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *ResponseTag) XXX_Merge(src proto.Message)
- func (m *ResponseTag) XXX_Size() int
- func (m *ResponseTag) XXX_Unmarshal(b []byte) error
- type TriggerFunc
- type UnimplementedJobServer
Constants ¶
const ( // DefaultSequenceID is a uuid which will be returned should uuid.NewV4 // fail. It can be safely compared with whatever is returned from // loadtest.SequenceID()- this uuid is a v5 uuid in the DNS namespace // whereas SequenceID() returns a v4 uuid. // see script/make_uuid.go in source repo for more information. DefaultSequenceID = "c276c8c7-6fec-5aa9-b6bd-4de12a49a9bb" )
const ( // RPCAddr is the default host on which a schedule listens // and an agent connects to RPCAddr = "127.0.0.1:9999" )
Variables ¶
This section is empty.
Functions ¶
func NewSequenceID ¶
func NewSequenceID() string
NewSequenceID will return a fresh v4 uuid for sequences of requests to use, to allow for ease of grouping journeys together. This function swallows errors; should an error occur then this will, instead, return loadtest.DefaultSequenceID. Thus: a usable ID can always be guaranteed from this function
func RegisterJobServer ¶
Types ¶
type Context ¶
type Context struct { JobName string `protobuf:"bytes,1,opt,name=jobName,proto3" json:"jobName,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Context) Descriptor ¶
func (*Context) GetJobName ¶
func (*Context) ProtoMessage ¶
func (*Context) ProtoMessage()
func (*Context) XXX_DiscardUnknown ¶
func (m *Context) XXX_DiscardUnknown()
func (*Context) XXX_Marshal ¶
func (*Context) XXX_Unmarshal ¶
type JobClient ¶
type JobClient interface {
Trigger(ctx context.Context, in *Context, opts ...grpc.CallOption) (*Response, error)
}
JobClient is the client API for Job service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
func NewJobClient ¶
func NewJobClient(cc *grpc.ClientConn) JobClient
type Loadtest ¶
type Loadtest struct {
// contains filtered or unexported fields
}
Loadtest holds configuration and gRPC contexts which Loadtests must be wrapped in
func New ¶
func New(f TriggerFunc) (l Loadtest, err error)
New takes scheduler code which implements the Runner interface and returns a Server. It also runs some bootstrap tasks to ensure a server has various things set that it ought to, like a clock and an HTTPClient
type Response ¶
type Response struct { Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` JobName string `protobuf:"bytes,2,opt,name=jobName,proto3" json:"jobName,omitempty"` Error bool `protobuf:"varint,3,opt,name=error,proto3" json:"error,omitempty"` Duration uint64 `protobuf:"varint,4,opt,name=duration,proto3" json:"duration,omitempty"` Output string `protobuf:"bytes,5,opt,name=output,proto3" json:"output,omitempty"` Tags []*ResponseTag `protobuf:"bytes,6,rep,name=tags,proto3" json:"tags,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func (*Response) Descriptor ¶
func (*Response) GetDuration ¶
func (*Response) GetJobName ¶
func (*Response) GetTags ¶
func (m *Response) GetTags() []*ResponseTag
func (*Response) ProtoMessage ¶
func (*Response) ProtoMessage()
func (*Response) XXX_DiscardUnknown ¶
func (m *Response) XXX_DiscardUnknown()
func (*Response) XXX_Marshal ¶
func (*Response) XXX_Unmarshal ¶
type ResponseTag ¶
type ResponseTag struct { Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` }
func Tagify ¶
func Tagify(m map[string]interface{}) (tags []*ResponseTag)
Tagify takes a map of strings to interfaces, and turns it into tags which can be used in Responses
func (*ResponseTag) Descriptor ¶
func (*ResponseTag) Descriptor() ([]byte, []int)
func (*ResponseTag) GetKey ¶
func (m *ResponseTag) GetKey() string
func (*ResponseTag) GetValue ¶
func (m *ResponseTag) GetValue() string
func (*ResponseTag) ProtoMessage ¶
func (*ResponseTag) ProtoMessage()
func (*ResponseTag) Reset ¶
func (m *ResponseTag) Reset()
func (*ResponseTag) String ¶
func (m *ResponseTag) String() string
func (*ResponseTag) XXX_DiscardUnknown ¶
func (m *ResponseTag) XXX_DiscardUnknown()
func (*ResponseTag) XXX_Marshal ¶
func (m *ResponseTag) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*ResponseTag) XXX_Merge ¶
func (m *ResponseTag) XXX_Merge(src proto.Message)
func (*ResponseTag) XXX_Size ¶
func (m *ResponseTag) XXX_Size() int
func (*ResponseTag) XXX_Unmarshal ¶
func (m *ResponseTag) XXX_Unmarshal(b []byte) error
type TriggerFunc ¶
TriggerFunc is a function which a loadtest calls. All loadtests have to do is implement this function in a go application.
type UnimplementedJobServer ¶
type UnimplementedJobServer struct { }
UnimplementedJobServer can be embedded to have forward compatible implementations.