Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@
from connector.src.utils.api_engine.api_client import ApiClient
from connector.src.utils.api_engine.exceptions.api_network_error import ApiNetworkError
from connector.src.utils.fetchers.generic_fetcher_config import GenericFetcherConfig
from prometheus_client import Counter

LOG_PREFIX = "[GenericFetcher]"

_ENDPOINT_CALL_COUNTER = Counter(
"google_ti_feeds_api_endpoint_calls",
"Count of API calls made by GenericFetcher for each Google TI Feeds API endpoint",
["endpoint"],
)


class GenericFetcher:
"""Generic fetcher for any API endpoint with flexible response handling."""
Expand Down Expand Up @@ -43,6 +50,8 @@ def __init__(
self.base_url = base_url
self.logger = logger or logging.getLogger(__name__)

self._endpoint_counter: dict[str, Counter] = {}

self.headers = {}
if base_headers:
self.headers.update(base_headers)
Expand Down Expand Up @@ -406,6 +415,14 @@ async def _make_api_call(
},
)

if self.config.endpoint not in self._endpoint_counter:
# Initialize a Prometheus counter for this endpoint if it doesn't exist
self._endpoint_counter[self.config.endpoint] = (
_ENDPOINT_CALL_COUNTER.labels(endpoint=self.config.endpoint)
)

self._endpoint_counter[self.config.endpoint].inc()

response = await self.api_client.call_api(
url=endpoint,
method=self.config.method,
Expand Down
Loading