Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add URL and Method to Result struct #438

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module github.com/tsenart/vegeta

go 1.13

require (
github.com/alecthomas/jsonschema v0.0.0-20180308105923-f2c93856175a
github.com/bmizerany/perks v0.0.0-20141205001514-d9a9656a3a4b
github.com/c2h5oh/datasize v0.0.0-20171227191756-4eba002a5eae
github.com/dgryski/go-gk v0.0.0-20140819190930-201884a44051
github.com/dgryski/go-lttb v0.0.0-20180810165845-318fcdf10a77
github.com/google/go-cmp v0.2.0
github.com/influxdata/tdigest v0.0.0-20180711151920-a7d76c6f093a
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329
github.com/miekg/dns v1.1.17
github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371
github.com/shurcooL/vfsgen v0.0.0-20180711163814-62bca832be04
github.com/streadway/quantile v0.0.0-20150917103942-b0c588724d25
github.com/tsenart/go-tsz v0.0.0-20180814232043-cdeb9e1e981e
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297
golang.org/x/text v0.3.2
)
3 changes: 3 additions & 0 deletions lib/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ func (a *Attacker) hit(tr Targeter, name string) *Result {
return &res
}

res.Method = tgt.Method
res.URL = tgt.URL

req, err := tgt.Request()
if err != nil {
return &res
Expand Down
28 changes: 20 additions & 8 deletions lib/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type Result struct {
BytesIn uint64 `json:"bytes_in"`
Error string `json:"error"`
Body []byte `json:"body"`
Method string `json:"method"`
URL string `json:"url"`
}

// End returns the time at which a Result ended.
Expand All @@ -45,7 +47,9 @@ func (r Result) Equal(other Result) bool {
r.BytesIn == other.BytesIn &&
r.BytesOut == other.BytesOut &&
r.Error == other.Error &&
bytes.Equal(r.Body, other.Body)
bytes.Equal(r.Body, other.Body) &&
r.Method == other.Method &&
r.URL == other.URL
}

// Results is a slice of Result type elements.
Expand Down Expand Up @@ -150,8 +154,9 @@ func NewCSVEncoder(w io.Writer) Encoder {
base64.StdEncoding.EncodeToString(r.Body),
r.Attack,
strconv.FormatUint(r.Seq, 10),
r.Method,
r.URL,
})

if err != nil {
return err
}
Expand All @@ -163,9 +168,9 @@ func NewCSVEncoder(w io.Writer) Encoder {
}

// NewCSVDecoder returns a Decoder that decodes CSV encoded Results.
func NewCSVDecoder(rd io.Reader) Decoder {
dec := csv.NewReader(rd)
dec.FieldsPerRecord = 9
func NewCSVDecoder(r io.Reader) Decoder {
dec := csv.NewReader(r)
dec.FieldsPerRecord = 11
dec.TrimLeadingSpace = true

return func(r *Result) error {
Expand Down Expand Up @@ -208,16 +213,23 @@ func NewCSVDecoder(rd io.Reader) Decoder {
return err
}

r.Method = rec[9]
r.URL = rec[10]

return err
}
}

//go:generate easyjson -no_std_marshalers -output_filename results_easyjson.go results.go
//easyjson:json
type jsonResult Result

// NewJSONEncoder returns an Encoder that dumps the given *Results as a JSON
// object.
func NewJSONEncoder(w io.Writer) Encoder {
var jw jwriter.Writer
return func(r *Result) error {
(*jsonResult)(r).encode(&jw)
(*jsonResult)(r).MarshalEasyJSON(&jw)
if jw.Error != nil {
return jw.Error
}
Expand All @@ -232,10 +244,10 @@ func NewJSONDecoder(r io.Reader) Decoder {
rd := bufio.NewReader(r)
return func(r *Result) (err error) {
var jl jlexer.Lexer
if jl.Data, err = rd.ReadSlice('\n'); err != nil {
if jl.Data, err = rd.ReadBytes('\n'); err != nil {
return err
}
(*jsonResult)(r).decode(&jl)
(*jsonResult)(r).UnmarshalEasyJSON(&jl)
return jl.Error()
}
}
150 changes: 67 additions & 83 deletions lib/results_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.