Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-28 07:24:56

0001 """Seed the `swf-alarms` context and two initial alarm configs."""
0002 from __future__ import annotations
0003 
0004 import time
0005 import uuid
0006 
0007 from django.db import migrations
0008 
0009 
0010 CONTEXT_NAME = 'swf-alarms'
0011 
0012 ALARM_CONFIGS = [
0013     {
0014         'title': "PanDA task failure rate — Sakib's tasks",
0015         'data': {
0016             'entry_id': 'alarm_panda_failure_rate_sakib',
0017             'enabled': True,
0018             'severity': 'warning',
0019             'recipients': ['srahman1@bnl.gov', 'wenaus@gmail.com'],
0020             'renotification_window_hours': 24,
0021             'params': {
0022                 'threshold': 0.03,
0023                 'since_days': 1,
0024                 'username': 'Sakib Rahman',
0025                 'min_terminal_jobs': 5,
0026             },
0027         },
0028         'content': (
0029             "Alert on PanDA tasks owned by Sakib Rahman whose computed "
0030             "failure rate exceeds the configured threshold over the "
0031             "configured window. Threshold, window, and minimum terminal "
0032             "jobs are in the Check params below.\n"
0033             "\n"
0034             "Dashboard: https://epic-devcloud.org/prod/alarms/\n"
0035         ),
0036     },
0037     {
0038         'title': 'PanDA task failure rate — catch-all',
0039         'data': {
0040             'entry_id': 'alarm_panda_failure_rate_eic_all',
0041             'enabled': True,
0042             'severity': 'info',
0043             'recipients': ['wenaus@gmail.com'],
0044             'renotification_window_hours': 48,
0045             'params': {
0046                 'threshold': 0.05,
0047                 'since_days': 1,
0048                 'min_terminal_jobs': 5,
0049             },
0050         },
0051         'content': (
0052             "Catch-all alert on any PanDA task whose computed failure rate "
0053             "exceeds the configured threshold over the configured window. "
0054             "Torre-only tuning channel for shaping future per-owner "
0055             "alarms. Threshold and window live in the Check params below.\n"
0056         ),
0057     },
0058 ]
0059 
0060 
0061 def seed(apps, schema_editor):
0062     Entry = apps.get_model('remote_app', 'Entry')
0063     EntryContext = apps.get_model('remote_app', 'EntryContext')
0064     now = time.time()
0065 
0066     ctx, _ = EntryContext.objects.get_or_create(
0067         name=CONTEXT_NAME,
0068         defaults={
0069             'title': 'swf-alarms',
0070             'description': 'Alarm configs, firings, and engine-run records.',
0071             'timestamp_created': now,
0072             'timestamp_modified': now,
0073         },
0074     )
0075     for cfg in ALARM_CONFIGS:
0076         eid = cfg['data']['entry_id']
0077         if Entry.objects.filter(context=ctx, kind='alarm',
0078                                 data__entry_id=eid).exists():
0079             continue
0080         Entry.objects.create(
0081             id=str(uuid.uuid4()),
0082             title=cfg['title'],
0083             content=cfg['content'],
0084             kind='alarm',
0085             context=ctx,
0086             data=cfg['data'],
0087             status='active',
0088             archived=False,
0089             timestamp_created=now,
0090             timestamp_modified=now,
0091         )
0092 
0093 
0094 def unseed(apps, schema_editor):
0095     Entry = apps.get_model('remote_app', 'Entry')
0096     EntryContext = apps.get_model('remote_app', 'EntryContext')
0097     Entry.objects.filter(context__name=CONTEXT_NAME).delete()
0098     EntryContext.objects.filter(name=CONTEXT_NAME).delete()
0099 
0100 
0101 class Migration(migrations.Migration):
0102     dependencies = [('remote_app', '0001_initial')]
0103     operations = [migrations.RunPython(seed, unseed)]