File tree Expand file tree Collapse file tree 4 files changed +48
-1
lines changed
Expand file tree Collapse file tree 4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 11from fastapi import FastAPI , HTTPException
2+ from prometheus_fastapi_instrumentator import Instrumentator
3+ from prometheus_client import Histogram
4+
25from catalog_api import schemas
36from catalog_api .solr_client import NotFoundError
47from catalog_api .record import record_for
710 title = "Catalog Search API" , description = "REST API for Catalog Search Solr"
811)
912
13+ Instrumentator ().instrument (app ).expose (app )
14+
15+ RECORD_HISTOGRAM = Histogram (
16+ "catalog_api_record_request_duration_seconds" ,
17+ "Length of api request for a catalog record" ,
18+ )
19+
1020
1121@app .get (
1222 "/records/{id}" ,
1828 },
1929 response_model_exclude_none = True ,
2030)
31+ @RECORD_HISTOGRAM .time ()
2132def get_record (id : str ) -> schemas .Record :
2233 """
2334 Gets a record from catalog solr. The record is fetched by the solr id, which
Original file line number Diff line number Diff line change 11import requests
22from requests .auth import HTTPBasicAuth
33from catalog_api .services import S
4+ from prometheus_client import Histogram
45
56
67class NotFoundError (Exception ):
78 pass
89
910
1011class SolrClient :
12+ SOLR_HISTOGRAM = Histogram (
13+ "catalog_api_solr_record_request_duration_seconds" , "Length of solr requests"
14+ )
15+
1116 def __init__ (self ) -> None :
1217 self .session = requests .Session ()
1318 self .base_url = f"{ S .solr_url } /solr/biblio"
1419 if S .solr_cloud_on :
1520 self .session .auth = HTTPBasicAuth (S .solr_user , S .solr_password )
1621
22+ @SOLR_HISTOGRAM .time ()
1723 def get_record (self , id : str ):
1824 params = {"q" : f"id:{ id } " }
1925 url = f"{ self .base_url } /select"
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ fastapi = "^0.115.11"
1818uvicorn = " ^0.34.0"
1919httpx = " ^0.28.1"
2020pymarc = " ^5.2.3"
21+ prometheus-fastapi-instrumentator = " ^7.1.0"
2122
2223
2324[tool .poetry .group .dev .dependencies ]
You can’t perform that action at this time.
0 commit comments