-- _diag_status.lua — diagnostic: tally response status codes and print them. -- -- The normal bench scripts report only an aggregate "Non-2xx" count, which -- can't tell a 401 (auth not reaching the server) from a 404 (store not -- populated) from a 503 (store-call erroring). This script counts every -- status code and prints the breakdown in done(). -- -- IMPORTANT: run with a SINGLE wrk thread (-t1) so response() and done() -- share one Lua VM and the counter aggregates. Low load is fine; this is a -- correctness probe, not a throughput test. -- -- Usage (against an already-running, pre-populated server): -- HOST=127.0.0.1:8080 BEARER=test-token-aaaaaaaaaaaaaaaaaaaa \ -- wrk -t1 -c10 -d3s -s loadgen/_diag_status.lua http://127.0.0.1:8080 -- -- It sends the S3 mix (GET-one / list / POST) so it exercises auth + store -- on every route. If you see mostly 401 -> the auth header isn't reaching the -- server (lua/header issue). Mostly 404 -> the store wasn't pre-populated. -- Mostly 503 -> store-call is erroring (store actor down). Mostly 2xx at low -- load but the full bench shows non-2xx -> it's load/scale dependent. local common = require("common") wrk.headers = common.headers wrk.headers["Content-Type"] = "application/json" math.randomseed(os.time() + os.getpid()) local body = [[{"name":"diag","email":"diag@example.test"}]] request = function() local r = math.random() if r < 0.80 then return wrk.format("GET", "/api/v1/users/" .. math.random(1, 10000)) elseif r < 0.95 then return wrk.format("GET", "/api/v1/users") else return wrk.format("POST", "/api/v1/users", nil, body) end end local codes = {} local total = 0 response = function(status, headers, body) codes[status] = (codes[status] or 0) + 1 total = total + 1 end done = function(summary, latency, requests) io.write("\n=== status code distribution (single-thread tally) ===\n") -- sort keys for stable output local keys = {} for k in pairs(codes) do keys[#keys + 1] = k end table.sort(keys) for _, k in ipairs(keys) do local n = codes[k] io.write(string.format(" %d : %d (%.1f%%)\n", k, n, 100.0 * n / total)) end io.write(string.format(" total tallied: %d\n", total)) if codes[401] and codes[401] > total * 0.5 then io.write(" -> mostly 401: the auth header is NOT reaching the server.\n") elseif codes[404] and codes[404] > total * 0.5 then io.write(" -> mostly 404: the store was NOT pre-populated (or id range mismatch).\n") elseif codes[503] and codes[503] > total * 0.5 then io.write(" -> mostly 503: store-call is erroring (store actor down).\n") end end