Skip to content
Merged
182 changes: 12 additions & 170 deletions .gitlab/ssi_gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,61 +26,10 @@ ssi_tests:
variables:
# Force gitlab to keep the exit code as 3 if the job fails with exit code 3
FF_USE_NEW_BASH_EVAL_STRATEGY: true
after_script: |
export DATADOG_SITE="${DATADOG_SITE:-datadoghq.com}"
DATADOG_API_KEY=$(read-system-tests-secret test_optimization dd_api_key) || DATADOG_API_KEY=""
export DATADOG_API_KEY
# Tag the job as part of the official system-tests workflow, first so it's done even if a later command fails.
# Skip the tag if the API key could not be fetched.
if [ -n "$DATADOG_API_KEY" ]; then
datadog-ci tag --level job --tags "ci.framework.name:system-tests" || echo "Failed to tag the job with ci.framework.name:system-tests"
else
echo "Failed to fetch the Datadog API key, skipping the ci.framework.name:system-tests tag"
fi

SCENARIO_SUFIX=$(echo "$SCENARIO" | tr "[:upper:]" "[:lower:]")
mkdir -p reports/
if [ "$CI_PROJECT_NAME" = "system-tests" ]; then
cp -R logs_"${SCENARIO_SUFIX}" reports/
else
cp -R /system-tests/logs_"${SCENARIO_SUFIX}" reports/
fi
if [ "$CI_COMMIT_BRANCH" = "main" ] && [ "$CI_PROJECT_NAME" = "system-tests" ]; then
export FP_IMPORT_URL=$(read-system-tests-secret fpd fp_import_url)
export FP_API_KEY=$(read-system-tests-secret fpd fp_api_key)
for folder in reports/logs*/ ; do
echo "Checking folder: ${folder}"
for filename in ./${folder}feature_parity.json; do
if [ -e ${filename} ]
then
echo "Processing report: ${filename}"
curl -X POST ${FP_IMPORT_URL} --fail --header "Content-Type: application/json" --header "FP_API_KEY: ${FP_API_KEY}" --data "@${filename}" --include
fi
done
done
fi

# Push JUnit results to Datadog Test Optimization
export DD_TAGS="test.configuration.ci_environment:${CI_ENVIRONMENT:-prod}"
if compgen -G "reports/logs*/reportJunit.xml" > /dev/null; then
datadog-ci junit upload \
reports/logs*/reportJunit.xml \
--service system-tests \
--env ci \
--verbose \
--xpath-tag "test.codeowners=/testcase/properties/property[@name='test.codeowners']"
else
echo "No reports/logs*/reportJunit.xml found; skipping Test Optimization upload"
fi

# Render all report logs as collapsible sections + run summary + banner.
if [ "$CI_PROJECT_NAME" = "system-tests" ]; then
SCRIPTS_DIR="./utils/scripts"
else
SCRIPTS_DIR="/system-tests/utils/scripts"
fi
export SCENARIO_SUFIX
bash "${SCRIPTS_DIR}/gitlab_print_logs.sh"
# gitlab_exporter.py points it to the system-tests checkout when another repository runs the job.
SYSTEM_TESTS_DIR: $CI_PROJECT_DIR
after_script:
- bash "${SYSTEM_TESTS_DIR}/utils/scripts/gitlab_finalize_job.sh" --profile docker
retry:
max: 2
when:
Expand Down Expand Up @@ -108,6 +57,8 @@ ssi_tests:
variables:
# Force gitlab to keep the exit code as 3 if the job fails with exit code 3
FF_USE_NEW_BASH_EVAL_STRATEGY: true
# gitlab_exporter.py points it to the system-tests checkout when another repository runs the job.
SYSTEM_TESTS_DIR: $CI_PROJECT_DIR
script:
- |
if [[ -n "${DD_INSTALL_SCRIPT_VERSION}" ]]; then
Expand All @@ -124,80 +75,8 @@ ssi_tests:
# Run the tests and capture stdout+stderr to a file
set -o pipefail
timeout 3000 ./run.sh "$SCENARIO" --vm-weblog "${WEBLOG}" --vm-env "${ONBOARDING_FILTER_ENV}" --vm-library "${TEST_LIBRARY}" --vm-provider aws --vm-default-vms All --vm-only "${VM}" --report-run-url "${CI_JOB_URL}" --report-environment "${ONBOARDING_FILTER_ENV}" 2>&1 | tee "${CI_PROJECT_DIR}/run_output.log"
after_script: |
# Tag the job as part of the official system-tests workflow, first so it's done even if a later command fails.
# The image does not ship datadog-ci, so the standalone binary is downloaded.
# Skip the tag if the API key could not be fetched.
DATADOG_API_KEY=$(read-system-tests-secret test_optimization dd_api_key) || DATADOG_API_KEY=""
if [ -n "$DATADOG_API_KEY" ]; then
DATADOG_SITE="${DATADOG_SITE:-datadoghq.com}" DATADOG_API_KEY="${DATADOG_API_KEY}" datadog-ci tag --level job --tags "ci.framework.name:system-tests" \
|| echo "Failed to tag the job with ci.framework.name:system-tests"
else
echo "Failed to fetch the Datadog API key, skipping the ci.framework.name:system-tests tag"
fi

