Skip to content

Commit

Permalink
[DISCO-2975] Add count metric for upstream accuweather requests (#622)
Browse files Browse the repository at this point in the history
* [DISCO-2975] Add count metric for upstream accuweather requests

* fix test

* fix enum typo

* fix enum typo in backend
  • Loading branch information
Herraj authored Sep 9, 2024
1 parent 6690fed commit 6e67609
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion merino/providers/weather/backends/accuweather/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ async def request_upstream(
- `HTTPError` upon HTTP request errors
- `AccuweatherError` upon cache write errors
"""
# increment the upstream request stat counter
self.metrics_client.increment(f"accuweather.upstream.request.{request_type}.get")
response_dict: dict[str, Any] | None

with self.metrics_client.timeit(
Expand Down Expand Up @@ -803,7 +805,7 @@ async def get_forecast(self, location_key: str) -> ForecastWithTTL | None:
params={
self.url_param_api_key: self.api_key,
},
request_type=RequestType.FORCASTS,
request_type=RequestType.FORECASTS,
process_api_response=process_forecast_response,
cache_ttl_sec=self.cached_forecast_ttl_sec,
)
Expand Down
2 changes: 1 addition & 1 deletion merino/providers/weather/backends/accuweather/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RequestType(StrEnum):

LOCATIONS = "locations"
CURRENT_CONDITIONS = "currentconditions"
FORCASTS = "forecasts"
FORECASTS = "forecasts"
AUTOCOMPLETE = "autocomplete"


Expand Down
6 changes: 4 additions & 2 deletions tests/unit/providers/weather/backends/test_accuweather.py
Original file line number Diff line number Diff line change
Expand Up @@ -1943,7 +1943,7 @@ def test_cache_key_for_accuweather_request(
@pytest.mark.parametrize(
("url", "expected_request_type"),
[
("/forecasts/v1/daily/1day/39376.json", RequestType.FORCASTS),
("/forecasts/v1/daily/1day/39376.json", RequestType.FORECASTS),
(
"/currentconditions/v1/39376.json",
RequestType.CURRENT_CONDITIONS,
Expand Down Expand Up @@ -2039,7 +2039,7 @@ async def test_get_request_cache_store_errors(
await accuweather.request_upstream(
url,
params={"apikey": "test"},
request_type=RequestType.FORCASTS,
request_type=RequestType.FORECASTS,
process_api_response=lambda a: cast(Optional[dict[str, Any]], a),
cache_ttl_sec=TEST_CACHE_TTL_SEC,
)
Expand All @@ -2055,6 +2055,7 @@ async def test_get_request_cache_store_errors(

increment_called = [call_arg[0][0] for call_arg in statsd_mock.increment.call_args_list]
assert [
f"accuweather.upstream.request.{RequestType.FORECASTS}.get",
"accuweather.cache.store.set_error",
] == increment_called

Expand Down Expand Up @@ -2312,6 +2313,7 @@ async def test_get_location_completion_with_invalid_accuweather_response(

metrics_called = [call_arg[0][0] for call_arg in statsd_mock.increment.call_args_list]
assert [
f"accuweather.upstream.request.{RequestType.AUTOCOMPLETE}.get",
f"accuweather.request.{RequestType.AUTOCOMPLETE}.processor.error",
] == metrics_called

Expand Down

0 comments on commit 6e67609

Please sign in to comment.