Skip to content

Commit

Permalink
add options to JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
bojand committed Aug 6, 2018
1 parent 1a5d675 commit 702c3b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
10 changes: 7 additions & 3 deletions reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

// Reporter gethers all the results
type Reporter struct {
options *Options
results chan *callResult
done chan bool

Expand All @@ -24,7 +25,8 @@ type Reporter struct {

// Report holds the data for the full test
type Report struct {
Date time.Time `json:"date"`
Options *Options `json:"options,omitempty"`
Date time.Time `json:"date"`

Count uint64 `json:"count"`
Total time.Duration `json:"total"`
Expand Down Expand Up @@ -78,9 +80,10 @@ type ResultDetail struct {
Status string `json:"status"`
}

func newReporter(results chan *callResult, n int) *Reporter {
cap := min(n, maxResult)
func newReporter(results chan *callResult, options *Options) *Reporter {
cap := min(options.N, maxResult)
return &Reporter{
options: options,
results: results,
done: make(chan bool, 1),
statusCodeDist: make(map[string]int),
Expand Down Expand Up @@ -122,6 +125,7 @@ func (r *Reporter) Finalize(total time.Duration) *Report {
rps := float64(r.totalCount) / total.Seconds()

rep := &Report{
Options: r.options,
Date: time.Now(),
Count: r.totalCount,
Total: total,
Expand Down
26 changes: 13 additions & 13 deletions requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ import (

// Options represents the request options
type Options struct {
Host string
Cert string
CName string
N int
C int
QPS int
Z time.Duration
Timeout int
DialTimtout int
KeepaliveTime int
Data interface{}
Metadata *map[string]string
Host string `json:"host,omitempty"`
Cert string `json:"cert,omitempty"`
CName string `json:"cname,omitempty"`
N int `json:"n,omitempty"`
C int `json:"c,omitempty"`
QPS int `json:"qps,omitempty"`
Z time.Duration `json:"z,omitempty"`
Timeout int `json:"timeout,omitempty"`
DialTimtout int `json:"dialTimeout,omitempty"`
KeepaliveTime int `json:"keepAlice,omitempty"`
Data interface{} `json:"data,omitempty"`
Metadata *map[string]string `json:"metadata,omitempty"`
}

// Max size of the buffer of result channel.
Expand Down Expand Up @@ -113,7 +113,7 @@ func (b *Requester) Run() (*Report, error) {

b.stub = grpcdynamic.NewStub(cc)

b.reporter = newReporter(b.results, b.config.N)
b.reporter = newReporter(b.results, b.config)

go func() {
b.reporter.Run()
Expand Down

0 comments on commit 702c3b9

Please sign in to comment.