1 |
commit: b2f1c115420e05c27fb7a57cf45734cb7f4a7731 |
2 |
Author: Magnus Granberg <zorry <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Apr 26 20:26:04 2021 +0000 |
4 |
Commit: Magnus Granberg <zorry <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Apr 26 20:26:04 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/tinderbox-cluster.git/commit/?id=b2f1c115 |
7 |
|
8 |
Add more checks and move * and >>> check to last |
9 |
|
10 |
Signed-off-by: Magnus Granberg <zorry <AT> gentoo.org> |
11 |
|
12 |
buildbot_gentoo_ci/steps/logs.py | 121 ++++++++++++++++++++++----------------- |
13 |
1 file changed, 70 insertions(+), 51 deletions(-) |
14 |
|
15 |
diff --git a/buildbot_gentoo_ci/steps/logs.py b/buildbot_gentoo_ci/steps/logs.py |
16 |
index 178d71e..0960b9b 100644 |
17 |
--- a/buildbot_gentoo_ci/steps/logs.py |
18 |
+++ b/buildbot_gentoo_ci/steps/logs.py |
19 |
@@ -57,39 +57,46 @@ class ParserBuildLog(BuildStep): |
20 |
self.summery_dict = {} |
21 |
self.index = 1 |
22 |
self.log_search_pattern_list = [] |
23 |
- self.max_text_lines = self.index -1 |
24 |
+ self.max_text_lines = 0 |
25 |
super().__init__(**kwargs) |
26 |
|
27 |
+ #FIXME: ansifilter |
28 |
+ def ansiFilter(self, text): |
29 |
+ return text |
30 |
+ |
31 |
@defer.inlineCallbacks |
32 |
def get_log_search_pattern(self): |
33 |
# get pattern from the projects |
34 |
# add that to log_search_pattern_list |
35 |
for project_pattern in (yield self.gentooci.db.projects.getProjectLogSearchPatternByUuid(self.getProperty('project_data')['uuid'])): |
36 |
- self.log_search_pattern_list.append(project_pattern) |
37 |
- # get the default profile pattern |
38 |
+ # check if the search pattern is vaild |
39 |
+ try: |
40 |
+ re.compile(project_pattern['search']) |
41 |
+ except re.error: |
42 |
+ print("Non valid regex pattern") |
43 |
+ print(project_pattern) |
44 |
+ else: |
45 |
+ self.log_search_pattern_list.append(project_pattern) |
46 |
+ # get the default project pattern |
47 |
# add if not pattern is in project ignore |
48 |
+ self.project_pattern_ignore = yield self.gentooci.db.projects.getProjectLogSearchPatternByUuidAndIgnore(self.getProperty('project_data')['uuid']) |
49 |
for project_pattern in (yield self.gentooci.db.projects.getProjectLogSearchPatternByUuid(self.getProperty('default_project_data')['uuid'])): |
50 |
- match = True |
51 |
- for project_pattern_ignore in (yield self.gentooci.db.projects.getProjectLogSearchPatternByUuidAndIgnore(self.getProperty('default_project_data')['uuid'])): |
52 |
- if project_pattern['search'] == project_pattern_ignore['search']: |
53 |
- match = False |
54 |
- if match: |
55 |
- self.log_search_pattern_list.append(project_pattern) |
56 |
+ if not project_pattern['search'] in self.project_pattern_ignore: |
57 |
+ # check if the search pattern is vaild |
58 |
+ try: |
59 |
+ re.compile(project_pattern['search']) |
60 |
+ except re.error: |
61 |
+ print("Non valid regex pattern") |
62 |
+ print(project_pattern) |
63 |
+ else: |
64 |
+ self.log_search_pattern_list.append(project_pattern) |
65 |
|
66 |
def search_buildlog(self, tmp_index): |
67 |
# get text line to search |
68 |
- text_line = self.logfile_text_dict[tmp_index] |
69 |
+ text_line = self.ansiFilter(self.logfile_text_dict[tmp_index]) |
70 |
# loop true the pattern list for match |
71 |
for search_pattern in self.log_search_pattern_list: |
72 |
search_hit = False |
73 |
- # we add all line that start with ' * ' as info |
74 |
- # we add all line that start with '>>>' but not '>>> /' as info |
75 |
- if text_line.startswith(' * ') or (text_line.startswith('>>>') and not text_line.startswith('>>> /')): |
76 |
- self.summery_dict[tmp_index] = {} |
77 |
- self.summery_dict[tmp_index]['text'] = text_line |
78 |
- self.summery_dict[tmp_index]['type'] = 'info' |
79 |
- self.summery_dict[tmp_index]['status'] = 'info' |
80 |
- self.summery_dict[tmp_index]['search_pattern_id'] = 0 |
81 |
if search_pattern['search_type'] == 'in': |
82 |
if search_pattern['search'] in text_line: |
83 |
search_hit = True |
84 |
@@ -100,63 +107,74 @@ class ParserBuildLog(BuildStep): |
85 |
if text_line.endswith(search_pattern['search']): |
86 |
search_hit = True |
87 |
if search_pattern['search_type'] == 'search': |
88 |
- if search_pattern['search'] in text_line: |
89 |
+ if re.search(search_pattern['search'], text_line): |
90 |
search_hit = True |
91 |
+ # add the line if the pattern match |
92 |
if search_hit: |
93 |
print(text_line) |
94 |
- print(search_pattern['search']) |
95 |
+ print(search_pattern) |
96 |
+ print(tmp_index) |
97 |
self.summery_dict[tmp_index] = {} |
98 |
self.summery_dict[tmp_index]['text'] = text_line |
99 |
self.summery_dict[tmp_index]['type'] = search_pattern['type'] |
100 |
self.summery_dict[tmp_index]['status'] = search_pattern['status'] |
101 |
self.summery_dict[tmp_index]['search_pattern_id'] = search_pattern['id'] |
102 |
# add upper text lines if requested |
103 |
- # max 10 |
104 |
- if search_pattern['start'] != 0 and search_hit: |
105 |
- i = tmp_index |
106 |
- i_start = i - search_pattern['start'] |
107 |
- match = True |
108 |
- while match: |
109 |
- i = i - 1 |
110 |
- if i < 0 or i < i_start: |
111 |
- match = False |
112 |
- else: |
113 |
- self.summery_dict[i] = {} |
114 |
- self.summery_dict[i]['text'] = self.logfile_text_dict[i] |
115 |
- self.summery_dict[i]['type'] = search_pattern['type'] |
116 |
- self.summery_dict[i]['status'] = 'info' |
117 |
+ # max 5 |
118 |
+ if search_pattern['start'] != 0: |
119 |
+ i = tmp_index - search_pattern['start'] - 1 |
120 |
+ match = True |
121 |
+ while match: |
122 |
+ i = i + 1 |
123 |
+ if i < (tmp_index - 9) or i == tmp_index: |
124 |
+ match = False |
125 |
+ else: |
126 |
+ if not i in self.summery_dict: |
127 |
+ self.summery_dict[i] = {} |
128 |
+ self.summery_dict[i]['text'] = self.ansiFilter(self.logfile_text_dict[i]) |
129 |
+ self.summery_dict[i]['type'] = 'info' |
130 |
+ self.summery_dict[i]['status'] = 'info' |
131 |
# add lower text lines if requested |
132 |
- # max 10 |
133 |
- if search_pattern['end'] != 0 and search_hit: |
134 |
- i = tmp_index |
135 |
- i_end = i + search_pattern['end'] |
136 |
- match = True |
137 |
- while match: |
138 |
- i = i + 1 |
139 |
- if i > self.max_text_lines or i > i_end: |
140 |
- match = False |
141 |
- else: |
142 |
- self.summery_dict[i] = {} |
143 |
- self.summery_dict[i]['text'] = self.logfile_text_dict[i] |
144 |
- self.summery_dict[i]['type'] = search_pattern['type'] |
145 |
- self.summery_dict[i]['status'] = 'info' |
146 |
+ # max 5 |
147 |
+ if search_pattern['end'] != 0: |
148 |
+ i = tmp_index |
149 |
+ end = tmp_index + search_pattern['end'] |
150 |
+ match = True |
151 |
+ while match: |
152 |
+ i = i + 1 |
153 |
+ if i > self.max_text_lines or i > end: |
154 |
+ match = False |
155 |
+ else: |
156 |
+ if not i in self.summery_dict: |
157 |
+ self.summery_dict[i] = {} |
158 |
+ self.summery_dict[i]['text'] = self.ansiFilter(self.logfile_text_dict[i]) |
159 |
+ self.summery_dict[i]['type'] = 'info' |
160 |
+ self.summery_dict[i]['status'] = 'info' |
161 |
+ else: |
162 |
+ # we add all line that start with ' * ' as info |
163 |
+ # we add all line that start with '>>>' but not '>>> /' as info |
164 |
+ if text_line.startswith(' * ') or (text_line.startswith('>>>') and not text_line.startswith('>>> /')): |
165 |
+ if not tmp_index in self.summery_dict: |
166 |
+ self.summery_dict[tmp_index] = {} |
167 |
+ self.summery_dict[tmp_index]['text'] = text_line |
168 |
+ self.summery_dict[tmp_index]['type'] = 'info' |
169 |
+ self.summery_dict[tmp_index]['status'] = 'info' |
170 |
|
171 |
@defer.inlineCallbacks |
172 |
def run(self): |
173 |
self.gentooci = self.master.namedServices['services'].namedServices['gentooci'] |
174 |
- #FIXME: |
175 |
- # get the log parser pattern from db |
176 |
yield self.get_log_search_pattern() |
177 |
# open the log file |
178 |
# read it to a buffer |
179 |
# make a dict of the buffer |
180 |
- # maby use mulitiprocces to speed up the search |
181 |
+ # maybe use mulitiprocces to speed up the search |
182 |
print(self.getProperty('log_build_data')) |
183 |
if self.getProperty('faild_cpv'): |
184 |
log_cpv = self.getProperty('log_build_data')[self.getProperty('faild_cpv')] |
185 |
else: |
186 |
log_cpv = self.getProperty('log_build_data')[self.getProperty('cpv')] |
187 |
file_path = yield os.path.join(self.master.basedir, 'cpv_logs', log_cpv['full_logname']) |
188 |
+ #FIXME: decode it to utf-8 |
189 |
with io.TextIOWrapper(io.BufferedReader(gzip.open(file_path, 'rb'))) as f: |
190 |
for text_line in f: |
191 |
self.logfile_text_dict[self.index] = text_line.strip('\n') |
192 |
@@ -168,6 +186,7 @@ class ParserBuildLog(BuildStep): |
193 |
if self.index >= 20: |
194 |
del self.logfile_text_dict[self.index - 19] |
195 |
self.index = self.index + 1 |
196 |
+ self.max_text_lines = self.index |
197 |
f.close() |
198 |
# check last 10 lines in logfile_text_dict |
199 |
yield self.search_buildlog(self.index - 10) |