Skip to content

Commit e61f806

Browse files
committed
Add debug for merge base logic
1 parent 1237b0d commit e61f806

3 files changed

Lines changed: 71 additions & 24 deletions

File tree

.gitlab-ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ include:
77
- project: 'DataDog/apm-reliability/apm-sdks-benchmarks'
88
file: '.gitlab/ci-java-spring-petclinic.yml'
99
ref: 'main'
10+
rules:
11+
- when: never # disable while testing merge base logic
1012
- project: 'DataDog/apm-reliability/apm-sdks-benchmarks'
1113
file: '.gitlab/ci-java-insecure-bank.yml'
1214
ref: 'main'
15+
rules:
16+
- when: never # disable while testing merge base logic
1317
- project: 'DataDog/apm-reliability/apm-sdks-benchmarks'
1418
file: '.gitlab/ci-java-dacapo.yml'
1519
ref: 'main'
20+
rules:
21+
- when: never # disable while testing merge base logic
1622

1723
stages:
1824
- build

.gitlab/scripts/benchmark-compare.sh

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,46 @@ download_job_artifacts() {
9090
local job_id="$1"
9191
local output_dir="$2"
9292
local archive_path="${output_dir}/artifacts.zip"
93+
local artifacts_url="${JOBS_API_URL}/jobs/${job_id}/artifacts"
94+
local http_code
9395

9496
mkdir -p "${output_dir}"
95-
curl --silent --show-error --fail --location \
96-
--header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
97-
"${JOBS_API_URL}/jobs/${job_id}/artifacts" \
98-
--output "${archive_path}"
97+
98+
http_code="$(
99+
curl --silent --show-error --location \
100+
--header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
101+
--output "${archive_path}" \
102+
--write-out "%{http_code}" \
103+
"${artifacts_url}"
104+
)"
105+
106+
if [[ "${http_code}" != "200" ]]; then
107+
rm -f "${archive_path}"
108+
case "${http_code}" in
109+
400)
110+
echo "ERROR: Bad request for job ${job_id} artifacts (HTTP 400)." >&2
111+
;;
112+
401)
113+
echo "ERROR: Authentication required for job ${job_id} artifacts (HTTP 401)." >&2
114+
;;
115+
403)
116+
echo "ERROR: Access forbidden for job ${job_id} artifacts (HTTP 403)." >&2
117+
;;
118+
404)
119+
echo "ERROR: Artifacts not found for job ${job_id} (HTTP 404). Job may still be running or produced no artifacts." >&2
120+
;;
121+
5*)
122+
echo "ERROR: Server/network issue while downloading artifacts for job ${job_id} (HTTP ${http_code})." >&2
123+
;;
124+
*)
125+
echo "ERROR: Failed to download artifacts for job ${job_id} (HTTP ${http_code})." >&2
126+
;;
127+
esac
128+
if [[ -n "${CI_PROJECT_URL:-}" ]]; then
129+
echo "See job details: ${CI_PROJECT_URL}/-/jobs/${job_id}" >&2
130+
fi
131+
return 1
132+
fi
99133

100134
rm -rf "${output_dir}/unzipped"
101135
mkdir -p "${output_dir}/unzipped"

.gitlab/scripts/get-baseline-commit-info.sh

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,46 @@ fi
1818

1919
readonly PROJECT_API_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}"
2020

21+
log_debug() {
22+
echo "[baseline-debug] $*" >&2
23+
}
24+
25+
response_snippet() {
26+
local response="$1"
27+
echo "${response}" | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g' | cut -c1-220
28+
}
29+
2130
get_pipeline_id_for_commit() {
2231
local commit_sha="$1"
23-
24-
# Query GitLab API to get pipeline ID that matches the commit SHA
2532
local api_url="${PROJECT_API_URL}/repository/commits/${commit_sha}"
2633
local response pipeline_id
34+
35+
log_debug "query commit endpoint: ${api_url}"
2736
response="$(curl --request GET --silent --show-error --header "JOB-TOKEN: ${CI_JOB_TOKEN}" "${api_url}" || true)"
2837
pipeline_id="$(echo "${response}" | grep -o '"last_pipeline"[^}]*"id":[0-9]*' | grep -o '[0-9]*$' | head -1 || true)"
2938
if [[ -n "${pipeline_id}" && "${pipeline_id}" != "null" ]]; then
39+
log_debug "found pipeline_id=${pipeline_id} for commit_sha=${commit_sha}"
3040
echo "${pipeline_id}"
3141
return 0
3242
fi
3343

34-
echo ""
44+
log_debug "no last_pipeline.id for commit_sha=${commit_sha}; response='$(response_snippet "${response}")'"
3545
return 1
3646
}
3747

