Exemplo n.º 1
0
    def test_temporary_file_assign_to_logtype(self, test_name):
        input_path, original_log_file, path, result_log_file, results_yaml_file = self._prepare_files_path(
            test_name)
        effect_line_offset, line_content = self._gather_effect_line_data(
            input_path, original_log_file)

        whylog_config = self._prepare_config(path)
        log_reader = LogReader(whylog_config)
        effect_line = FrontInput(
            effect_line_offset, line_content,
            LineSource(
                'localhost',
                os.path.join(path, self._get_starting_file_name(input_path))))

        node1_source = LineSource('localhost',
                                  os.path.join(path, 'node_1.log'))
        node2_source = LineSource('localhost',
                                  os.path.join(path, 'node_2.log'))
        node3_source = LineSource('localhost',
                                  os.path.join(path, 'node_3.log'))
        temp_assign = {AbstractConfig.DEFAULT_LOG_TYPE: [node1_source]}
        if test_name == "010_multiple_files":
            temp_assign = {
                AbstractConfig.DEFAULT_LOG_TYPE: [node1_source, node2_source]
            }
        if test_name == "011_different_entry":
            temp_assign = {
                AbstractConfig.DEFAULT_LOG_TYPE:
                [node1_source, node2_source, node3_source]
            }

        results = log_reader.get_causes(effect_line, temp_assign)
        expected_results = self._investigation_results_from_yaml(
            results_yaml_file, result_log_file)
        self._check_results(results, expected_results)
Exemplo n.º 2
0
    def tests_whylog_factory(self):
        log_reader, teacher_generator, config = whylog_factory()
        teacher = teacher_generator()

        front_input = FrontInput(1, 'line content', LineSource('host', 'path'))
        teacher.add_line(0, front_input, True)
        self.assertRaises(NoLogTypeError, log_reader.get_causes, front_input)
        config.get_log_type(front_input.line_source)
Exemplo n.º 3
0
 def test_update_by_pattern(self):
     ra = RegexAssistant()
     line = "Hello, Whylog guy!"
     line_id = 1
     ra.add_line(line_id, FrontInput(0, line, 0))
     unlikely_regex = r'^Hello, (Whylog (team|guy)!)$'
     assert not ra.regex_matches[line_id].regex == unlikely_regex
     ra.update_by_pattern(line_id, unlikely_regex)
     assert ra.regex_matches[line_id].regex == unlikely_regex
Exemplo n.º 4
0
    def setUp(self):
        """
        Creates teacher with sample Rule.
        """
        test_files_dir = 'empty_config_files'
        path = os.path.join(*path_test_files + [test_files_dir])
        parsers_path, rules_path, log_types_path = ConfigPathFactory.get_path_to_config_files(
            path, False
        )

        self.test_files = [parsers_path, rules_path, log_types_path]
        self._clean_test_files()

        yaml_config = YamlConfig(parsers_path, rules_path, log_types_path)
        regex_assistant = RegexAssistant()
        self.teacher = Teacher(yaml_config, regex_assistant)

        self.effect_id = 0
        self.effect_front_input = FrontInput(
            offset=42,
            line_content=r'2015-12-03 12:11:00 Error occurred in reading test',
            line_source=LineSource('sample_host', 'sample_path')
        )

        self.cause1_id = 1
        self.cause1_front_input = FrontInput(
            offset=30,
            line_content=r'2015-12-03 12:10:55 Data is missing on comp21',
            line_source=LineSource('sample_host1', 'sample_path1')
        )

        self.cause2_id = 2
        self.cause2_front_input = FrontInput(
            offset=21,
            line_content=r'2015-12-03 12:10:50 Data migration to comp21 failed in test 123',
            line_source=LineSource('sample_host2', 'sample_path2')
        )

        self.identical_groups = [(self.cause1_id, 2), (self.cause2_id, 2)]
        self.date_groups = [(self.effect_id, 1), (self.effect_id, 1)]

        self._add_rule()
Exemplo n.º 5
0
 def _investigation_results_from_yaml(self, yaml_file, real_log_file):
     file_content = yaml.load(open(yaml_file))
     results = []
     for result in file_content:
         causes = [
             FrontInput(
                 self._deduce_line_offset_by_unique_content(real_log_file, line_str), line_str,
                 LineSource("localhost", real_log_file)
             ) for line_str in result['causes']
         ]  # yapf: disable
         results.append(
             InvestigationResult(causes, result['constraints'],
                                 result['linkage']))
     return results
Exemplo n.º 6
0
 def test_guess_pattern_matches(self):
     line = r'2015-12-03 or [10/Oct/1999 21:15:05 +0500] "GET /index.html HTTP/1.0" 200 1043'
     front_input = FrontInput(0, line, 0)
     line_id = 1
     ra = RegexAssistant()
     ra.add_line(line_id, front_input)
     pattern_matches = ra.guess_pattern_matches(line_id)
     assert pattern_matches
     guessed_regexes = [
         pattern_match.pattern
         for pattern_match in pattern_matches.values()
     ]
     for guessed_regex in guessed_regexes:
         self.verify_regex_match(guessed_regex, line)
Exemplo n.º 7
0
 def test_creatig_effect_clues(self):
     #TODO: add some line source assert when FrontInput will contains LineSource or something like that
     offset = 42
     front_input = FrontInput(offset, self.lost_data_line, None)
     effect_params = {
         'lostdata': ("2015-12-03 12:11:00", "alfa21", "567.02", "101")
     }
     clues = self.simple_config._create_effect_clues(
         effect_params, front_input)
     assert len(clues) == 1
     clue = clues['lostdata']
     assert clue.regex_parameters == (datetime(2015, 12, 3, 12, 11),
                                      'alfa21', '567.02', '101')
     assert clue.line_offset == offset
     assert clue.line_prefix_content == self.lost_data_line
Exemplo n.º 8
0
    def test_one(self, test_name):
        input_path, original_log_file, path, result_log_file, results_yaml_file = self._prepare_files_path(
            test_name)
        effect_line_offset, line_content = self._gather_effect_line_data(
            input_path, original_log_file)

        # preparing Whylog structures, normally prepared by Front
        whylog_config = YamlConfig(
            *ConfigPathFactory.get_path_to_config_files(path))
        log_reader = LogReader(whylog_config)
        effect_line = FrontInput(
            effect_line_offset, line_content,
            LineSource(
                'localhost',
                os.path.join(path, self._get_starting_file_name(input_path))))

        results = log_reader.get_causes(effect_line)
        expected_results = self._investigation_results_from_yaml(
            results_yaml_file, result_log_file)
        self._check_results(results, expected_results)