From 1ada0e6a03a2d15ec557d46669424866a0874cc2 Mon Sep 17 00:00:00 2001 From: Vicky Date: Tue, 5 Jul 2022 15:37:58 -0400 Subject: [PATCH] add success true and false metrics w prometheus --- .../src/tasks/update_track_is_available.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/discovery-provider/src/tasks/update_track_is_available.py b/discovery-provider/src/tasks/update_track_is_available.py index 8c2ac17f043..17762acaeca 100644 --- a/discovery-provider/src/tasks/update_track_is_available.py +++ b/discovery-provider/src/tasks/update_track_is_available.py @@ -229,16 +229,15 @@ def update_track_is_available(self) -> None: have_lock = update_lock.acquire(blocking=False) if have_lock: - metric = None + metric = PrometheusMetric( + "update_track_is_available_duration_seconds", + "Runtimes for src.task.update_track_is_available:celery.task()", + ("task_name", "success"), + ) try: - metric = PrometheusMetric( - "update_track_is_available_duration_seconds", - "Runtimes for src.task.update_track_is_available:celery.task()", - ("task_name",), - ) - # TODO: we can deprecate this manual redis timestamp tracker once we confirm - # that prometheus works in tracking duration + # that prometheus works in tracking duration. Needs to be removed from + # the health check too redis.set( UPDATE_TRACK_IS_AVAILABLE_START_REDIS_KEY, datetime.now(tz=timezone.utc).strftime("%Y-%m-%d %H:%M:%S.%f %Z"), @@ -248,15 +247,19 @@ def update_track_is_available(self) -> None: fetch_unavailable_track_ids_in_network(session, redis) update_tracks_is_available_status(db, redis) + + metric.save_time( + {"task_name": "update_track_is_available", "success": "true"} + ) except Exception as e: + metric.save_time( + {"task_name": "update_track_is_available", "success": "false"} + ) logger.error( "update_track_is_available.py | Fatal error in main loop", exc_info=True ) raise e finally: - if metric is not None: - metric.save_time({"task_name": "update_track_is_available"}) - # TODO: see comment above about deprecation redis.set( UPDATE_TRACK_IS_AVAILABLE_FINISH_REDIS_KEY,