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 monitoring endpoint for oldest task in a given status #1076

Merged
merged 1 commit into from
Feb 21, 2025

Conversation

benoit74
Copy link
Collaborator

@benoit74 benoit74 commented Feb 20, 2025

Rationale

Add an endpoint which can be called from UptimeRobot to e.g. monitor oldest running task

Changes

  • add a generic /status/{monitor_name} endpoint
  • implement a first monitor oldest_task_older_than which takes two parameters (as query string):
    • status: a task status which has an associated timestamp, e.g. scraper_started, scraper_completed, cancel_requested
    • threshold_secs: a threshold which cause the monitor to fail if oldest task is older than this threshold, in seconds
    • returns a textual answer with HTTP code 200 and details if monitor succeeded to run:
      • e.g. oldest_task for scraper_started and 500s: OK or oldest_task for scraper_started and 5s: KO
    • returns HTTP code 400 on bad requests
  • update (manually 🤢) OpenAPI spec
  • add automated tests
    • slightly modify test fixtures so that tasks have timestamp a bit in the past (we didn't cared about their values so far)

The : KO or : OK strings can be searched for in UptimeRobot KW probe. Always returning 200 even in case of "problem" is deemed more appropriate to respect HTTP paradigms and allows to more easily differentiate a buggy API from a down monitor.

@benoit74 benoit74 self-assigned this Feb 20, 2025
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.49%. Comparing base (7aaa114) to head (02a4a48).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1076      +/-   ##
==========================================
+ Coverage   88.38%   88.49%   +0.11%     
==========================================
  Files          98      101       +3     
  Lines        5482     5538      +56     
==========================================
+ Hits         4845     4901      +56     
  Misses        637      637              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@benoit74 benoit74 force-pushed the monitoring_tasks branch 2 times, most recently from 02ffdf8 to bc7fb77 Compare February 20, 2025 16:59
@benoit74 benoit74 marked this pull request as ready for review February 20, 2025 17:01
@benoit74 benoit74 requested a review from rgaudin February 20, 2025 17:01
Copy link
Member

@rgaudin rgaudin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good ; cleanup the commented code first though

@benoit74
Copy link
Collaborator Author

🤦🏻‍♂️thank you

@benoit74 benoit74 merged commit dad1613 into main Feb 21, 2025
7 checks passed
@benoit74 benoit74 deleted the monitoring_tasks branch February 21, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants