golo

package module
v0.0.0-...-0c6ade2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2020 License: GPL-3.0 Imports: 10 Imported by: 2

README

Go Report Card Build Status GoDoc

golo

import "github.com/go-lo/go-lo"

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 = "<a href="https://example.com">https://example.com</a>"
)

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

Package files

doc.go go-lo.pb.go interface.go sequences.go tags.go

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"
)

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

func RegisterJobServer(s *grpc.Server, srv JobServer)

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) Descriptor() ([]byte, []int)
func (*Context) GetJobName
func (m *Context) GetJobName() string
func (*Context) ProtoMessage
func (*Context) ProtoMessage()
func (*Context) Reset
func (m *Context) Reset()
func (*Context) String
func (m *Context) String() string
func (*Context) XXX_DiscardUnknown
func (m *Context) XXX_DiscardUnknown()
func (*Context) XXX_Marshal
func (m *Context) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*Context) XXX_Merge
func (m *Context) XXX_Merge(src proto.Message)
func (*Context) XXX_Size
func (m *Context) XXX_Size() int
func (*Context) XXX_Unmarshal
func (m *Context) XXX_Unmarshal(b []byte) error

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 JobServer

type JobServer interface {
    Trigger(context.Context, *Context) (*Response, error)
}

JobServer is the server API for Job service.

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

func (Loadtest) Start
func (l Loadtest) Start() (err error)

Start will start an RPC server on loadtest.RPCAddr and register Server ahead of Agents scheduling jobs

func (Loadtest) Trigger
func (l Loadtest) Trigger(ctx context.Context, c *Context) (r *Response, err error)

Trigger creates contexts/ outputs, and passes them to (Loadtest).trigger() to run a test

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"`
    Output               string         `protobuf:"bytes,4,opt,name=output,proto3" json:"output,omitempty"`
    Tags                 []*ResponseTag `protobuf:"bytes,5,rep,name=tags,proto3" json:"tags,omitempty"`
    XXX_NoUnkeyedLiteral struct{}       `json:"-"`
    XXX_unrecognized     []byte         `json:"-"`
    XXX_sizecache        int32          `json:"-"`
}

func (*Response) Descriptor
func (*Response) Descriptor() ([]byte, []int)
func (*Response) GetError
func (m *Response) GetError() bool
func (*Response) GetId
func (m *Response) GetId() string
func (*Response) GetJobName
func (m *Response) GetJobName() string
func (*Response) GetOutput
func (m *Response) GetOutput() string
func (*Response) GetTags
func (m *Response) GetTags() []*ResponseTag
func (*Response) ProtoMessage
func (*Response) ProtoMessage()
func (*Response) Reset
func (m *Response) Reset()
func (*Response) String
func (m *Response) String() string
func (*Response) XXX_DiscardUnknown
func (m *Response) XXX_DiscardUnknown()
func (*Response) XXX_Marshal
func (m *Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*Response) XXX_Merge
func (m *Response) XXX_Merge(src proto.Message)
func (*Response) XXX_Size
func (m *Response) XXX_Size() int
func (*Response) XXX_Unmarshal
func (m *Response) XXX_Unmarshal(b []byte) error

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

type TriggerFunc func(*Context, *Response) (*Response, error)

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.

func (*UnimplementedJobServer) Trigger
func (*UnimplementedJobServer) Trigger(ctx context.Context, req *Context) (*Response, error)

Generated by godoc2md

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

View Source
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"
)
View Source
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

func RegisterJobServer(s *grpc.Server, srv JobServer)

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) Descriptor() ([]byte, []int)

func (*Context) GetJobName

func (m *Context) GetJobName() string

func (*Context) ProtoMessage

func (*Context) ProtoMessage()

func (*Context) Reset

func (m *Context) Reset()

func (*Context) String

func (m *Context) String() string

func (*Context) XXX_DiscardUnknown

func (m *Context) XXX_DiscardUnknown()

func (*Context) XXX_Marshal

func (m *Context) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Context) XXX_Merge

func (m *Context) XXX_Merge(src proto.Message)

func (*Context) XXX_Size

func (m *Context) XXX_Size() int

func (*Context) XXX_Unmarshal

func (m *Context) XXX_Unmarshal(b []byte) error

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 JobServer

type JobServer interface {
	Trigger(context.Context, *Context) (*Response, error)
}

JobServer is the server API for Job service.

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

func (Loadtest) Start

func (l Loadtest) Start() (err error)

Start will start an RPC server on loadtest.RPCAddr and register Server ahead of Agents scheduling jobs

func (Loadtest) Trigger

func (l Loadtest) Trigger(ctx context.Context, c *Context) (r *Response, err error)

Trigger creates contexts/ outputs, and passes them to (Loadtest).trigger() to run a test

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) Descriptor() ([]byte, []int)

func (*Response) GetDuration

func (m *Response) GetDuration() uint64

func (*Response) GetError

func (m *Response) GetError() bool

func (*Response) GetId

func (m *Response) GetId() string

func (*Response) GetJobName

func (m *Response) GetJobName() string

func (*Response) GetOutput

func (m *Response) GetOutput() string

func (*Response) GetTags

func (m *Response) GetTags() []*ResponseTag

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) Reset

func (m *Response) Reset()

func (*Response) String

func (m *Response) String() string

func (*Response) XXX_DiscardUnknown

func (m *Response) XXX_DiscardUnknown()

func (*Response) XXX_Marshal

func (m *Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Response) XXX_Merge

func (m *Response) XXX_Merge(src proto.Message)

func (*Response) XXX_Size

func (m *Response) XXX_Size() int

func (*Response) XXX_Unmarshal

func (m *Response) XXX_Unmarshal(b []byte) error

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

type TriggerFunc func(*Context, *Response) (*Response, error)

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.

func (*UnimplementedJobServer) Trigger

func (*UnimplementedJobServer) Trigger(ctx context.Context, req *Context) (*Response, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL