A few thoughts:
1. Best not to use io.open to read config data from a file on disk. This will kill your performance. Better to store any data necessary either as a Lua module config, or if it changes dynamically with some frequency, some saner in-memory solution like memcached/redis/etc.
2. split_clients could be useful but it might be a bit of overkill wrt. cognitive load, depending on the use case and such. Short circuiting a percentage of requests via the access phase, like you've shown above, could also be acceptable:
access_by_lua_block {
local AVG = 3 -- 3 out of 10 requests get
if math.random(10) >= AVG then
ngx.status = 200
ngx.say("mocked a 200 response")
return ngx.exit(200)
end
}
With the above, roughly 3 out of every ten requests will not go through a content handler like proxy_pass, and instead have a mock message sent back to the client. If the condition above is not met, the request simply falls through the access phase, and content is delivered accordingly. Of course, writing this business logic in Lua gives you a lot more flexibility wrt. how you determine which clients get the short circuit message (e.g., deriving or white/blacklist mock responses based on client IP, arbitrary request data, etc).
Good luck with it!