Skip to content

Commit cb4adac

Browse files
authored
Merge pull request #204 from perlpunk/post-investigate
Post comment about sporadic failure
2 parents 33c70a7 + 024e921 commit cb4adac

File tree

5 files changed

+117
-17
lines changed

5 files changed

+117
-17
lines changed

_common

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ runcurl() {
7575
echo "$body"
7676
}
7777

78+
openqa-api-get() {
79+
client_args=(api --header 'User-Agent: openqa-investigate (https://github.com/os-autoinst/scripts)' --host "$host_url")
80+
openqa-cli "${client_args[@]}" --json "$@"
81+
}
82+
7883
comment_on_job() {
7984
local id=$1 comment=$2 force_result=${3:-''}
8085
if $enable_force_result && [[ -n $force_result ]]; then

openqa-investigate

Lines changed: 28 additions & 10 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,16 +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>/dev/null) || \
205-
if [[ $(echo "$out" | runjq .error_status) != "404" ]]; then
206-
echoerr "Unexpected error encountered when posting comments on job $origin_job_id after investigation job $id failed: '$out'"
207-
return 2
208-
fi
225+
post-investigate "$id" "$old_name" || return $?
209226
return 0
210227
fi
211228
clone="$(echo "$job_data" | runjq -r '.job.clone_id')" || return $?
@@ -241,6 +258,7 @@ investigate() {
241258
}
242259

