def mocked_investigation_plan():
    super_parser = RegexSuperParser('^(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d).*', [1], {1: 'date'})
    matcher = WildCardFilenameMatcher('localhost', 'node_1.log', 'default', super_parser)
    default_log_type = LogType('default', [matcher])
    cause = RegexParser(
        'cause', '2015-12-03 12:08:08 root cause',
        '^(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d) root cause$', [1], 'default', {1: 'date'}
    )
    effect = RegexParser(
        'effect', '2015-12-03 12:08:09 visible effect',
        '^(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d) visible effect$', [1], 'default', {1: 'date'}
    )
    concatenated = ConcatenatedRegexParser([cause])
    effect_time = datetime(2015, 12, 3, 12, 8, 9)
    search_range = {
        'default': {
            'date': {
                'left_bound': datetime(2015, 12, 3, 12, 8, 8),
                'right_bound': effect_time
            }
        }
    }
    default_investigation_step = InvestigationStep(concatenated, search_range)
    rule = Rule(
        [cause], effect, [
            {
                'clues_groups': [[1, 1], [0, 1]],
                'name': 'time',
                'params': {'max_delta': 1}
            }
        ], Rule.LINKAGE_AND
    )  # yapf: disable
    line_source = LineSource('localhost', 'node_1.log')
    effect_clues = {'effect': Clue((effect_time,), 'visible effect', 40, line_source)}
    return InvestigationPlan([rule], [(default_investigation_step, default_log_type)], effect_clues)
示例#2
0
 def setUp(cls):
     search_ranges = {
         'date': {
             InvestigationStep.LEFT_BOUND: datetime(2015, 12, 3, 12, 8, 0),
             InvestigationStep.RIGHT_BOUND: datetime(2015, 12, 3, 12, 8, 11)
         }
     }  # yapf: disable
     cls.investigation_step = InvestigationStep(None, search_ranges)
示例#3
0
 def _create_steps_in_investigation(self, concatenated_parsers,
                                    suspected_rules, effect_clues):
     steps = []
     search_ranges = self._get_search_ranges(suspected_rules, effect_clues)
     for log_type_name, parser in six.iteritems(concatenated_parsers):
         log_type = self._log_types[log_type_name]
         investigation_step = InvestigationStep(
             parser, search_ranges.get(log_type_name, {}))
         steps.append((investigation_step, log_type))
     return steps
示例#4
0
    def test_bisect_last_line_of_file(self):
        investigation_step = InvestigationStep(
            None, {
                'date': {
                    InvestigationStep.LEFT_BOUND: self.dummy_date,
                    InvestigationStep.RIGHT_BOUND: datetime.max
                }
            })

        backtracker = BacktrackSearcher("", investigation_step,
                                        self.super_parser)
        offset = backtracker._find_right(self.opened_file)

        assert offset == self.number_of_lines * self.line_padding
        assert self.opened_file._seek_count < 35
示例#5
0
    def test_bisect_first_line_of_file(self):
        investigation_step = InvestigationStep(
            None, {
                'date': {
                    InvestigationStep.LEFT_BOUND: datetime.min,
                    InvestigationStep.RIGHT_BOUND: self.dummy_date
                }
            })

        backtracker = BacktrackSearcher("", investigation_step,
                                        self.super_parser)
        offset = backtracker._find_left(self.opened_file)

        assert offset == 0
        assert self.opened_file._seek_count < 35
示例#6
0
    def test_bisect_line_finding(self):
        secs = 3
        date = datetime(year=2000, month=1, day=1, second=secs)

        investigation_step = InvestigationStep(
            None, {
                'date': {
                    InvestigationStep.LEFT_BOUND: date,
                    InvestigationStep.RIGHT_BOUND: self.dummy_date
                }
            })

        backtracker = BacktrackSearcher("", investigation_step,
                                        self.super_parser)
        offset = backtracker._find_left(self.opened_file)

        assert offset == secs * self.line_padding
        assert self.opened_file._seek_count < 35
示例#7
0
    def test_bisect_right_when_lines_are_repeated(self):
        secs = 3
        date = datetime(year=2000, month=1, day=1, second=secs)

        investigation_step = InvestigationStep(
            None, {
                'date': {
                    InvestigationStep.LEFT_BOUND: self.dummy_date,
                    InvestigationStep.RIGHT_BOUND: date
                }
            })

        backtracker = BacktrackSearcher("", investigation_step,
                                        self.super_parser)
        offset = backtracker._find_right(self.file_with_repeated_lines)

        line_no = (secs + 1) * self.repetitions
        assert offset == line_no * self.line_padding
        assert self.file_with_repeated_lines._seek_count < 35