Skip to content

Commit 024e921

Browse files
committed
Post a comment about sporadic failure
When a retry job passed, then the original failure was likely just a sporadic issue. We now post a comment to the original job with this information. Issue: https://progress.opensuse.org/issues/98862 Still todo: enable _TRIGGER_JOB_DONE_HOOK=1 to allow processing passed investigation jobs.
1 parent f953d47 commit 024e921

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

openqa-investigate

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,32 @@ $comment_text"
180180
fi
181181
}
182182

183+
post-investigate() {
184+
local id=$1 old_name=$2
185+
local rc=0 status
186+
[[ ! "$old_name" =~ investigate:retry$ ]] && echo "Job is ':investigate:' already, skipping investigation" && return 0
187+
result="$(echo "$job_data" | runjq -r '.job.result')" || return $?
188+
investigate_origin="$(echo "$job_data" | runjq -r '.job.settings.OPENQA_INVESTIGATE_ORIGIN')" || return 1
189+
origin_job_id=${investigate_origin#"$host_url/t"}
190+
comment="Investigate retry job: $host_url/t$id"
191+
if [[ "$result" == passed ]]; then
192+
comment+=" passed, likely a sporadic failure"
193+
else
194+
comment+=" failed, likely not a sporadic failure"
195+
fi
196+
197+
# meanwhile the original job might have been deleted already, handle
198+
# gracefully
199+
out=$("${client_call[@]}" -X POST jobs/"$origin_job_id"/comments text="$comment" 2>&1) || rc=$?
200+
if [[ "$rc" -ne 0 ]]; then
201+
status=$(echo "$out" | runjq .error_status 2>/dev/null || echo "unknown")
202+
if [[ "$status" != "404" ]]; then
203+
echoerr "Unexpected error encountered when posting comments on job $origin_job_id after investigation job $id failed: '$out'"
204+
return 2
205+
fi
206+
fi
207+
}
208+
183209
# crosscheck
184210
# 1. current job/build + current test -> check if reproducible/sporadic
185211
# 2. current job/build + last good test (+ last good needles) -> check for
@@ -196,17 +222,7 @@ investigate() {
196222
[[ $? != 0 ]] && echoerr "unable to query job data for $id: $job_data" && return 1
197223
old_name="$(echo "$job_data" | runjq -r '.job.test')" || return $?
198224
if [[ "$old_name" =~ ":investigate:" ]]; then
199-
[[ ! "$old_name" =~ investigate:retry$ ]] && echo "Job is ':investigate:' already, skipping investigation" && return 0
200-
investigate_origin="$(echo "$job_data" | runjq -r '.job.settings.OPENQA_INVESTIGATE_ORIGIN')" || return 1
201-
origin_job_id=${investigate_origin#"$host_url/t"}
202-
# meanwhile the original job might have been deleted already, handle
203-
# gracefully
204-
out=$("${client_call[@]}" -X POST jobs/"$origin_job_id"/comments text="Investigate retry job: $host_url/t$id failed, likely not a sporadic failure" 2>&1) || \
205-
status=$(echo "$out" | runjq .error_status 2>/dev/null || echo "unknown")
206-
if [[ "$status" != "404" ]]; then
207-
echoerr "Unexpected error encountered when posting comments on job $origin_job_id after investigation job $id failed: '$out'"
208-
return 2
209-
fi
225+
post-investigate "$id" "$old_name" || return $?
210226
return 0
211227
fi
212228
clone="$(echo "$job_data" | runjq -r '.job.clone_id')" || return $?

test/02-investigate.t

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source test/init
44
bpan:source bashplus +err +fs +sym
55

6-
plan tests 31
6+
plan tests 35
77

88
host=localhost
99
url=https://localhost
@@ -37,6 +37,8 @@ openqa-cli() {
3737
echo '{"job": { "test": "vim", "test": "vim:investigate:abc", "result": "failed" } }'
3838
elif [[ "$1 $2" == "--json jobs/34" ]]; then
3939
echo '{"job": { "test": "vim:investigate:retry", "result": "failed", "settings": {"OPENQA_INVESTIGATE_ORIGIN": "35"} } }'
40+
elif [[ "$1 $2" == "--json jobs/35" ]]; then
41+
echo '{"job": { "test": "vim:investigate:retry", "result": "passed", "settings": {"OPENQA_INVESTIGATE_ORIGIN": "35"} } }'
4042
elif [[ $@ == "-X POST jobs/30/comments text=Starting investigation for job 31" ]]; then
4143
echo '{"id": 1234}'
4244
elif [[ $@ == $'-X PUT jobs/30/comments/1234 text=Automatic investigation jobs for job 31:\n\nfoo' ]]; then
@@ -105,11 +107,17 @@ has "$got" 'Job w/o job group, $exclude_no_group is set, skipping investigation'
105107

106108
try investigate 33
107109
is "$rc" 0 'success (33)'
108-
has "$got" "Job is ':investigate:' already, skipping investigation" "skip :investigate:"
110+
has "$got" "Job is ':investigate:' already, skipping investigation" "skip :investigate: (33)"
109111

110112
try investigate 34
111113
is "$rc" 2 'mocked function returned failure (34)'
112-
has "$got" "Commenting 35" "Posting comment on OPENQA_INVESTIGATE_ORIGIN"
114+
has "$got" "Commenting 35" "Posting comment on OPENQA_INVESTIGATE_ORIGIN (34)"
115+
has "$got" "likely not a sporadic" "not sporadic (34)"
116+
117+
try investigate 35
118+
is "$rc" 2 'mocked function returned failure (35)'
119+
has "$got" "Commenting 35" "Posting comment on OPENQA_INVESTIGATE_ORIGIN (35)"
120+
has "$got" "likely a sporadic" "sporadic (35)"
113121

114122
# test syncing via investigation comment; we're first
115123
try force=true sync_via_investigation_comment 31 30

0 commit comments

Comments
 (0)