Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-01 09:34:24

0001 from datetime import datetime, timezone
0002 from unittest.mock import patch
0003 
0004 from django.test import SimpleTestCase
0005 from django.template.loader import render_to_string
0006 
0007 from monitor_app.snapper_providers import (_delivery_curve_values,
0008                                            _delivery_focus_view,
0009                                            _delivery_groups,
0010                                            _epicprod_curve_values,
0011                                            _epicprod_scope_groups,
0012                                            _panda_card, _site_focus_view,
0013                                            _site_groups)
0014 
0015 
0016 class EpicprodCurveValuesTests(SimpleTestCase):
0017     @patch('monitor_app.snapper_providers._queue_stack_members',
0018            return_value=('QUEUE_A',))
0019     def test_ops_scope_omits_state_and_type_by_state_plots(self, _queues):
0020         names = [group['name'] for group in _epicprod_scope_groups()]
0021 
0022         self.assertNotIn('In-flight jobs', names)
0023         self.assertNotIn('Type × state', names)
0024         self.assertEqual(names, [
0025             'Running cores by queue', 'Job outcomes',
0026             'In-flight job types', 'Tasks',
0027         ])
0028 
0029     @patch('monitor_app.snapper_providers._pc_cache')
0030     def test_delivery_emits_per_pc_cumulative_curves(self, pc_cache):
0031         pc_cache.return_value = {
0032             'requestors': {'pc1': ['PWG']},
0033             'keys': {'pc1': 'configuration'},
0034             'categories': {'pc1': 'DIS'},
0035             'group_names': {'dis': 'DIS'},
0036         }
0037         state = {'components': {'delivery': {'data': {'campaigns': {
0038             '26.08': {
0039                 'totals': {'arrived_files': 3},
0040                 'leaves': {'pc1': {
0041                     'arrived_events': 12_000_000,
0042                     'arrived_files': 3,
0043                     'events': 80_000_000,
0044                     'cum_files': 20,
0045                 }},
0046             },
0047         }}}}}
0048 
0049         values = _delivery_curve_values(state)
0050 
0051         self.assertEqual(values['dlvpc_26_08_pc1'], 80.0)
0052         self.assertEqual(values['dlvpcf_26_08_pc1'], 20)
0053 
0054     @patch('swf_epicprod.analytics.rollup.resolve_target_campaigns',
0055            return_value=['26.08'])
0056     @patch('monitor_app.snapper_providers._pc_tick_groupings',
0057            return_value={})
0058     @patch('monitor_app.snapper_providers._pc_cache')
0059     def test_campaign_cumulative_categories_and_pcs_are_stacked(
0060             self, pc_cache, _pc_groups, _campaigns):
0061         pc_cache.return_value = {
0062             'categories': {'pc1': 'DIS', 'pc2': 'DIS', 'pc3': 'SIDIS'},
0063         }
0064 
0065         groups = {group['name']: group for group in _delivery_groups()}
0066 
0067         category = groups['Cumulative 26.08 files category']
0068         self.assertTrue(category['stacked'])
0069         self.assertTrue(category['default_off'])
0070         self.assertEqual(category['detail_key'],
0071                          'delivery-categories-26_08')
0072         self.assertFalse(
0073             groups['Cumulative 26.08 files requestor']['stacked'])
0074         dis = groups['Cumulative 26.08 files PCs DIS']
0075         self.assertTrue(dis['stacked'])
0076         self.assertTrue(dis['compact'])
0077         self.assertEqual(dis['ids'],
0078                          ['dlvpcf_26_08_pc1', 'dlvpcf_26_08_pc2'])
0079 
0080     @patch('swf_epicprod.analytics.rollup.resolve_target_campaigns',
0081            return_value=['26.08'])
0082     @patch('monitor_app.snapper_providers._campaign_delivery_starts',
0083            return_value={})
0084     @patch('monitor_app.snapper_providers._delivery_categories',
0085            return_value=('DIS', 'SIDIS'))
0086     def test_campaign_focus_orders_pc_panels_after_category_cumulative(
0087             self, _categories, _starts, _campaigns):
0088         focus = _delivery_focus_view()
0089         families = focus['options'][0]['families_by']['files|category']
0090 
0091         self.assertEqual(families, [
0092             'Arrivals 26.08 files',
0093             'Cumulative 26.08 files category',
0094             'Cumulative 26.08 files PCs DIS',
0095             'Cumulative 26.08 files PCs SIDIS',
0096         ])
0097 
0098     @patch('monitor_app.snapper_providers._panda_sites',
0099            return_value=('SITE_A',))
0100     def test_site_panels_are_stacked_with_cores_on_top(self, _sites):
0101         groups = {group['name']: group for group in _site_groups()}
0102 
0103         jobs = groups['Site jobs SITE_A']
0104         self.assertTrue(jobs['stacked'])
0105         self.assertEqual(jobs['order'][-2:],
0106                          ['sj_SITE_A_running', 'sjc_SITE_A'])
0107         self.assertEqual(jobs['default_off_ids'],
0108                          ['sj_SITE_A_activated'])
0109         for name in ('Site outcomes SITE_A', 'Site failures SITE_A',
0110                      'Site tasks SITE_A'):
0111             self.assertTrue(groups[name]['stacked'])
0112 
0113     @patch('monitor_app.snapper_providers._panda_sites',
0114            return_value=('SITE_A',))
0115     def test_site_focus_uses_a_panda_only_focus_series_product(self, _sites):
0116         focus = _site_focus_view()
0117 
0118         self.assertTrue(focus['cache_series'])
0119         self.assertEqual(focus['components'], ('panda',))
0120         self.assertFalse(focus['prewarm_series'])
0121 
0122     def test_sent_jobs_stay_in_state_but_not_plot_curves(self):
0123         state = {
0124             'components': {
0125                 'panda': {
0126                     'data': {
0127                         'jobs': {
0128                             'in_flight_now': {
0129                                 'running_cores': 16,
0130                                 'by_status': {
0131                                     'activated': 100,
0132                                     'sent': 40,
0133                                     'running': 10,
0134                                 },
0135                                 'by_type': {'epicproduction': 150},
0136                                 'by_type_status': {
0137                                     'epicproduction': {
0138                                         'activated': 100,
0139                                         'sent': 40,
0140                                         'running': 10,
0141                                     },
0142                                 },
0143                             },
0144                             'sites': {
0145                                 'SITE_A': {
0146                                     'by_status_now': {
0147                                         'activated': 100,
0148                                         'sent': 40,
0149                                         'running': 10,
0150                                     },
0151                                 },
0152                             },
0153                         },
0154                     },
0155                 },
0156             },
0157         }
0158 
0159         values = _epicprod_curve_values(state)
0160 
0161         self.assertNotIn('job_sent', values)
0162         self.assertNotIn('ts_epicproduction_sent', values)
0163         self.assertNotIn('sj_SITE_A_sent', values)
0164         self.assertEqual(values['type_epicproduction'], 10)
0165         self.assertEqual(values['job_running'], 10)
0166         self.assertEqual(values['ts_epicproduction_running'], 10)
0167         self.assertEqual(values['job_activated'], 100)
0168 
0169     def test_scope_cut_is_six_vertical_plot_aligned_tables(self):
0170         data = {
0171             'jobs': {
0172                 'cum': {'finished': 120, 'failed': 8},
0173                 'in_flight_now': {
0174                     'by_status': {
0175                         'activated': 100, 'sent': 40, 'starting': 20,
0176                         'holding': 2, 'running': 10,
0177                     },
0178                     'by_type': {'epicproduction': 172},
0179                     'by_type_status': {
0180                         'epicproduction': {
0181                             'activated': 100, 'sent': 40, 'starting': 20,
0182                             'holding': 2, 'running': 10,
0183                         },
0184                     },
0185                 },
0186                 'sites': {},
0187             },
0188             'tasks': {
0189                 'in_flight_now': {
0190                     'by_status': {'ready': 7, 'running': 3},
0191                 },
0192                 'sites': {},
0193             },
0194         }
0195         previous = {
0196             'jobs': {
0197                 'cum': {'finished': 115, 'failed': 7},
0198                 'in_flight_now': {
0199                     'by_status': {'holding': 1, 'running': 9},
0200                     'by_type_status': {
0201                         'epicproduction': {'holding': 1, 'running': 9},
0202                     },
0203                 },
0204             },
0205             'tasks': {'in_flight_now': {'by_status': {'running': 2}}},
0206         }
0207         card = _panda_card(data, previous, {
0208             'params': {},
0209             'since': datetime(2026, 8, 1, tzinfo=timezone.utc),
0210             'since_data': {'jobs': {'cum': {'finished': 100, 'failed': 5}}},
0211         })
0212         card.update({
0213             'name': 'panda',
0214             'template': 'monitor_app/_snapper_cards.html',
0215             'payload_json': '{}',
0216         })
0217 
0218         self.assertTrue(card['split_panels'])
0219         self.assertEqual(card['types'][0]['value'], 12)
0220         self.assertEqual([row['label'] for row in card['states']],
0221                          ['holding', 'running'])
0222         self.assertEqual([row['label'] for row in card['tasks']],
0223                          ['running'])
0224         self.assertEqual([row['value'] for row in card['outcomes']], [20, 3])
0225 
0226         html = render_to_string(
0227             'snapper_ai/_snapper_cut.html',
0228             {
0229                 'requested_at': None,
0230                 'cards': [{
0231                     'name': 'health', 'kind': 'health',
0232                     'chip': {'color': '#2e7d32', 'value': 'ok'},
0233                     'counts': {'ok': 5}, 'non_ok_checks': [],
0234                     'payload_json': '{}',
0235                 }, card],
0236             },
0237         )
0238         positions = [html.index(f'<strong>{title}</strong>') for title in (
0239             'Health', 'Queues', 'Outcomes', 'Types', 'States', 'Tasks')]
0240         self.assertEqual(positions, sorted(positions))
0241         self.assertIn('d-flex flex-column gap-3 align-items-stretch', html)
0242         self.assertNotIn('Type × state', html)
0243         self.assertNotIn('job_sent', html)