AWeber-Imbi / imbi

An operational management platform for medium to large environments
BSD 3-Clause "New" or "Revised" License
2 stars 12 forks source link

Add project fact type based on SQL query #103

Open dave-shawley opened 3 months ago

dave-shawley commented 3 months ago

We were discussing how to add a project fact that tracks the number of recent restarts as an indicator of quality recently. It would be trivial to implement if we had a way to periodically run

SELECT COUNT(o.id)
  FROM v1.operations_log AS o
 WHERE o.project_id = %(project_id)s
   AND o.change_type = 'Restarted'
   AND o.recorded_at > CURRENT_TIMESTAMP - INTERVAL '14d'

and assign the value to the Recent Restart Count fact.

This shouldn't be too difficult to implement... without thinking too hard about it:

  1. add a new fact type named query -- current values are enum, range, & free-form
  2. create v1.project_fact_types_query to hold the query and frequency
  3. add a periodic task somewhere that runs queries for projects with a "query" fact type -- pgcron?
  4. add necessary CRUD to the Admin UI