File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
src/dstack/_internal/server Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -306,19 +306,31 @@ def _extract_project_name(request: Request):
306306
307307 return project_name
308308
309+ def _extract_endpoint_label (request : Request , response : Response ) -> str :
310+ route = request .scope .get ("route" )
311+ route_path = getattr (route , "path" , None )
312+ if route_path :
313+ return route_path
314+ if not request .url .path .startswith ("/api/" ):
315+ return "__non_api__"
316+ if response .status_code == status .HTTP_404_NOT_FOUND :
317+ return "__not_found__"
318+ return "__unmatched__"
319+
309320 project_name = _extract_project_name (request )
310321 response : Response = await call_next (request )
322+ endpoint_label = _extract_endpoint_label (request , response )
311323
312324 REQUEST_DURATION .labels (
313325 method = request .method ,
314- endpoint = request . url . path ,
326+ endpoint = endpoint_label ,
315327 http_status = response .status_code ,
316328 project_name = project_name ,
317329 ).observe (request .state .process_time )
318330
319331 REQUESTS_TOTAL .labels (
320332 method = request .method ,
321- endpoint = request . url . path ,
333+ endpoint = endpoint_label ,
322334 http_status = response .status_code ,
323335 project_name = project_name ,
324336 ).inc ()
Original file line number Diff line number Diff line change 2525async def get_prometheus_metrics (
2626 session : Annotated [AsyncSession , Depends (get_session )],
2727) -> str :
28+ # Note: Prometheus warns against storing high cardinality values in labels,
29+ # yet both client and custom metrics have labels like project, run, fleet, etc.
30+ # This may require a very big Prometheus server with lots of storage.
2831 if not settings .ENABLE_PROMETHEUS_METRICS :
2932 raise error_not_found ()
3033 custom_metrics_ = await custom_metrics .get_metrics (session = session )
You can’t perform that action at this time.
0 commit comments