From 6e676097642b4007d7dcba46c389b0a19f520c02 Mon Sep 17 00:00:00 2001 From: Herraj Luhano Date: Mon, 9 Sep 2024 17:32:01 -0400 Subject: [PATCH] [DISCO-2975] Add count metric for upstream accuweather requests (#622) * [DISCO-2975] Add count metric for upstream accuweather requests * fix test * fix enum typo * fix enum typo in backend --- merino/providers/weather/backends/accuweather/backend.py | 4 +++- merino/providers/weather/backends/accuweather/utils.py | 2 +- tests/unit/providers/weather/backends/test_accuweather.py | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/merino/providers/weather/backends/accuweather/backend.py b/merino/providers/weather/backends/accuweather/backend.py index 13e1392ad..0a5c2d9e8 100644 --- a/merino/providers/weather/backends/accuweather/backend.py +++ b/merino/providers/weather/backends/accuweather/backend.py @@ -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( @@ -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, ) diff --git a/merino/providers/weather/backends/accuweather/utils.py b/merino/providers/weather/backends/accuweather/utils.py index aa39220a8..983ebd4e5 100644 --- a/merino/providers/weather/backends/accuweather/utils.py +++ b/merino/providers/weather/backends/accuweather/utils.py @@ -19,7 +19,7 @@ class RequestType(StrEnum): LOCATIONS = "locations" CURRENT_CONDITIONS = "currentconditions" - FORCASTS = "forecasts" + FORECASTS = "forecasts" AUTOCOMPLETE = "autocomplete" diff --git a/tests/unit/providers/weather/backends/test_accuweather.py b/tests/unit/providers/weather/backends/test_accuweather.py index 6109dc1f1..49030d127 100644 --- a/tests/unit/providers/weather/backends/test_accuweather.py +++ b/tests/unit/providers/weather/backends/test_accuweather.py @@ -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, @@ -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, ) @@ -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 @@ -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