# Only fetch FP params on main in system-tests repo (use default CI creds)
if [ "$CI_COMMIT_BRANCH" = "main" ] && [ "$CI_PROJECT_NAME" = "system-tests" ]; then
export FP_IMPORT_URL=$(read-system-tests-secret fpd fp_import_url)
export FP_API_KEY=$(read-system-tests-secret fpd fp_api_key)
fi
# Re-establish AWS credentials for S3 operations (after_script runs in new shell session)
echo "Setting up AWS credentials for after_script..."
mkdir -p ~/.aws

# Clean up any existing config and recreate it
rm -f ~/.aws/config
read-system-tests-secret apm-ecosystems-reliability-profile config > ~/.aws/config
export AWS_PROFILE=apm-ecosystems-reliability-ci

SCENARIO_SUFIX=$(echo "$SCENARIO" | tr "[:upper:]" "[:lower:]")
mkdir -p reports/
# Upload logs to S3 and delete large files
# When this template is included from downstream repos (dd-trace-*), the
# system-tests checkout lives under a `system-tests/` subdirectory, so
# all relative paths into the system-tests repo need that prefix.
if [ "$CI_PROJECT_NAME" = "system-tests" ]; then
LOGS_FOLDER="logs_${SCENARIO_SUFIX}"
SCRIPTS_DIR="./utils/scripts"
else
LOGS_FOLDER="system-tests/logs_${SCENARIO_SUFIX}"
SCRIPTS_DIR="./system-tests/utils/scripts"
fi
AWS_CONSOLE_URL=""
if [ -d "$LOGS_FOLDER" ]; then
EXECUTION_UNIQUE_IDENTIFIER="${CI_PIPELINE_ID:-datadog-local}"
LAST_DIRECTORY=$(basename "$LOGS_FOLDER")
S3_BUCKET="system-tests-aws-ssi-apm"
S3_DESTINATION="s3://${S3_BUCKET}/${EXECUTION_UNIQUE_IDENTIFIER}/${LAST_DIRECTORY}/${VM}_${WEBLOG}/"
AWS_CONSOLE_URL="https://s3.console.aws.amazon.com/s3/buckets/${S3_BUCKET}?region=us-east-1&prefix=${EXECUTION_UNIQUE_IDENTIFIER}/${LAST_DIRECTORY}/${VM}_${WEBLOG}/"

aws s3 cp "$LOGS_FOLDER" "$S3_DESTINATION" --recursive --quiet || echo "Failed to upload logs to S3"

# Delete large files (>50MB) to avoid CI/CD archiving
find "$LOGS_FOLDER" -type f -size +50M -exec sh -c 'echo "Deleting large file ($(du -h "$1" | cut -f1)): $1" && rm "$1"' _ {} \; || echo "Failed to delete some large files"
fi

# Logs to be archived by gitlab
cp -R "$LOGS_FOLDER" reports/

# Feature parity
if [ "$CI_COMMIT_BRANCH" = "main" ] && [ "$CI_PROJECT_NAME" = "system-tests" ]; then
for folder in reports/logs*/ ; do
echo "Checking folder: ${folder}"
for filename in ./${folder}*_feature_parity.json; do
if [ -e ${filename} ]
then
echo "Processing report: ${filename}"
curl -X POST ${FP_IMPORT_URL} --fail --header "Content-Type: application/json" --header "FP_API_KEY: ${FP_API_KEY}" --data "@${filename}" --include
fi
done
done
fi

