Is there a way to change the json body in vegeta Post request load tests in vegeta.
I want to send a request with a different parameter in the json body for each of the requests. for example if I have
POST https://endpoint.com/createNew
@/targets/data.json
and data.json looks like
{
"id": 1234
}
What is the best way to make it so we have different request data for each of the requests in the attack?
The header identifies the source and destination of the packet, and is only used in the transmission process, while the actual data is referred to as the payload. Payload testing ensures that users receive data correctly on their next-generation networks.
Vegeta is an HTTP load testing tool written in Go that can be used as a command in a command-line interface or as a library. The program tests how an HTTP-based application behaves when multiple users access it at the same time by generating a background load of GET requests.
I needed to do something similiar and decided to use the vegeta lib rather than cli for this which allows me to control the HTTP requests
So you need to write your own function which return a vegeta.Targeter
func NewCustomTargeter() vegeta.Targeter {
return func(tgt *vegeta.Target) error {
if tgt == nil {
return vegeta.ErrNilTarget
}
tgt.Method = "POST"
tgt.URL = "https://endpoint.com/createNew"
rand := generateFourDigitRandom()
payload := '{ "id":"`+rand+ `" } `
tgt.Body = []byte(payload)
return nil
}
}
and use this function in the main function like this
targeter := NewCustomTargeter()
attacker := vegeta.NewAttacker()
var metrics vegeta.Metrics
for res := range attacker.Attack(targeter, rate, duration, "Load Test") {
metrics.Add(res)
}
metrics.Close()
fmt.Printf("%+v \n", metrics)
On Jul 10, 2018, vegeta#PR300 introduced the -format=json
option. Here is the vegeta README description:
The JSON format makes integration with programs that produce targets dynamically easier. Each target is one JSON object in its own line. The method and url fields are required. If present, the body field must be base64 encoded. The generated JSON Schema defines the format in detail.
And their provided example:
jq -ncM '{method: "GET", url: "http://goku", body: "Punch!" | @base64, header: {"Content-Type": ["text/plain"]}}' |
vegeta attack -format=json -rate=100 | vegeta encode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With