Skip to content

Commit 9bc1240

Browse files
Merge branch 'main' into sql/cli_cps
2 parents b3ef278 + e86a8a1 commit 9bc1240

File tree

8,899 files changed

+641319
-130462
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

8,899 files changed

+641319
-130462
lines changed

.backportrc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"upstream" : "elastic/elasticsearch",
3-
"targetBranchChoices" : [ "main", "9.2", "9.1", "9.0", "8.19", "8.18", "8.17", "8.16", "8.15", "8.14", "8.13", "8.12", "8.11", "8.10", "8.9", "8.8", "8.7", "8.6", "8.5", "8.4", "8.3", "8.2", "8.1", "8.0", "7.17", "6.8" ],
3+
"targetBranchChoices" : [ "main", "9.3", "9.2", "9.1", "9.0", "8.19", "8.18", "8.17", "8.16", "8.15", "8.14", "8.13", "8.12", "8.11", "8.10", "8.9", "8.8", "8.7", "8.6", "8.5", "8.4", "8.3", "8.2", "8.1", "8.0", "7.17", "6.8" ],
44
"targetPRLabels" : [ "backport" ],
55
"branchLabelMapping" : {
6-
"^v9.3.0$" : "main",
6+
"^v9.4.0$" : "main",
77
"^v(\\d+).(\\d+).\\d+(?:-(?:alpha|beta|rc)\\d+)?$" : "$1.$2"
88
}
99
}

.buildkite/hooks/pre-command

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ export GRADLE_BUILD_CACHE_USERNAME
4444
GRADLE_BUILD_CACHE_PASSWORD=$(vault read -field=password secret/ci/elastic-elasticsearch/migrated/gradle-build-cache)
4545
export GRADLE_BUILD_CACHE_PASSWORD
4646

47-
DEVELOCITY_ACCESS_KEY="gradle-enterprise.elastic.co=$(vault read -field=accesskey secret/ci/elastic-elasticsearch/migrated/gradle-build-cache)"
47+
DEVELOCITY_API_ACCESS_KEY=$(vault read -field=accesskey secret/ci/elastic-elasticsearch/migrated/gradle-build-cache)
48+
export DEVELOCITY_API_ACCESS_KEY
49+
50+
DEVELOCITY_ACCESS_KEY="gradle-enterprise.elastic.co=$DEVELOCITY_API_ACCESS_KEY"
4851
export DEVELOCITY_ACCESS_KEY
4952

5053
BUILDKITE_API_TOKEN=$(vault read -field=token secret/ci/elastic-elasticsearch/buildkite-api-token)
@@ -112,6 +115,7 @@ if [[ "${USE_PERF_CREDENTIALS:-}" == "true" ]]; then
112115
export PERF_METRICS_PASSWORD
113116
fi
114117

118+
115119
# Authenticate to the Docker Hub public read-only registry
116120
if which docker > /dev/null 2>&1; then
117121
DOCKERHUB_REGISTRY_USERNAME="$(vault read -field=username secret/ci/elastic-elasticsearch/docker_hub_public_ro_credentials)"
@@ -141,6 +145,155 @@ EOF
141145
EOF
142146
fi
143147

