This repository has been archived by the owner on Aug 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
write-secrets.lua
62 lines (56 loc) · 1.87 KB
/
write-secrets.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
-- Script that writes secrets to k/v engine in Vault
-- Indicate number of secrets to write to secret/read-test path with "-- <N>"
local counter = 1
local threads = {}
function setup(thread)
thread:set("id", counter)
table.insert(threads, thread)
counter = counter + 1
end
function init(args)
if args[1] == nil then
num_secrets = 1000
else
num_secrets = tonumber(args[1])
end
print("Number of secrets is: " .. num_secrets)
requests = 0
writes = 0
responses = 0
method = "POST"
path = "/v1/secret/read-test/secret-0"
body = ''
local msg = "thread %d created"
print(msg:format(id))
end
function request()
-- First request is not actually invoked
-- So, don't process it in order to get secret-1 as first secret
if requests > 0 then
writes = writes + 1
-- cycle through paths from 1 to num_secrets in order
path = "/v1/secret/read-test/secret-" .. writes
-- minimal secret giving thread id and # of write
-- body = '{"foo-' .. id .. '" : "bar-' .. writes ..'"}'
-- add extra key with 100 bytes
body = '{"thread-' .. id .. '" : "write-' .. writes ..'","extra" : "1xxxxxxxxx2xxxxxxxxx3xxxxxxxxx4xxxxxxxxx5xxxxxxxxx6xxxxxxxxx7xxxxxxxxx8xxxxxxxxx9xxxxxxxxx0xxxxxxxxx"}'
end
requests = requests + 1
return wrk.format(method, path, nil, body)
end
function response(status, headers, body)
responses = responses + 1
if responses == num_secrets then
os.exit()
end
end
function done(summary, latency, requests)
for index, thread in ipairs(threads) do
local id = thread:get("id")
local requests = thread:get("requests")
local writes = thread:get("writes")
local responses = thread:get("responses")
local msg = "thread %d made %d requests including %d writes and got %d responses"
print(msg:format(id, requests, writes, responses))
end
end