Skip to content

Commit 4d9abbe

Browse files
authored
[Google-TI-Feeds] Add a prometheus counter for api calls (#6306)
1 parent e42dd11 commit 4d9abbe

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

external-import/google-ti-feeds/connector/src/utils/fetchers/generic_fetcher.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@
1313
from connector.src.utils.api_engine.api_client import ApiClient
1414
from connector.src.utils.api_engine.exceptions.api_network_error import ApiNetworkError
1515
from connector.src.utils.fetchers.generic_fetcher_config import GenericFetcherConfig
16+
from prometheus_client import Counter
1617

1718
LOG_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

2027
class 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,

0 commit comments

Comments
 (0)