Files
moloapp/tests/example/prom/metrics_test.cpp
T

21 lines
904 B
C++
Raw Normal View History

// Route: GET /metrics (Prometheus text: stats plus example metrics)
#include "support/Assert.hpp"
using namespace molo::example::test;
using molo::example::fw::Method;
int main() {
Fixture f;
f.services.metrics->inc("demo.hits", 3);
f.client->get("/health");
auto res = f.client->get("/metrics");
check(res.status == 200, "status 200");
check(contains(res.headers.get("Content-Type"), "text/plain; version=0.0.4"), "prometheus content type");
check(contains(res.body, "# TYPE molo_http_requests_total counter"), "type line");
check(contains(res.body, "molo_http_requests_total "), "request counter");
check(contains(res.body, "molo_example_demo_hits 3"), "example metric sanitized");
check(f.services.stats->total_requests() >= 2, "side effect: stats counted");
check(f.client->request(Method::Post, "/metrics").status == 405, "post is 405");
return finish("prom/metrics");
}