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
pull/1072/head
Sean Bright 3 months ago committed by asterisk-org-access-app[bot]
parent 6384e8667c
commit b460148163

@ -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;
}

Loading…
Cancel
Save