File tree Expand file tree Collapse file tree 4 files changed +9
-1
lines changed Expand file tree Collapse file tree 4 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1818- Fix OpenAPI broken docs link by @taimoorzaeem in #4080
1919- Fix OpenAPI specification incorrectly exposing GET methods for volatile functions by @joelonsql in #4174
2020- Fix empty spread embeddings return unexpected SQL error by @taimoorzaeem in #3887
21+ - Fix ` /metrics ` endpoint not responding with ` Content-Type ` header by @taimoorzaeem in #4271
2122
2223### Changed
2324
Original file line number Diff line number Diff line change @@ -128,6 +128,11 @@ The ``metrics`` endpoint on the :ref:`admin_server` endpoint provides metrics in
128128
129129 curl " http://localhost:3001/metrics"
130130
131+ .. code-block :: http
132+
133+ HTTP/1.1 200 OK
134+ Content-Type: text/plain; charset=utf-8
135+
131136 # HELP pgrst_schema_cache_query_time_seconds The query time in seconds of the last schema cache load
132137 # TYPE pgrst_schema_cache_query_time_seconds gauge
133138 pgrst_schema_cache_query_time_seconds 1.5937927e-2
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import Network.Socket.ByteString
1616
1717import PostgREST.AppState (AppState )
1818import PostgREST.Config (AppConfig (.. ))
19+ import PostgREST.MediaType (MediaType (.. ), toContentType )
1920import PostgREST.Metrics (metricsToText )
2021import PostgREST.Network (resolveHost )
2122import PostgREST.Observation (Observation (.. ))
@@ -58,7 +59,7 @@ admin appState req respond = do
5859 respond $ Wai. responseLBS HTTP. status200 [] (maybe mempty JSON. encode sCache)
5960 [" metrics" ] -> do
6061 mets <- metricsToText
61- respond $ Wai. responseLBS HTTP. status200 [] mets
62+ respond $ Wai. responseLBS HTTP. status200 [toContentType MTTextPlain ] mets -- Content-Type is required for prometheus compliance
6263 _ ->
6364 respond $ Wai. responseLBS HTTP. status404 [] mempty
6465
Original file line number Diff line number Diff line change @@ -1730,6 +1730,7 @@ def test_admin_metrics(defaultenv):
17301730 with run (env = defaultenv , port = freeport ()) as postgrest :
17311731 response = postgrest .admin .get ("/metrics" )
17321732 assert response .status_code == 200
1733+ assert response .headers ["Content-Type" ] == "text/plain; charset=utf-8"
17331734 assert "pgrst_schema_cache_query_time_seconds" in response .text
17341735 assert 'pgrst_schema_cache_loads_total{status="SUCCESS"}' in response .text
17351736 assert "pgrst_db_pool_max" in response .text
You can’t perform that action at this time.
0 commit comments