diff --git a/.github/actions/archive-artifacts/action.yaml b/.github/actions/archive-artifacts/action.yaml index 0f18c7e653..3b86fb69b9 100644 --- a/.github/actions/archive-artifacts/action.yaml +++ b/.github/actions/archive-artifacts/action.yaml @@ -42,3 +42,25 @@ runs: sh -c "kubectl exec -i -n ${NAMESPACE} kcat -- \ kcat -L -b ${KAFKA_SERVICE} -t {} -C -o beginning -e -q -J \ > /tmp/artifacts/data/${STAGE}/kafka-messages-{}.log" + - name: Dump MongoDB + shell: bash + continue-on-error: true + run: |- + set -exu + + ZENKO_MONGODB_DATABASE=${ZENKO_MONGODB_DATABASE:-zenko-database} + MONGODB_ROOT_USERNAME="${MONGODB_ROOT_USERNAME:-root}" + MONGODB_ROOT_PASSWORD="${MONGODB_ROOT_PASSWORD:-rootpass}" + NAMESPACE=${NAMESPACE:-default} + + # Get the list of collections + MONGODB_COLLECTIONS=$(kubectl exec -n ${NAMESPACE} data-db-mongodb-sharded-mongos-0 -- mongo "${ZENKO_MONGODB_DATABASE}" -u "${MONGODB_ROOT_USERNAME}" -p "${MONGODB_ROOT_PASSWORD}" --authenticationDatabase admin --eval "db.getCollectionNames()" | grep -v '^__') + + # Iterate over collections and dump them to log files using db.getCollection() + for collection in ${MONGODB_COLLECTIONS}; do + kubectl exec -n ${NAMESPACE} data-db-mongodb-sharded-mongos-0 -- mongo "${ZENKO_MONGODB_DATABASE}" -u "${MONGODB_ROOT_USERNAME}" -p "${MONGODB_ROOT_PASSWORD}" --authenticationDatabase admin --eval "db.getCollection('${collection}').find().toArray()" | jq -r '.' > /tmp/artifacts/data/${STAGE}/mongodb-${collection}.log + done + + # Get full collection information and save to a log file (including system collections) + kubectl exec -n ${NAMESPACE} data-db-mongodb-sharded-mongos-0 -- mongo "${ZENKO_MONGODB_DATABASE}" -u "${MONGODB_ROOT_USERNAME}" -p "${MONGODB_ROOT_PASSWORD}" --authenticationDatabase admin --eval "db.getCollectionInfos()" | jq -r '.[] | .name + " " + (.count | tostring)' > /tmp/artifacts/data/${STAGE}/mongodb-collections.log +