runner

package
v0.53.0-beta9 Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: Apache-2.0 Imports: 39 Imported by: 41

Documentation

Index

Examples

Constants

View Source
const (
	// ReasonNormalEnd indicates a normal end to the run
	ReasonNormalEnd = StopReason("normal")

	// ReasonCancel indicates end due to cancellation
	ReasonCancel = StopReason("cancel")

	// ReasonTimeout indicates run ended due to Z parameter timeout
	ReasonTimeout = StopReason("timeout")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket struct {
	// The Mark for histogram bucket in seconds
	Mark float64 `json:"mark"`

	// The count in the bucket
	Count int `json:"count"`

	// The frequency of results in the bucket as a decimal percentage
	Frequency float64 `json:"frequency"`
}

Bucket holds histogram data

type Config added in v0.52.0

type Config struct {
	Proto             string             `json:"proto" toml:"proto" yaml:"proto"`
	Protoset          string             `json:"protoset" toml:"protoset" yaml:"protoset"`
	Call              string             `json:"call" toml:"call" yaml:"call"`
	RootCert          string             `json:"cacert" toml:"cacert" yaml:"cacert"`
	Cert              string             `json:"cert" toml:"cert" yaml:"cert"`
	Key               string             `json:"key" toml:"key" yaml:"key"`
	SkipTLSVerify     bool               `json:"skipTLS" toml:"skipTLS" yaml:"skipTLS"`
	CName             string             `json:"cname" toml:"cname" yaml:"cname"`
	Authority         string             `json:"authority" toml:"authority" yaml:"authority"`
	Insecure          bool               `json:"insecure,omitempty" toml:"insecure,omitempty" yaml:"insecure,omitempty"`
	N                 uint               `json:"total" toml:"total" yaml:"total" default:"200"`
	C                 uint               `json:"concurrency" toml:"concurrency" yaml:"concurrency" default:"50"`
	Connections       uint               `json:"connections" toml:"connections" yaml:"connections" default:"1"`
	QPS               uint               `json:"qps" toml:"qps" yaml:"qps"`
	Z                 Duration           `json:"duration" toml:"duration" yaml:"duration"`
	ZStop             string             `json:"duration-stop" toml:"duration-stop" yaml:"duration-stop" default:"close"`
	X                 Duration           `json:"max-duration" toml:"max-duration" yaml:"max-duration"`
	Timeout           Duration           `json:"timeout" toml:"timeout" yaml:"timeout" default:"20s"`
	Data              interface{}        `json:"data,omitempty" toml:"data,omitempty" yaml:"data,omitempty"`
	DataPath          string             `json:"data-file" toml:"data-file" yaml:"data-file"`
	BinData           []byte             `json:"-" toml:"-" yaml:"-"`
	BinDataPath       string             `json:"binary-file" toml:"binary-file" yaml:"binary-file"`
	Metadata          *map[string]string `json:"metadata,omitempty" toml:"metadata,omitempty" yaml:"metadata,omitempty"`
	MetadataPath      string             `json:"metadata-file" toml:"metadata-file" yaml:"metadata-file"`
	SI                Duration           `json:"stream-interval" toml:"stream-interval" yaml:"stream-interval"`
	Output            string             `json:"output" toml:"output" yaml:"output"`
	Format            string             `json:"format" toml:"format" yaml:"format" default:"summary"`
	DialTimeout       Duration           `json:"connect-timeout" toml:"connect-timeout" yaml:"connect-timeout" default:"10s"`
	KeepaliveTime     Duration           `json:"keepalive" toml:"keepalive" yaml:"keepalive"`
	CPUs              uint               `json:"cpus" toml:"cpus" yaml:"cpus"`
	ImportPaths       []string           `json:"import-paths,omitempty" toml:"import-paths,omitempty" yaml:"import-paths,omitempty"`
	Name              string             `json:"name,omitempty" toml:"name,omitempty" yaml:"name,omitempty"`
	Tags              *map[string]string `json:"tags,omitempty" toml:"tags,omitempty" yaml:"tags,omitempty"`
	ReflectMetadata   *map[string]string `json:"reflect-metadata,omitempty" toml:"reflect-metadata,omitempty" yaml:"reflect-metadata,omitempty"`
	Debug             string             `json:"debug,omitempty" toml:"debug,omitempty" yaml:"debug,omitempty"`
	Host              string             `json:"host" toml:"host" yaml:"host"`
	EnableCompression bool               `json:"enable-compression,omitempty" toml:"enable-compression,omitempty" yaml:"enable-compression,omitempty"`
}

Config for the run.

func (Config) MarshalJSON added in v0.52.0

func (c Config) MarshalJSON() ([]byte, error)

MarshalJSON is our custom implementation to handle the Duration fields

func (*Config) UnmarshalJSON added in v0.52.0

func (c *Config) UnmarshalJSON(data []byte) error

UnmarshalJSON is our custom implementation to handle the Duration fields and validate data

type Duration added in v0.52.0

type Duration time.Duration

Duration is our duration with TOML support

func (Duration) MarshalText added in v0.52.0

func (d Duration) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler

func (Duration) String added in v0.52.0

func (d Duration) String() string

func (*Duration) UnmarshalText added in v0.52.0

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText is our custom unmarshaller with TOML support

type LatencyDistribution

type LatencyDistribution struct {
	Percentage int           `json:"percentage"`
	Latency    time.Duration `json:"latency"`
}

LatencyDistribution holds latency distribution data

type Logger added in v0.47.0

type Logger interface {
	Debug(args ...interface{})
	Debugf(template string, args ...interface{})
	Debugw(msg string, keysAndValues ...interface{})
	Error(args ...interface{})
	Errorf(template string, args ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
}

Logger interface is the common logger interface for all of web

type Option

type Option func(*RunConfig) error

Option controls some aspect of run

func WithAuthority added in v0.25.0

func WithAuthority(authority string) Option

WithAuthority specifies the value to be used as the :authority pseudo-header. This only works with WithInsecure option.

func WithBinaryData

func WithBinaryData(data []byte) Option

WithBinaryData specifies the binary data

msg := &helloworld.HelloRequest{}
msg.Name = "bob"
binData, _ := proto.Marshal(msg)
WithBinaryData(binData)

func WithBinaryDataFromFile

func WithBinaryDataFromFile(path string) Option

WithBinaryDataFromFile specifies the binary data

WithBinaryDataFromFile("request_data.bin")

func WithCPUs

func WithCPUs(c uint) Option

WithCPUs specifies the number of CPU's to be used

WithCPUs(4)

func WithCertificate

func WithCertificate(cert, key string) Option

WithCertificate specifies the certificate options for the run

WithCertificate("client.crt", "client.key")

func WithConcurrency

func WithConcurrency(c uint) Option

WithConcurrency specifies the C (number of concurrent requests) option

WithConcurrency(20)

func WithConfig added in v0.52.0

func WithConfig(c *Config) Option

WithConfig uses the configuration to populate the RunConfig See also: WithConfigFromFile, WithConfigFromReader

func WithConfigFromFile added in v0.52.0

func WithConfigFromFile(file string) Option

WithConfigFromFile uses a configuration JSON file to populate the RunConfig

WithConfig("config.json")

func WithConfigFromReader added in v0.52.0

func WithConfigFromReader(reader io.Reader) Option

WithConfigFromReader uses a reader containing JSON data to populate the RunConfig See also: WithConfigFromFile

func WithConnections added in v0.35.0

func WithConnections(c uint) Option

WithConnections specifies the number of gRPC connections to use

WithConnections(5)

func WithData

func WithData(data interface{}) Option

WithData specifies data as generic data that can be serailized to JSON

func WithDataFromFile

func WithDataFromFile(path string) Option

WithDataFromFile loads JSON data from file

WithDataFromFile("data.json")

func WithDataFromJSON

func WithDataFromJSON(data string) Option

WithDataFromJSON loads JSON data from string

WithDataFromJSON(`{"name":"bob"}`)

func WithDataFromReader

func WithDataFromReader(r io.Reader) Option

WithDataFromReader loads JSON data from reader

file, _ := os.Open("data.json")
WithDataFromReader(file)

func WithDialTimeout

func WithDialTimeout(dt time.Duration) Option

WithDialTimeout specifies the initial connection dial timeout

WithDialTimeout(time.Duration(20*time.Second))

func WithDurationStopAction added in v0.42.0

func WithDurationStopAction(action string) Option

WithDurationStopAction specifies how run duration (Z) timeout is handled Possible options are "close", "ignore", and "wait"

WithDurationStopAction("ignore")

func WithEnableCompression added in v0.50.0

func WithEnableCompression(enableCompression bool) Option

WithEnableCompression specifies that requests should be done using gzip Compressor WithEnableCompression(true)

func WithInsecure

func WithInsecure(insec bool) Option

WithInsecure specifies that this run should be done using insecure mode

WithInsecure(true)

func WithKeepalive

func WithKeepalive(k time.Duration) Option

WithKeepalive specifies the keepalive timeout

WithKeepalive(time.Duration(1*time.Minute))

func WithLogger added in v0.47.0

func WithLogger(log Logger) Option

WithLogger specifies the logging option

func WithMetadata

func WithMetadata(md *map[string]string) Option

WithMetadata specifies the metadata to be used as a map

md := make(map[string]string)
md["token"] = "foobar"
md["request-id"] = "123"
WithMetadata(&md)

func WithMetadataFromFile

func WithMetadataFromFile(path string) Option

WithMetadataFromFile loads JSON metadata from file

WithMetadataFromJSON("metadata.json")

func WithMetadataFromJSON

func WithMetadataFromJSON(md string) Option

WithMetadataFromJSON specifies the metadata to be read from JSON string

WithMetadataFromJSON(`{"request-id":"123"}`)

func WithName

func WithName(name string) Option

WithName sets the name of the test run

WithName("greeter service test")

func WithProtoFile

func WithProtoFile(proto string, importPaths []string) Option

WithProtoFile specified proto file path and optionally import paths We will automatically add the proto file path's directory and the current directory

WithProtoFile("greeter.proto", []string{"/home/protos"})

func WithProtoset

func WithProtoset(protoset string) Option

WithProtoset specified protoset file path

WithProtoset("bundle.protoset")

func WithQPS

func WithQPS(qps uint) Option

WithQPS specifies the QPS (queries per second) limit option

WithQPS(10)

func WithReflectionMetadata added in v0.30.0

func WithReflectionMetadata(md *map[string]string) Option

WithReflectionMetadata specifies the metadata to be used as a map

md := make(map[string]string)
md["token"] = "foobar"
md["request-id"] = "123"
WithReflectionMetadata(&md)

func WithRootCertificate added in v0.25.0

func WithRootCertificate(cert string) Option

WithRootCertificate specifies the root certificate options for the run

WithRootCertificate("ca.crt")

func WithRunDuration

func WithRunDuration(z time.Duration) Option

WithRunDuration specifies the Z (total test duration) option

WithRunDuration(time.Duration(2*time.Minute))

func WithServerNameOverride added in v0.25.0

func WithServerNameOverride(cname string) Option

WithServerNameOverride specifies the certificate options for the run

func WithSkipTLSVerify added in v0.25.0

func WithSkipTLSVerify(skip bool) Option

WithSkipTLSVerify skip client side TLS verification of server certificate

func WithStreamInterval added in v0.28.0

func WithStreamInterval(d time.Duration) Option

WithStreamInterval sets the stream interval

func WithTags added in v0.22.0

func WithTags(tags *map[string]string) Option

WithTags specifies the user defined tags as a map

tags := make(map[string]string)
tags["env"] = "staging"
tags["created by"] = "joe developer"
WithTags(&tags)

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout specifies the timeout for each request

WithTimeout(time.Duration(20*time.Second))

func WithTotalRequests

func WithTotalRequests(n uint) Option

WithTotalRequests specifies the N (number of total requests) setting

WithTotalRequests(1000)

type Options

type Options struct {
	Host          string        `json:"host,omitempty"`
	Proto         string        `json:"proto,omitempty"`
	Protoset      string        `json:"protoset,omitempty"`
	ImportPaths   []string      `json:"import-paths,omitempty"`
	Call          string        `json:"call,omitempty"`
	CACert        string        `json:"cacert,omitempty"`
	Cert          string        `json:"cert,omitempty"`
	Key           string        `json:"key,omitempty"`
	SkipTLS       bool          `json:"skipTLS,omitempty"`
	CName         string        `json:"cname,omitempty"`
	Authority     string        `json:"authority,omitempty"`
	Insecure      bool          `json:"insecure"`
	Total         uint          `json:"total,omitempty"`
	Concurrency   uint          `json:"concurrency,omitempty"`
	QPS           uint          `json:"qps,omitempty"`
	Connections   uint          `json:"connections,omitempty"`
	Duration      time.Duration `json:"duration,omitempty"`
	Timeout       time.Duration `json:"timeout,omitempty"`
	DialTimeout   time.Duration `json:"dial-timeout,omitempty"`
	KeepaliveTime time.Duration `json:"keepalive,omitempty"`

	Data     interface{}        `json:"data,omitempty"`
	Binary   bool               `json:"binary"`
	Metadata *map[string]string `json:"metadata,omitempty"`

	CPUs int    `json:"CPUs"`
	Name string `json:"name,omitempty"`
}

Options represents the request options

type Report

type Report struct {
	Name      string     `json:"name,omitempty"`
	EndReason StopReason `json:"endReason,omitempty"`

	Options Options   `json:"options,omitempty"`
	Date    time.Time `json:"date"`

	Count   uint64        `json:"count"`
	Total   time.Duration `json:"total"`
	Average time.Duration `json:"average"`
	Fastest time.Duration `json:"fastest"`
	Slowest time.Duration `json:"slowest"`
	Rps     float64       `json:"rps"`

	ErrorDist      map[string]int `json:"errorDistribution"`
	StatusCodeDist map[string]int `json:"statusCodeDistribution"`

	LatencyDistribution []LatencyDistribution `json:"latencyDistribution"`
	Histogram           []Bucket              `json:"histogram"`
	Details             []ResultDetail        `json:"details"`

	Tags map[string]string `json:"tags,omitempty"`
}

Report holds the data for the full test

func Run

func Run(call, host string, options ...Option) (*Report, error)

Run executes the test

report, err := runner.Run(
	"helloworld.Greeter.SayHello",
	"localhost:50051",
	WithProtoFile("greeter.proto", []string{}),
	WithDataFromFile("data.json"),
	WithInsecure(true),
)
Example

ExampleRun demonstrates how to use runner package to perform a gRPC load test programmatically. We use the printer package to print the report in pretty JSON format.

package main

import (
	"fmt"
	"os"

	"github.com/bojand/ghz/printer"
	"github.com/bojand/ghz/runner"
)

func main() {
	report, err := runner.Run(
		"helloworld.Greeter.SayHello",
		"localhost:50051",
		runner.WithProtoFile("greeter.proto", []string{}),
		runner.WithDataFromFile("data.json"),
		runner.WithInsecure(true),
	)

	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	printer := printer.ReportPrinter{
		Out:    os.Stdout,
		Report: report,
	}

	printer.Print("pretty")
}
Output:

func (Report) MarshalJSON

func (r Report) MarshalJSON() ([]byte, error)

MarshalJSON is custom marshal for report to properly format the date

type Reporter

type Reporter struct {
	// contains filtered or unexported fields
}

Reporter gathers all the results

func (*Reporter) Finalize

func (r *Reporter) Finalize(stopReason StopReason, total time.Duration) *Report

Finalize all the gathered data into a final report

func (*Reporter) Run

func (r *Reporter) Run()

Run runs the reporter

type Requester

type Requester struct {
	// contains filtered or unexported fields
}

Requester is used for doing the requests

func (*Requester) Finish

func (b *Requester) Finish() *Report

Finish finishes the test run

func (*Requester) Run

func (b *Requester) Run() (*Report, error)

Run makes all the requests and returns a report of results It blocks until all work is done.

func (*Requester) Stop

func (b *Requester) Stop(reason StopReason)

Stop stops the test

type ResultDetail

type ResultDetail struct {
	Timestamp time.Time     `json:"timestamp"`
	Latency   time.Duration `json:"latency"`
	Error     string        `json:"error"`
	Status    string        `json:"status"`
}

ResultDetail data for each result

type RunConfig

type RunConfig struct {
	// contains filtered or unexported fields
}

RunConfig represents the request Configs

type StopReason

type StopReason string

StopReason is a reason why the run ended

func ReasonFromString

func ReasonFromString(str string) StopReason

ReasonFromString creates a Status from a string

func (StopReason) MarshalJSON

func (s StopReason) MarshalJSON() ([]byte, error)

MarshalJSON formats a Threshold value into a JSON string

func (StopReason) String

func (s StopReason) String() string

String() is the string representation of threshold

func (*StopReason) UnmarshalJSON

func (s *StopReason) UnmarshalJSON(b []byte) error

UnmarshalJSON prases a Threshold value from JSON string

type Worker added in v0.35.0

type Worker struct {
	// contains filtered or unexported fields
}

Worker is used for doing a single stream of requests in parallel

Jump to

Keyboard shortcuts

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