def report_event(body, spec, logger, **kwargs): metadata = body['metadata'] if kwargs["type"] not in ['ADDED', 'MODIFIED']: return configurations = retrieve_configurations_from_API() if not configurations: raise utils.ConfigurationMissing( 'Bad response from API, no configuration found.' ) begin = rated_or_not(metadata['name']) configs = tuple(ts['valid_from'] for ts in configurations) choosen_config = get_closest_configs_bisect( begin.strftime('%s'), configs) table = kwargs['status'].get('tableRef') if not table: return metric_config = check_rating_conditions(metadata['name'], table['name'], begin, configurations[choosen_config]) if not metric_config: return logger.info(f'using config with timestamp {configs[choosen_config]}') logger.info( 'rating for {metric} in {table} for period {begin} to {end} started..' .format(metric=metric_config['metric'], table=metric_config['presto_table'], begin=metric_config['begin'], end=metric_config['end']) ) rules.ensure_rules_config(configurations[choosen_config]['rules']['rules']) rated_metrics.retrieve_data( configurations[choosen_config]['rules']['rules'], metric_config, logger)
def test_find_closest_timestamp_bisect_begin(self): timestamp = 250 result = get_closest_configs_bisect(timestamp, self.timestamps) self.assertEqual(result, 1)
def test_find_closest_timestamp_bisect_one(self): timestamp = 1 result = get_closest_configs_bisect(timestamp, self.timestamps) self.assertEqual(result, 0)
def test_find_in_small(self): timestamps = (0, 1576663550, 1576675754, 1576678772) timestamp = 1576672457 result = get_closest_configs_bisect(timestamp, timestamps) self.assertEqual(result, 2)
def test_find_closest_timestamp_bisect_over(self): timestamp = 19231123123 result = get_closest_configs_bisect(timestamp, self.timestamps) self.assertEqual(result, 9999)
def test_find_closest_timestamp_bisect_last(self): timestamp = 100000 result = get_closest_configs_bisect(timestamp, self.timestamps) self.assertEqual(result, 100)
def test_find_closest_timestamp_bisect_middle(self): timestamp = 694200 result = get_closest_configs_bisect(timestamp, self.timestamps) self.assertEqual(result, 695)