Coverage for chalicelib/core/metrics/custom_metrics.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 12:56 +0000

1from chalicelib.utils import helper, pg_client 

2 

3 

4def get_series_for_alert(project_id, user_id): 

5 with pg_client.PostgresClient() as cur: 

6 cur.execute( 

7 cur.mogrify( 

8 """SELECT series_id AS value, 

9 metrics.name || '.' || (COALESCE(metric_series.name, 'series ' || index)) || '.count' AS name, 

10 'count' AS unit, 

11 FALSE AS predefined, 

12 metric_id, 

13 series_id 

14 FROM metric_series 

15 INNER JOIN metrics USING (metric_id) 

16 WHERE metrics.deleted_at ISNULL 

17 AND metrics.project_id = %(project_id)s 

18 AND metrics.metric_type = 'timeseries' 

19 AND (user_id = %(user_id)s 

20 OR is_public) 

21 ORDER BY name;""", 

22 {"project_id": project_id, "user_id": user_id} 

23 ) 

24 ) 

25 rows = cur.fetchall() 

26 return helper.list_to_camel_case(rows)