You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by to...@apache.org on 2021/04/14 00:23:47 UTC
[couchdb] 04/05: add prometheus versioning to header
This is an automated email from the ASF dual-hosted git repository.
tonysun83 pushed a commit to branch port-prometheus-3.x
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 68382c2cc1b4c001897c8a4f6b3a19398fb2d614
Author: Tony Sun <to...@gmail.com>
AuthorDate: Mon Apr 12 22:34:01 2021 -0700
add prometheus versioning to header
---
src/chttpd/src/chttpd_node.erl | 4 +++-
src/couch_prometheus/src/couch_prometheus.hrl | 1 +
src/couch_prometheus/src/couch_prometheus_http.erl | 3 ++-
src/couch_prometheus/src/couch_prometheus_server.erl | 6 +++++-
4 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl
index 063ef4b..848ca69 100644
--- a/src/chttpd/src/chttpd_node.erl
+++ b/src/chttpd/src/chttpd_node.erl
@@ -119,7 +119,9 @@ handle_node_req(#httpd{path_parts=[_, _Node, <<"_stats">>]}=Req) ->
send_method_not_allowed(Req, "GET");
handle_node_req(#httpd{method='GET', path_parts=[_, Node, <<"_prometheus">>]}=Req) ->
Metrics = call_node(Node, couch_prometheus_server, scrape, []),
- Header = [{<<"Content-Type">>, <<"text/plain">>}],
+ Version = call_node(Node, couch_prometheus_server, version, []),
+ Type = "text/plain; version=" ++ Version,
+ Header = [{<<"Content-Type">>, ?l2b(Type)}],
chttpd:send_response(Req, 200, Header, Metrics);
handle_node_req(#httpd{path_parts=[_, _Node, <<"_prometheus">>]}=Req) ->
send_method_not_allowed(Req, "GET");
diff --git a/src/couch_prometheus/src/couch_prometheus.hrl b/src/couch_prometheus/src/couch_prometheus.hrl
index 383dbfe..0970f44 100644
--- a/src/couch_prometheus/src/couch_prometheus.hrl
+++ b/src/couch_prometheus/src/couch_prometheus.hrl
@@ -11,4 +11,5 @@
% the License.
-define(REFRESH_INTERVAL, 5).
+-define(PROMETHEUS_VERSION, "2.0").
diff --git a/src/couch_prometheus/src/couch_prometheus_http.erl b/src/couch_prometheus/src/couch_prometheus_http.erl
index 4edb538..c123a38 100644
--- a/src/couch_prometheus/src/couch_prometheus_http.erl
+++ b/src/couch_prometheus/src/couch_prometheus_http.erl
@@ -48,8 +48,9 @@ handle_request(MochiReq) ->
end.
send_prometheus(MochiReq, Node) ->
+ Type = "text/plain; version=" ++ ?PROMETHEUS_VERSION,
Headers = couch_httpd:server_header() ++ [
- {<<"Content-Type">>, <<"text/plain">>}
+ {<<"Content-Type">>, ?l2b(Type)}
],
Body = call_node(Node, couch_prometheus_server, scrape, []),
send_resp(MochiReq, 200, Headers, Body).
diff --git a/src/couch_prometheus/src/couch_prometheus_server.erl b/src/couch_prometheus/src/couch_prometheus_server.erl
index 753e953..e97df04 100644
--- a/src/couch_prometheus/src/couch_prometheus_server.erl
+++ b/src/couch_prometheus/src/couch_prometheus_server.erl
@@ -21,7 +21,8 @@
]).
-export([
- scrape/0
+ scrape/0,
+ version/0
]).
-export([
@@ -53,6 +54,9 @@ scrape() ->
{ok, Metrics} = gen_server:call(?MODULE, scrape),
Metrics.
+version() ->
+ ?PROMETHEUS_VERSION.
+
handle_call(scrape, _from, #st{metrics = Metrics}=State) ->
{reply, {ok, Metrics}, State};
handle_call(refresh, _from, #st{refresh=OldRT} = State) ->