Skip to content

Commit

Permalink
Dump MongoDB db at the end of scenarios
Browse files Browse the repository at this point in the history
Issue: ZENKO-4898
  • Loading branch information
williamlardier committed Sep 24, 2024
1 parent 2d730a7 commit 241c291
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/actions/archive-artifacts/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 241c291

Please sign in to comment.