Skip to content

Commit

Permalink
Collect test logs into directory and zip it
Browse files Browse the repository at this point in the history
  • Loading branch information
tplavcic committed Oct 17, 2023
1 parent 6956521 commit f59685b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
18 changes: 12 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,21 @@ void pushLogFile(String FILE_NAME) {
}

void pushK8SLogs(String TEST_NAME) {
def LOG_FILE_PATH="e2e-tests/logs/"
def FILE_NAMES="logs_${TEST_NAME}_*"
def LOG_FILE_PATH="e2e-tests/logs"
echo "Push k8s logs to S3!"

withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', accessKeyVariable: 'AWS_ACCESS_KEY_ID', credentialsId: 'AMI/OVF', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]) {
sh """
S3_PATH=s3://percona-jenkins-artifactory/\$JOB_NAME/\$(git rev-parse --short HEAD)/logs/
aws s3 ls \$S3_PATH || :
aws s3 rm \$S3_PATH --recursive --exclude "*" --include "${FILE_NAMES}" || :
aws s3 cp --quiet ${LOG_FILE_PATH} \$S3_PATH --recursive --exclude "*" --include "$FILE_NAMES" || :
if [ -d "${LOG_FILE_PATH}/${TEST_NAME}" ]; then
zip -r ${TEST_NAME}.zip ${LOG_FILE_PATH}/${TEST_NAME} || :
rm -rf ${LOG_FILE_PATH}/${TEST_NAME}
S3_PATH=s3://percona-jenkins-artifactory/\$JOB_NAME/\$(git rev-parse --short HEAD)/logs
aws s3 ls \$S3_PATH/ || :
aws s3 rm \$S3_PATH/${TEST_NAME}.zip || :
aws s3 cp --quiet ${TEST_NAME}.zip \$S3_PATH/ || :
rm -f ${TEST_NAME}.zip
fi
"""
}
}
Expand Down Expand Up @@ -266,6 +271,7 @@ pipeline {
CLUSTER_NAME = sh(script: "echo jen-psmdb-${env.CHANGE_ID}-${GIT_SHORT_COMMIT}-${env.BUILD_NUMBER} | tr '[:upper:]' '[:lower:]'", , returnStdout: true).trim()
AUTHOR_NAME = sh(script: "echo ${CHANGE_AUTHOR_EMAIL} | awk -F'@' '{print \$1}'", , returnStdout: true).trim()
ENABLE_LOGGING = "true"
ENABLE_LOG_COLLECT = "true"
}
agent {
label 'docker'
Expand Down
23 changes: 12 additions & 11 deletions e2e-tests/functions
Original file line number Diff line number Diff line change
Expand Up @@ -1300,28 +1300,29 @@ function generate_vs_json() {
}

collect_k8s_logs() {
if [[ ${ENABLE_LOGGING} == "true" ]]; then
rm -f ${logs_dir}/logs_${test_name}_* || :

if [[ ${ENABLE_LOG_COLLECT} == "true" ]]; then
local check_namespaces="${namespace}${OPERATOR_NS:+ $OPERATOR_NS}"
local logs_path="${logs_dir}/${test_name}"
rm -rf ${logs_path} || :
mkdir -p $logs_path

for ns in ${check_namespaces}; do
local pods=$(kubectl_bin get pods -n "${ns}" -o name | awk -F "/" '{print $2}')
for p in ${pods}; do
kubectl_bin -n "${ns}" describe pod ${p} >${logs_dir}/logs_${test_name}_${ns}_${p}.dsc || :
kubectl_bin -n "${ns}" describe pod ${p} >${logs_path}/pod_${ns}_${p}.dsc || :
local containers=$(kubectl_bin -n "${ns}" get pod ${p} -o jsonpath='{.spec.containers[*].name}')
for c in ${containers}; do
kubectl_bin -n "${ns}" logs ${p} -c ${c} >${logs_dir}/logs_${test_name}_${ns}_${p}_${c}.txt || :
echo logs saved in: ${logs_dir}/logs_${test_name}_${p}_${c}.txt
kubectl_bin -n "${ns}" logs ${p} -c ${c} >${logs_path}/${ns}_${p}_${c}.log || :
echo "logs saved in: ${logs_path}/${ns}_${p}_${c}.log"
done
done
done
for object in psmdb psmdb-backup psmdb-restore pods deployments services events sts; do
echo "##### START: ${ns}: ${object} #####" >>${logs_dir}/logs_${test_name}_${ns}_simple.txt
kubectl_bin get ${object} -n "${ns}" >>${logs_dir}/logs_${test_name}_${ns}_simple.txt || :
echo "##### END: ${ns}: ${object} ####\n" >>${logs_dir}/logs_${test_name}_${ns}_simple.txt
kubectl_bin get ${object} -n "${ns}" -oyaml >${logs_dir}/logs_${test_name}_${ns}_${object}.yaml || :
kubectl_bin describe ${object} -n "${ns}" >${logs_dir}/logs_${test_name}_${ns}_${object}.dsc || :
echo "##### START: ${ns}: ${object} #####" >>${logs_path}/_overview_${ns}.txt
kubectl_bin get ${object} -n "${ns}" >>${logs_path}/_overview_${ns}.txt || :
echo -e "##### END: ${ns}: ${object} ####\n" >>${logs_path}/_overview_${ns}.txt
kubectl_bin get ${object} -n "${ns}" -oyaml >${logs_path}/${object}_${ns}.yaml || :
kubectl_bin describe ${object} -n "${ns}" >${logs_path}/${object}_${ns}.dsc || :
done
fi
}
Expand Down

0 comments on commit f59685b

Please sign in to comment.