Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add success true and false metrics w prometheus #3382

Merged
merged 1 commit into from
Jul 5, 2022
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
25 changes: 14 additions & 11 deletions discovery-provider/src/tasks/update_track_is_available.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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,
Expand Down