243260
main() {
261+
local id=${1:?"Need 'job_id'"}
244262
client_prefix=''
245263
[ "$dry_run" = "1" ] && client_prefix="echo"
246264
set +u

openqa-label-known-issues-and-investigate-hook

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ set -eo pipefail
88
dir=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
99
PATH=$dir:$PATH
1010

11+
# shellcheck source=/dev/null
12+
source "$dir"/_common
13+
1114
host="${host:-"openqa.opensuse.org"}"
1215
scheme="${scheme:-"https"}"
1316
host_url="$scheme://$host"
@@ -21,9 +24,23 @@ investigate-and-bisect() {
2124
return "$rc"
2225
}
2326

27+
label() {
28+
local url=$1
29+
openqa-label-known-issues "$url" | sed -n 's/\[\([^]]*\)\].*Unknown issue, to be reviewed.*/\1/p'
30+
}
31+
2432
hook() {
2533
local id="${1:?"Need 'job_id'"}"
26-
openqa-label-known-issues "$host_url/tests/$id" | sed -n 's/\[\([^]]*\)\].*Unknown issue, to be reviewed.*/\1/p' | investigate-and-bisect
34+
local url=$host_url/tests/$id
35+
job_data=$(openqa-api-get "jobs/$id")
36+
state="$(echo "$job_data" | runjq -r '.job.state')" || return $?
37+
result="$(echo "$job_data" | runjq -r '.job.result')" || return $?
38+
[[ "$state" != "done" ]] && return
39+
if [[ "$result" != passed ]]; then
40+
label "$url" | investigate-and-bisect
41+
else
42+
echo "$url" | investigate-and-bisect
43+
fi
2744
}
2845

2946
caller 0 >/dev/null || hook "$@"

test/02-investigate.t

Lines changed: 26 additions & 1 deletion
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 27
6+
plan tests 35
77

88
host=localhost
99
url=https://localhost
@@ -33,6 +33,12 @@ openqa-cli() {
3333
echo '{"job": { "test": "vim", "priority": 50, "settings" : {} } }'
3434
elif [[ "$1 $2" == "--json jobs/27" ]]; then
3535
echo '{"job": { "test": "vim", "clone_id" : 28 } }'
36+
elif [[ "$1 $2" == "--json jobs/33" ]]; then
37+
echo '{"job": { "test": "vim", "test": "vim:investigate:abc", "result": "failed" } }'
38+
elif [[ "$1 $2" == "--json jobs/34" ]]; then
39+
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"} } }'
3642
elif [[ $@ == "-X POST jobs/30/comments text=Starting investigation for job 31" ]]; then
3743
echo '{"id": 1234}'
3844
elif [[ $@ == $'-X PUT jobs/30/comments/1234 text=Automatic investigation jobs for job 31:\n\nfoo' ]]; then
@@ -47,10 +53,15 @@ openqa-cli() {
4753
echo '{"id": 1237}'
4854
elif [[ $@ == "-X GET jobs/32/comments" ]]; then
4955
echo '[{"id": 1236, "text":"Starting investigation for job 32"},{"id": 1237, "text":"Starting investigation for job 32"}]'
56+
elif [[ $@ =~ "-X POST jobs/35/comments" ]]; then
57+
warn "Commenting 35 ($@)"
58+
exit 99
5059
elif [[ $@ == '--apibase --json tests/27/dependencies_ajax' ]]; then
5160
echo '{"cluster":{}, "edges":[], "nodes":[{"id":27,"state":"done","result":"passed"}]}'
5261
elif [[ $@ == '--apibase --json tests/28/dependencies_ajax' ]]; then
5362
echo '{"cluster":{}, "edges":[], "nodes":[{"id":28,"state":"done","result":"failed"}]}'
63+
elif [[ $@ == '--apibase --json tests/33/dependencies_ajax' ]]; then
64+
echo '{"cluster":{}, "edges":[], "nodes":[]}'
5465
elif [[ $@ == '--apibase --json tests/29/dependencies_ajax' ]]; then
5566
echo '{"cluster":{"cluster_foo":[28],"cluster_bar":[29]}, "edges":[], "nodes":[{"id":28,"state":"done","result":"failed"},{"id":29,"state":"done","result":"passed"}]}'
5667
elif [[ $@ == '--apibase --json tests/30/dependencies_ajax' ]]; then
@@ -94,6 +105,20 @@ try force=true investigate 31
94105
is "$rc" 0 'success when job is skipped (because of exclude_no_group and job w/o group)'
95106
has "$got" 'Job w/o job group, $exclude_no_group is set, skipping investigation'
96107

108+
try investigate 33
109+
is "$rc" 0 'success (33)'
110+
has "$got" "Job is ':investigate:' already, skipping investigation" "skip :investigate: (33)"
111+
112+
try investigate 34
113+
is "$rc" 2 'mocked function returned failure (34)'
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)"
121+
97122
# test syncing via investigation comment; we're first
98123
try force=true sync_via_investigation_comment 31 30
99124
is "$rc" 255 'do not skip if we own first investigation comment'

test/03-openqa-label-known-issues-and-investigate-hook.t

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source test/init
44

5-
plan tests 5
5+
plan tests 18
66
dir=$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)
77

88
source "$dir/../openqa-label-known-issues-and-investigate-hook"
@@ -17,20 +17,55 @@ openqa-trigger-bisect-jobs() {
1717
}
1818
openqa-label-known-issues() {
1919
testurl=$1
20+
warn "- openqa-label-known-issues $testurl"
2021
echo "[$testurl]($testurl): Unknown issue, to be reviewed -> $testurl/file/autoinst-log.txt"
2122
}
2223
openqa-investigate() {
2324
local testurl=$1
2425
"$INVESTIGATE_FAIL" && return 1
2526
"$INVESTIGATE_RETRIGGER_HOOK" && return 142
26-
echo "openqa-investigate $testurl"
27+
warn "- openqa-investigate $testurl"
28+
}
29+
openqa-trigger-bisect-jobs() {
30+
warn "- openqa-trigger-bisect-jobs $1"
31+
}
32+
openqa-api-get() {
33+
local path=$1
34+
if [[ "$path" == "jobs/123" ]]; then
35+
echo '{"job":{"state":"done", "result":"failed", "test":"foo"}}'
36+
elif [[ "$path" == "jobs/124" ]]; then
37+
echo '{"job":{"state":"done", "result":"passed", "test":"foo"}}'
38+
elif [[ "$path" == "jobs/125" ]]; then
39+
echo '{"job":{"state":"done", "result":"failed", "test":"foo:investigate:retry:x"}}'
40+
elif [[ "$path" == "jobs/126" ]]; then
41+
echo '{"job":{"state":"done", "result":"failed", "test":"foo:investigate:abc:x"}}'
42+
fi
2743
}
2844

2945
try hook 123
30-
is "$rc" 0 'successful hook'
46+
is "$rc" 0 'successful hook (123)'
47+
has "$got" "- openqa-label-known-issues"
48+
has "$got" "- openqa-investigate"
49+
has "$got" "- openqa-trigger-bisect-jobs"
50+
51+
try hook 124
52+
is "$rc" 0 'successful hook (124)'
53+
hasnt "$got" "- openqa-label-known-issues"
54+
has "$got" "- openqa-investigate"
55+
has "$got" "- openqa-trigger-bisect-jobs"
56+
57+
try hook 125
58+
is "$rc" 0 'successful hook (125)'
59+
has "$got" "- openqa-label-known-issues"
60+
has "$got" "- openqa-investigate"
61+
has "$got" "- openqa-trigger-bisect-jobs"
62+
63+
try hook 126
64+
is "$rc" 0 'successful hook (126)'
65+
has "$got" "- openqa-label-known-issues"
66+
has "$got" "- openqa-investigate"
67+
has "$got" "- openqa-trigger-bisect-jobs"
3168

32-
has "$got" 'openqa-investigate https://openqa.opensuse.org/tests/123' 'correct output 1'
33-
has "$got" 'openqa-trigger-bisect-jobs (--url https://openqa.opensuse.org/tests/123)' 'correct output 2'
3469

3570
export INVESTIGATE_FAIL=true
3671
try hook 123

0 commit comments

Comments
 (0)