hatoo / oha

Ohayou(おはよう), HTTP load generator, inspired by rakyll/hey with tui animation.
MIT License
5.62k stars 138 forks source link

Feature request: support dynamic request body similar to --rand-regex-url #586

Open fedulovivan opened 1 week ago

fedulovivan commented 1 week ago

I'm trying to create load for the enpoint which has a unique name constraint for the created entity. So the imaginary ⚠️ syntax could be like:

oha --method PUT -H 'Content-Type: application/json' -d '{"name":"name-{{uuid}}"}' http://localhost/entity
# or
oha --method PUT -H 'Content-Type: application/json' -d '{"name":"name-[a-z][a-z][0-9]"}' http://localhost/entity

Following snippet obviously do not work, as well:

oha --method PUT -H 'Content-Type: application/json' -d "{\"name\":\"name-`uuidgen`\"}" http://localhost/entity
fedulovivan commented 1 week ago

I have found a workaround thought. Which utilises --rand-regex-url feature.

First step is adding special handling in PUT request handler for the load-tested application, which is able to receive entity name via the url, in addition to the request body handling (normal behavior). See details here my case here.

Second step, is using url with random entity name for the put request: oha --method PUT -H 'Content-Type: application/json' -n 10000 -c 10 -D ./assets/load/create-rule.json --rand-regex-url http://localhost/rules/name-[a-z0-9]{16} Complete example is here