From: Sean Bright Date: Tue, 21 Jan 2025 23:37:54 +0000 (-0500) Subject: res_prometheus.c: Set Content-Type header on /metrics response. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa286641fb39b8aedab19127996d2c13afdb45b7;p=thirdparty%2Fasterisk.git res_prometheus.c: Set Content-Type header on /metrics response. This should resolve the Prometheus error: > Error scraping target: non-compliant scrape target sending blank Content-Type and no fallback_scrape_protocol specified for target. Resolves: #1075 --- diff --git a/res/res_prometheus.c b/res/res_prometheus.c index 6633c1755e..a04dbd8520 100644 --- a/res/res_prometheus.c +++ b/res/res_prometheus.c @@ -603,6 +603,7 @@ static int http_callback(struct ast_tcptls_session_instance *ser, { RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(global_config), ao2_cleanup); struct ast_str *response = NULL; + struct ast_str *content_type_header = NULL; struct timeval start; struct timeval end; @@ -635,10 +636,13 @@ static int http_callback(struct ast_tcptls_session_instance *ser, } response = ast_str_create(512); - if (!response) { + content_type_header = ast_str_create(32); + if (!response || !content_type_header) { goto err500; } + ast_str_set(&content_type_header, 0, "Content-Type: text/plain\r\n"); + start = ast_tvnow(); ast_mutex_lock(&scrape_lock); @@ -659,7 +663,7 @@ static int http_callback(struct ast_tcptls_session_instance *ser, } ast_mutex_unlock(&scrape_lock); - ast_http_send(ser, method, 200, "OK", NULL, response, 0, 0); + ast_http_send(ser, method, 200, "OK", content_type_header, response, 0, 0); return 0; @@ -678,14 +682,17 @@ err401: ast_http_send(ser, method, 401, "Unauthorized", auth_challenge_headers, NULL, 0, 1); } ast_free(response); + ast_free(content_type_header); return 0; err503: ast_http_send(ser, method, 503, "Service Unavailable", NULL, NULL, 0, 1); ast_free(response); + ast_free(content_type_header); return 0; err500: ast_http_send(ser, method, 500, "Server Error", NULL, NULL, 0, 1); ast_free(response); + ast_free(content_type_header); return 0; }