Performance Test – Vegeta Load Test: Different subjects of each post request in the attack

Is there a way to change the load test of the json body in the vegetable in the later request load test in the vegetable.

I want to send in the json body for each request A request with different parameters. For example, if I have

POST https://endpoint.com/createNew
@/targets/data.json

pre>

and data.json looks like

{
"id": 1234
}

Make it What is the best way for us to provide different request data for each request in the attack?

I need to do something similar and decided to use vegeta lib instead of cli, which allows me to control HTTP request

So you need to write your own function to return vegeta.Targeter

func NewCustomTargeter() vegeta.Targeter {
return func(tgt *vegeta.Target) error {
if tgt == nil {
return vegeta.ErrNilTarget
}

tgt.Method = "POST"< br />
tgt.URL = "https://endpoint.com/createNew"

rand := generateFourDigitRandom()

payload :='{ " id":"`+rand+ `"} `
tgt.Body = []byte(payload)
return nil
}
}

and in This function is used in this main function

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

Is there a way to change the load test of the json body in the vegetable in the later request load test in the vegetable.

I want to send a different request in the json body for each request Parameter request. For example, if I have

POST https://endpoint.com/createNew
@/targets/data.json

and data.json looks like

{
"id": 1234
}

The best way to make it What is it so that we provide different request data for each request in the attack?

I need to do something similar and decided to use vegeta lib instead of cli, which allows me to control HTTP requests

So you need to write your own function to return vegeta.Targeter

func NewCustomTargeter() vegeta.Targeter {
return func(tgt *vegeta.Target) error {< br /> if tgt == nil {
return vegeta.ErrNilTarget
}

tgt.Method = "POST"

tgt.URL = " https://endpoint.com/createNew"

rand := generateFourDigitRandom()

payload :='{ "id":"`+rand+ `"} `< br /> tgt.Body = []byte(payload)
return nil
}
}

and use this function in this main function

< p>

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

Leave a Comment

Your email address will not be published.