Files

30 lines
1.3 KiB
C++

// Route: GET /stats/data (request, connection, and service statistics)
#include "support/Assert.hpp"
using namespace molo::example::test;
int main() {
Fixture f;
f.client->get("/health");
f.client->get("/health");
f.client->get("/no/such/route");
f.client->post("/forms/contact", "name=ada",
"application/x-www-form-urlencoded");
auto res = f.client->get("/stats/data");
check(res.status == 200, "status 200");
check(contains(res.headers.get("Content-Type"), "application/json"), "json");
check(contains(res.body, "\"requests\":4"), "four requests before this one");
check(contains(res.body, "\"errors\":2"), "404 and 422 counted as errors");
check(contains(res.body, "\"404\":1") && contains(res.body, "\"422\":1"),
"status breakdown");
check(contains(res.body, "\"/health\""), "route pattern grouped");
check(contains(res.body, "\"(unmatched)\""), "unmatched bucket");
check(contains(res.body, "\"POST\":1") && contains(res.body, "\"GET\":3"),
"method breakdown");
check(contains(res.body, "\"p95_ms\""), "latency percentiles");
check(contains(res.body, "\"connections\""), "connection block");
check(contains(res.body, "\"series\""), "time series");
check(f.services.stats->total_requests() == 5, "side effect: 5 recorded");
return finish("stats/data");
}