diff options
author | Tony Sun <tony.sun427@gmail.com> | 2021-04-12 22:34:01 -0700 |
---|---|---|
committer | Tony Sun <tony.sun427@gmail.com> | 2021-04-13 11:18:11 -0700 |
commit | f754fadb92e7d42a3fa25777953b3657f5b70649 (patch) | |
tree | 90498697205403b5925e3c9cb4558580bda69677 | |
parent | b4d355468d103746a38ab5806744d84fd2ea6481 (diff) | |
download | couchdb-f754fadb92e7d42a3fa25777953b3657f5b70649.tar.gz |
add prometheus versioning to header
-rw-r--r-- | src/chttpd/src/chttpd_node.erl | 4 | ||||
-rw-r--r-- | src/couch_prometheus/src/couch_prometheus.hrl | 1 | ||||
-rw-r--r-- | src/couch_prometheus/src/couch_prometheus_http.erl | 3 | ||||
-rw-r--r-- | 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 3c48459af..b6c4fac6c 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 383dbfeab..0970f4469 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 4edb53886..c123a3892 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 753e95351..e97df04a4 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) -> |