# Render all report logs as collapsible sections + run summary + banner.
export SCENARIO_SUFIX AWS_CONSOLE_URL
bash "${SCRIPTS_DIR}/gitlab_print_logs.sh"

after_script:
- bash "${SYSTEM_TESTS_DIR}/utils/scripts/gitlab_finalize_job.sh" --profile aws
retry:
max: 2
when:
Expand Down Expand Up @@ -227,6 +106,8 @@ ssi_tests:
variables:
# Force gitlab to keep the exit code as 3 if the job fails with exit code 3
FF_USE_NEW_BASH_EVAL_STRATEGY: true
# gitlab_exporter.py points it to the system-tests checkout when another repository runs the job.
SYSTEM_TESTS_DIR: $CI_PROJECT_DIR
script:
- |
# Wrap the build steps (runner image, venv, ECR login, weblog image) in a
Expand Down Expand Up @@ -254,47 +135,8 @@ ssi_tests:
set -o pipefail
./run.sh ${K8S_SCENARIO} --k8s-library ${TEST_LIBRARY} --k8s-weblog ${K8S_WEBLOG} --k8s-weblog-img ${K8S_WEBLOG_IMG}:${TAG_NAME} --k8s-lib-init-img ${K8S_LIB_INIT_IMG} --k8s-injector-img ${K8S_INJECTOR_IMG:-None} --k8s-cluster-img ${K8S_CLUSTER_IMG:-None} --report-run-url $CI_JOB_URL --report-environment ${REPORT_ENVIRONMENT} 2>&1 | tee "${CI_PROJECT_DIR}/run_output.log"

after_script: |
# Tag the job as part of the official system-tests workflow, first so it's done even if a later command fails.
# Skip the tag if the API key could not be fetched.
TAG_DD_API_KEY=$(read-system-tests-secret test_optimization dd_api_key) || TAG_DD_API_KEY=""
if [ -n "$TAG_DD_API_KEY" ]; then
DATADOG_SITE="${DATADOG_SITE:-datadoghq.com}" DATADOG_API_KEY="${TAG_DD_API_KEY}" \
datadog-ci tag --level job --tags "ci.framework.name:system-tests" || echo "Failed to tag the job with ci.framework.name:system-tests"
else
echo "Failed to fetch the Datadog API key, skipping the ci.framework.name:system-tests tag"
fi

kind delete clusters --all || true
mkdir -p reports
if [ "$CI_PROJECT_NAME" = "system-tests" ]; then
cp -R logs_*/ reports/
else
cp -R /system-tests/logs_*/ reports/
fi
if [ "$CI_COMMIT_BRANCH" = "main" ] && [ "$CI_PROJECT_NAME" = "system-tests" ]; then
export FP_IMPORT_URL=$(read-system-tests-secret fpd fp_import_url)
export FP_API_KEY=$(read-system-tests-secret fpd fp_api_key)
for folder in reports/logs*/ ; do
echo "Checking folder: ${folder}"
for filename in ./${folder}feature_parity.json; do
if [ -e ${filename} ]
then
echo "Processing report: ${filename}"
curl -X POST ${FP_IMPORT_URL} --fail --header "Content-Type: application/json" --header "FP_API_KEY: ${FP_API_KEY}" --data "@${filename}" --include
fi
done
done
fi

# Render all report logs as collapsible sections + run summary + banner.
if [ "$CI_PROJECT_NAME" = "system-tests" ]; then
SCRIPTS_DIR="./utils/scripts"
else
SCRIPTS_DIR="/system-tests/utils/scripts"
fi
export SCENARIO_SUFIX=$(echo "${K8S_SCENARIO:-logs}" | tr "[:upper:]" "[:lower:]")
bash "${SCRIPTS_DIR}/gitlab_print_logs.sh"
after_script:
- bash "${SYSTEM_TESTS_DIR}/utils/scripts/gitlab_finalize_job.sh" --profile k8s
retry:
max: 2
when:
Expand Down
Loading
Loading