38-
get_branch_head_sha() {
39-
local branch="$1"
40-
41-
# Query GitLab API to get branch head SHA
42-
local api_url="${PROJECT_API_URL}/repository/branches/${branch}"
43-
local response branch_sha
44-
response="$(curl --request GET --silent --show-error --header "JOB-TOKEN: ${CI_JOB_TOKEN}" "${api_url}" || true)"
45-
branch_sha="$(echo "${response}" | grep -o '"commit"[^}]*"id":"[a-f0-9]\{40\}"' | sed -E 's/.*"id":"([a-f0-9]{40})".*/\1/' | head -1 || true)"
46-
47-
echo "${branch_sha}"
48-
}
49-
5048
get_latest_pipeline_id_for_branch() {
5149
local branch="$1"
52-
local api_url="${PROJECT_API_URL}/pipelines?ref=${branch}&status=success&order_by=updated_at&sort=desc&per_page=1"
50+
local api_url="${PROJECT_API_URL}/pipelines?ref=${branch}&order_by=id&sort=desc&per_page=1"
5351
local response pipeline_id
5452

53+
log_debug "query pipelines endpoint: ${api_url}"
5554
response="$(curl --request GET --silent --show-error --header "JOB-TOKEN: ${CI_JOB_TOKEN}" "${api_url}" || true)"
5655
pipeline_id="$(echo "${response}" | grep -o '"id":[0-9]*' | head -1 | grep -o '[0-9]*' || true)"
56+
if [[ -n "${pipeline_id}" ]]; then
57+
log_debug "found latest pipeline_id=${pipeline_id} for branch=${branch}"
58+
else
59+
log_debug "no pipeline found for branch=${branch}; response='$(response_snippet "${response}")'"
60+
fi
5761
echo "${pipeline_id}"
5862
}
5963

@@ -73,21 +77,24 @@ BASELINE_PIPELINE_ID=""
7377
BASELINE_SOURCE="merge_base"
7478
FALLBACK_TO_MASTER="false"
7579

80+
log_debug "resolved merge_base_sha='${MERGE_BASE_SHA:-<empty>}' target_branch='${TARGET_BRANCH}'"
81+
7682
if [[ -n "${MERGE_BASE_SHA}" ]]; then
7783
BASELINE_PIPELINE_ID="$(get_pipeline_id_for_commit "${MERGE_BASE_SHA}" || true)"
7884
fi
7985

8086
if [[ -z "${BASELINE_PIPELINE_ID}" ]]; then
8187
FALLBACK_TO_MASTER="true"
8288
BASELINE_SOURCE="${TARGET_BRANCH}"
89+
log_debug "merge-base pipeline not found; falling back to branch='${TARGET_BRANCH}'"
8390

8491
BASELINE_SHA="$(git rev-parse "origin/${TARGET_BRANCH}" 2>/dev/null || true)"
85-
if [[ -z "${BASELINE_SHA}" ]]; then
86-
BASELINE_SHA="$(get_branch_head_sha "${TARGET_BRANCH}" || true)"
92+
log_debug "resolved branch sha from local git: '${BASELINE_SHA:-<empty>}'"
93+
if [[ -n "${BASELINE_SHA}" ]]; then
94+
BASELINE_PIPELINE_ID="$(get_pipeline_id_for_commit "${BASELINE_SHA}" || true)"
8795
fi
88-
BASELINE_PIPELINE_ID="$(get_pipeline_id_for_commit "${BASELINE_SHA}" || true)"
8996

90-
# use latest successful branch pipeline
97+
# Final fallback: use latest branch pipeline
9198
if [[ -z "${BASELINE_PIPELINE_ID}" ]]; then
9299
BASELINE_PIPELINE_ID="$(get_latest_pipeline_id_for_branch "${TARGET_BRANCH}" || true)"
93100
fi

0 commit comments

Comments
 (0)