From 8b2b26ffe06be7371d3923987d22887320cee9b4 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Thu, 4 Aug 2022 18:57:07 -0400 Subject: [PATCH] fix: Correct routes and URLs to please prometheus --- runtime/src/metrics_server.c | 2 +- .../src/metrics_server_route_level_metrics.c | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/runtime/src/metrics_server.c b/runtime/src/metrics_server.c index b8cd157..a4f4d4a 100644 --- a/runtime/src/metrics_server.c +++ b/runtime/src/metrics_server.c @@ -56,7 +56,7 @@ metrics_server_thread_spawn(int client_socket) fgets(http_status_code_buf, 256, req_body); fclose(req_body); - if (strncmp(http_status_code_buf, "GET / HTTP", 10) != 0) { + if (strncmp(http_status_code_buf, "GET /metrics HTTP", 10) != 0) { write(client_socket, http_header_build(404), http_header_len(404)); close(client_socket); return; diff --git a/runtime/src/metrics_server_route_level_metrics.c b/runtime/src/metrics_server_route_level_metrics.c index 2936a5d..b517874 100644 --- a/runtime/src/metrics_server_route_level_metrics.c +++ b/runtime/src/metrics_server_route_level_metrics.c @@ -25,17 +25,20 @@ render_routes(struct route *route, void *arg_one, void *arg_two) uint64_t total_4XX = atomic_load(&route->metrics.total_4XX); uint64_t total_5XX = atomic_load(&route->metrics.total_5XX); - fprintf(ostream, "# TYPE %s_%s_total_requests counter\n", tenant->name, route->route); - fprintf(ostream, "%s_%s_total_requests: %lu\n", tenant->name, route->route, total_requests); + // Strip leading / + const char *route_label = &route->route[1]; - fprintf(ostream, "# TYPE %s_%s_total_2XX counter\n", tenant->name, route->route); - fprintf(ostream, "%s_%s_total_2XX: %lu\n", tenant->name, route->route, total_2XX); + fprintf(ostream, "# TYPE %s_%s_total_requests counter\n", tenant->name, route_label); + fprintf(ostream, "%s_%s_total_requests: %lu\n", tenant->name, route_label, total_requests); - fprintf(ostream, "# TYPE %s_%s_total_4XX counter\n", tenant->name, route->route); - fprintf(ostream, "%s_%s_total_4XX: %lu\n", tenant->name, route->route, total_4XX); + fprintf(ostream, "# TYPE %s_%s_total_2XX counter\n", tenant->name, route_label); + fprintf(ostream, "%s_%s_total_2XX: %lu\n", tenant->name, route_label, total_2XX); - fprintf(ostream, "# TYPE %s_%s_total_5XX counter\n", tenant->name, route->route); - fprintf(ostream, "%s_%s_total_5XX: %lu\n", tenant->name, route->route, total_5XX); + fprintf(ostream, "# TYPE %s_%s_total_4XX counter\n", tenant->name, route_label); + fprintf(ostream, "%s_%s_total_4XX: %lu\n", tenant->name, route_label, total_4XX); + + fprintf(ostream, "# TYPE %s_%s_total_5XX counter\n", tenant->name, route_label); + fprintf(ostream, "%s_%s_total_5XX: %lu\n", tenant->name, route_label, total_5XX); #ifdef ADMISSIONS_CONTROL fprintf(ostream, "# TYPE %s_%s_latency_p50 gauge\n", tenant->name, route->route);