148+
if [[ "${SMART_RETRIES:-}" == "true" && "${BUILDKITE_RETRY_COUNT:-0}" -gt 0 ]]; then
149+
echo "--- Resolving previously failed tests"
150+
SMART_RETRY_STATUS="disabled"
151+
SMART_RETRY_DETAILS=""
152+
153+
if BUILD_JSON=$(curl --max-time 30 -H "Authorization: Bearer $BUILDKITE_API_TOKEN" -X GET "https://api.buildkite.com/v2/organizations/elastic/pipelines/${BUILDKITE_PIPELINE_SLUG}/builds/${BUILDKITE_BUILD_NUMBER}?include_retried_jobs=true" 2>/dev/null); then
154+
if ORIGIN_JOB_ID=$(printf '%s\n' "$BUILD_JSON" | jq -r --arg jobId "$BUILDKITE_JOB_ID" ' .jobs[] | select(.id == $jobId) | .retry_source.job_id' 2>/dev/null) && [ "$ORIGIN_JOB_ID" != "null" ] && [ -n "$ORIGIN_JOB_ID" ]; then
155+
156+
# Attempt to retrieve build scan ID directly from metadata
157+
BUILD_SCAN_ID=$(printf '%s\n' "$BUILD_JSON" | jq -r --arg job_id "$ORIGIN_JOB_ID" '.meta_data["build-scan-id-" + $job_id]' 2>/dev/null)
158+
159+
# Retrieve build scan URL for annotation
160+
BUILD_SCAN_URL=$(printf '%s\n' "$BUILD_JSON" | jq -r --arg job_id "$ORIGIN_JOB_ID" '.meta_data["build-scan-" + $job_id]' 2>/dev/null)
161+
162+
if [[ -n "$BUILD_SCAN_ID" ]] && [[ "$BUILD_SCAN_ID" != "null" ]]; then
163+
# Validate BUILD_SCAN_ID format to prevent injection attacks
164+
if [[ ! "$BUILD_SCAN_ID" =~ ^[a-zA-Z0-9_-]+$ ]]; then
165+
echo "Smart Retry Configuration Issue"
166+
echo "Invalid build scan ID format: $BUILD_SCAN_ID"
167+
echo "Smart retry will be disabled for this run."
168+
SMART_RETRY_STATUS="failed"
169+
SMART_RETRY_DETAILS="Invalid build scan ID format"
170+
else
171+
DEVELOCITY_BASE_URL="${DEVELOCITY_BASE_URL:-https://gradle-enterprise.elastic.co}"
172+
DEVELOCITY_FAILED_TEST_API_URL="${DEVELOCITY_BASE_URL}/api/tests/build/${BUILD_SCAN_ID}?testOutcomes=failed"
173+
174+
# Fetch test seed from build scan custom values
175+
# Support both DEVELOCITY_API_KEY and DEVELOCITY_API_ACCESS_KEY
176+
API_KEY="${DEVELOCITY_API_KEY:-$DEVELOCITY_API_ACCESS_KEY}"
177+
178+
if [[ -z "$API_KEY" ]]; then
179+
echo "Warning: No Develocity API key available (DEVELOCITY_API_KEY or DEVELOCITY_API_ACCESS_KEY)"
180+
echo "Test seed retrieval will be skipped"
181+
else
182+
DEVELOCITY_BUILD_SCAN_API_URL="${DEVELOCITY_BASE_URL}/api/builds/${BUILD_SCAN_ID}?models=gradle-attributes"
183+
TESTS_SEED=""
184+
185+
echo "Fetching test seed from build scan: $BUILD_SCAN_ID"
186+
echo "API URL: $DEVELOCITY_BUILD_SCAN_API_URL"
187+
188+
if BUILD_SCAN_DATA=$(curl --silent --show-error --compressed --request GET \
189+
--url "$DEVELOCITY_BUILD_SCAN_API_URL" \
190+
--max-time 30 \
191+
--header 'accept: application/json' \
192+
--header "authorization: Bearer $API_KEY" \
193+
--header 'content-type: application/json' 2>&1); then
194+
195+
# Check if we got valid JSON
196+
if echo "$BUILD_SCAN_DATA" | jq empty 2>/dev/null; then
197+
# Extract test seed from gradle attributes
198+
TESTS_SEED=$(printf '%s\n' "$BUILD_SCAN_DATA" | jq -r '.models.gradleAttributes.model.values[]? | select(.name == "tests.seed") | .value' 2>/dev/null)
199+
200+
if [[ -z "$TESTS_SEED" ]] || [[ "$TESTS_SEED" == "null" ]]; then
201+
echo "Could not retrieve test seed from build scan"
202+
echo "Debug: Checking available gradle attributes..."
203+
printf '%s\n' "$BUILD_SCAN_DATA" | jq -r '.models.gradleAttributes.model.values[]? | .name' 2>/dev/null || echo "No gradle attributes found"
204+
TESTS_SEED=""
205+
else
206+
echo "Retrieved test seed: $TESTS_SEED"
207+
export TESTS_SEED
208+
fi
209+
else
210+
echo "Error: Invalid JSON response from Develocity API"
211+
echo "Response preview: ${BUILD_SCAN_DATA:0:200}"
212+
TESTS_SEED=""
213+
fi
214+
else
215+
echo "Error: Failed to fetch build scan data from Develocity API"
216+
echo "Curl output: ${BUILD_SCAN_DATA:0:200}"
217+
TESTS_SEED=""
218+
fi
219+
fi
220+
221+
# Add random delay to prevent API rate limiting from parallel retries
222+
sleep $((RANDOM % 5))
223+
224+
if curl --compressed --request GET \
225+
--url "$DEVELOCITY_FAILED_TEST_API_URL" \
226+
--max-filesize 10485760 \
227+
--max-time 30 \
228+
--header 'accept: application/json' \
229+
--header "authorization: Bearer $DEVELOCITY_API_ACCESS_KEY" \
230+
--header 'content-type: application/json' 2>/dev/null | jq --arg testseed "$TESTS_SEED" '. + {testseed: $testseed}' &> .failed-test-history.json; then
231+
232+
# Set secure file permissions
233+
chmod 600 .failed-test-history.json
234+
235+
# Count filtered tests for visibility
236+
FILTERED_WORK_UNITS=$(jq -r '.workUnits | length' .failed-test-history.json 2>/dev/null || echo "0")
237+
SMART_RETRY_STATUS="enabled"
238+
SMART_RETRY_DETAILS="Filtering to $FILTERED_WORK_UNITS work units with failures"
239+
240+
# Get the origin job name for better annotation labels
241+
ORIGIN_JOB_NAME=$(printf '%s\n' "$BUILD_JSON" | jq -r --arg jobId "$ORIGIN_JOB_ID" '.jobs[] | select(.id == $jobId) | .name' 2>/dev/null)
242+
if [ -z "$ORIGIN_JOB_NAME" ] || [ "$ORIGIN_JOB_NAME" = "null" ]; then
243+
ORIGIN_JOB_NAME="previous attempt"
244+
fi
245+
246+
echo "Smart retry enabled: filtering to $FILTERED_WORK_UNITS work units"
247+
248+
# Create Buildkite annotation for visibility
249+
# Use unique context per job to support multiple retries
250+
cat << EOF | buildkite-agent annotate --style info --context "smart-retry-$BUILDKITE_JOB_ID"
251+
Rerunning failed build job [$ORIGIN_JOB_NAME]($BUILD_SCAN_URL)
252+
253+
**Gradle Tasks with Failures:** $FILTERED_WORK_UNITS
254+
255+
This retry will skip test tasks that had no failures in the previous run.
256+
EOF
257+
else
258+
echo "Smart Retry API Error"
259+
echo "Failed to fetch failed tests from Develocity API"
260+
echo "Smart retry will be disabled - all tests will run."
261+
SMART_RETRY_STATUS="failed"
262+
SMART_RETRY_DETAILS="API request failed"
263+
fi
264+
fi
265+
else
266+
echo "Smart Retry Configuration Issue"
267+
echo "Could not find build scan ID in metadata."
268+
echo "Smart retry will be disabled for this run."
269+
SMART_RETRY_STATUS="failed"
270+
SMART_RETRY_DETAILS="No build scan ID in metadata"
271+
fi
272+
else
273+
echo "Smart Retry Configuration Issue"
274+
echo "Could not find origin job ID for retry."
275+
echo "Smart retry will be disabled for this run."
276+
SMART_RETRY_STATUS="failed"
277+
SMART_RETRY_DETAILS="No origin job ID found"
278+
fi
279+
else
280+
echo "Smart Retry API Error"
281+
echo "Failed to fetch build information from Buildkite API"
282+
echo "Smart retry will be disabled - all tests will run."
283+
SMART_RETRY_STATUS="failed"
284+
SMART_RETRY_DETAILS="Buildkite API request failed"
285+
fi
286+
287+
# Store metadata for tracking and analysis
288+
buildkite-agent meta-data set "smart-retry-status" "$SMART_RETRY_STATUS" 2>/dev/null || true
289+
if [[ -n "$SMART_RETRY_DETAILS" ]]; then
290+
buildkite-agent meta-data set "smart-retry-details" "$SMART_RETRY_DETAILS" 2>/dev/null || true
291+
fi
292+
if [[ -n "$BUILD_SCAN_URL" ]]; then
293+
buildkite-agent meta-data set "origin-build-scan" "$BUILD_SCAN_URL" 2>/dev/null || true
294+
fi
295+
fi
296+
144297
# Amazon Linux 2 has DNS resolution issues with resource-based hostnames in EC2
145298
# We have many functional tests that try to lookup and resolve the hostname of the local machine in a particular way
146299
# And they fail. This sets up a manual entry for the hostname in dnsmasq.

0 commit comments

Comments
 (0)