Add more tracing to kojiwrapper

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
(cherry picked from commit 431cd630e93d8655329a0a1c77d291e7714c12c4)
This commit is contained in:
Lubomír Sedlář 2025-03-20 13:42:45 +01:00 committed by Stepan Oksanichenko
parent 85d7d19dc5
commit 4d432fd385

View File

@ -288,36 +288,38 @@ class KojiWrapper(object):
:return dict: {"retcode": 0, "output": "", "task_id": 1} :return dict: {"retcode": 0, "output": "", "task_id": 1}
""" """
task_id = None task_id = None
with self.get_koji_cmd_env() as env: with tracing.span("run-runroot-cmd", command=command):
retcode, output = run( with self.get_koji_cmd_env() as env:
command, retcode, output = run(
can_fail=True, command,
logfile=log_file, can_fail=True,
show_cmd=True, logfile=log_file,
env=env, show_cmd=True,
buffer_size=-1, env=env,
text=True, buffer_size=-1,
errors="replace", text=True,
) errors="replace",
)
# Look for first line that contains only a number. This is the ID of # Look for first line that contains only a number. This is the ID of
# the new task. Usually this should be the first line, but there may be # the new task. Usually this should be the first line, but there may be
# warnings before it. # warnings before it.
for line in output.splitlines(): for line in output.splitlines():
match = re.search(r"^(\d+)$", line) match = re.search(r"^(\d+)$", line)
if match: if match:
task_id = int(match.groups()[0]) task_id = int(match.groups()[0])
break break
if not task_id: if not task_id:
raise RuntimeError( raise RuntimeError(
"Could not find task ID in output. Command '%s' returned '%s'." "Could not find task ID in output. Command '%s' returned '%s'."
% (" ".join(command), output) % (" ".join(command), output)
) )
self.save_task_id(task_id) self.save_task_id(task_id)
tracing.set_attribute("task_id", task_id)
retcode, output = self._wait_for_task(task_id, logfile=log_file) retcode, output = self._wait_for_task(task_id, logfile=log_file)
return { return {
"retcode": retcode, "retcode": retcode,
@ -432,9 +434,10 @@ class KojiWrapper(object):
attempt = 0 attempt = 0
while True: while True:
retcode, output = run( with tracing.span("watch-task", task_id=task_id):
cmd, can_fail=True, logfile=logfile, text=True, errors="replace" retcode, output = run(
) cmd, can_fail=True, logfile=logfile, text=True, errors="replace"
)
if retcode == 0 or not ( if retcode == 0 or not (
self._has_connection_error(output) or self._has_offline_error(output) self._has_connection_error(output) or self._has_offline_error(output)
@ -458,34 +461,36 @@ class KojiWrapper(object):
its exit code and parsed task id. This method will block until the its exit code and parsed task id. This method will block until the
command finishes. command finishes.
""" """
with self.get_koji_cmd_env() as env: with tracing.span("run-blocking-cmd", command=command):
retcode, output = run( with self.get_koji_cmd_env() as env:
command, retcode, output = run(
can_fail=True, command,
show_cmd=True, can_fail=True,
logfile=log_file, show_cmd=True,
env=env, logfile=log_file,
buffer_size=-1, env=env,
text=True, buffer_size=-1,
errors="replace", text=True,
) errors="replace",
)
match = re.search(r"Created task: (\d+)", output) match = re.search(r"Created task: (\d+)", output)
if not match: if not match:
raise RuntimeError( raise RuntimeError(
"Could not find task ID in output. Command '%s' returned '%s'." "Could not find task ID in output. Command '%s' returned '%s'."
% (" ".join(command), output) % (" ".join(command), output)
) )
task_id = int(match.groups()[0]) task_id = int(match.groups()[0])
tracing.set_attribute("task_id", task_id)
self.save_task_id(task_id) self.save_task_id(task_id)
if retcode != 0 and ( if retcode != 0 and (
self._has_connection_error(output) or self._has_offline_error(output) self._has_connection_error(output) or self._has_offline_error(output)
): ):
retcode, output = self._wait_for_task( retcode, output = self._wait_for_task(
task_id, logfile=log_file, max_retries=max_retries task_id, logfile=log_file, max_retries=max_retries
) )
return { return {
"retcode": retcode, "retcode": retcode,