Skip to content

Commit

Permalink
src/send_kcidb: set log_excerpt for builds and tests
Browse files Browse the repository at this point in the history
Fetch logs from compressed log file(*.log.gz) URL
and send last 16*1024 characters for setting `log_excerpt`
field for build and test nodes as it is the max allowed
length of the KCIDB field.

Signed-off-by: Jeny Sadadia <[email protected]>
  • Loading branch information
Jeny Sadadia authored and JenySadadia committed Jun 6, 2024
1 parent 2f7699c commit d2da73c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/send_kcidb.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import datetime
import sys
import re
import io
import gzip
import requests

import kernelci
import kernelci.config
Expand Down Expand Up @@ -116,6 +119,17 @@ def _get_output_files(self, artifacts: dict, exclude_properties=None):
)
return output_files

def _get_log_excerpt(self, log_url):
"""Parse compressed log file and return last 16*1024 characters as it's
the maximum allowed length for KCIDB `log_excerpt` field"""
res = requests.get(log_url, timeout=60)
if res.status_code != 200:
return None
buffer_data = io.BytesIO(res.content)
with gzip.open(buffer_data, mode='rt') as fp:
data = fp.read()
return data[-(16*1024):]

def _parse_build_node(self, origin, node):
parsed_build_node = {
'checkout_id': f"{origin}:{node['parent']}",
Expand Down Expand Up @@ -143,6 +157,10 @@ def _parse_build_node(self, origin, node):
)
parsed_build_node['config_url'] = artifacts.get('_config')
parsed_build_node['log_url'] = artifacts.get('build_log')
log_url = parsed_build_node['log_url']
if log_url:
parsed_build_node['log_excerpt'] = self._get_log_excerpt(
log_url)

return [parsed_build_node]

Expand Down Expand Up @@ -316,6 +334,11 @@ def _parse_test_node(self, origin, test_node):
else:
parsed_test_node['log_url'] = artifacts.get('test_log')

log_url = parsed_test_node['log_url']
if log_url:
parsed_test_node['log_excerpt'] = self._get_log_excerpt(
log_url)

if test_node['result']:
parsed_test_node['status'] = self._parse_node_result(test_node)

Expand Down

0 comments on commit d2da73c

Please sign in to comment.