File tree Expand file tree Collapse file tree
external-import/google-ti-feeds/connector/src/utils/fetchers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313from connector .src .utils .api_engine .api_client import ApiClient
1414from connector .src .utils .api_engine .exceptions .api_network_error import ApiNetworkError
1515from connector .src .utils .fetchers .generic_fetcher_config import GenericFetcherConfig
16+ from prometheus_client import Counter
1617
1718LOG_PREFIX = "[GenericFetcher]"
1819
20+ _ENDPOINT_CALL_COUNTER = Counter (
21+ "google_ti_feeds_api_endpoint_calls" ,
22+ "Count of API calls made by GenericFetcher for each Google TI Feeds API endpoint" ,
23+ ["endpoint" ],
24+ )
25+
1926
2027class GenericFetcher :
2128 """Generic fetcher for any API endpoint with flexible response handling."""
@@ -43,6 +50,8 @@ def __init__(
4350 self .base_url = base_url
4451 self .logger = logger or logging .getLogger (__name__ )
4552
53+ self ._endpoint_counter : dict [str , Counter ] = {}
54+
4655 self .headers = {}
4756 if base_headers :
4857 self .headers .update (base_headers )
@@ -406,6 +415,14 @@ async def _make_api_call(
406415 },
407416 )
408417
418+ if self .config .endpoint not in self ._endpoint_counter :
419+ # Initialize a Prometheus counter for this endpoint if it doesn't exist
420+ self ._endpoint_counter [self .config .endpoint ] = (
421+ _ENDPOINT_CALL_COUNTER .labels (endpoint = self .config .endpoint )
422+ )
423+
424+ self ._endpoint_counter [self .config .endpoint ].inc ()
425+
409426 response = await self .api_client .call_api (
410427 url = endpoint ,
411428 method = self .config .method ,
You can’t perform that action at this time.
0 commit comments