Skip to content

Commit

Permalink
Improved failure logging during federated reporting schema import
Browse files Browse the repository at this point in the history
Saves full log in /var/cfengine/outputs

TODO: clean up old /var/cfengine/outputs/*-schema-attach-*.log files

Ticket: ENT-10789
Changelog: title
  • Loading branch information
craigcomstock committed Nov 20, 2023
1 parent f56ea0e commit 2311970
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions templates/federated_reporting/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ source "$(dirname "$0")/log.sh"
source "$(dirname "$0")/parallel.sh"

# check that we have all the variables we need
true "${WORKDIR?undefined}"
true "${CFE_BIN_DIR?undefined}"
true "${CFE_FR_SUPERHUB_DROP_DIR?undefined}"
true "${CFE_FR_SUPERHUB_IMPORT_DIR?undefined}"
Expand Down Expand Up @@ -119,26 +120,35 @@ if [ "$CFE_FR_HANDLE_DUPLICATES" = "yes" ]; then
fi
fi

failed=0
one_failed=0
any_failed=0
log "Attaching schemas"
for file in $dump_files; do
if [ ! -f "${file}.failed" ]; then
hostkey=$(basename "$file" | cut -d. -f1)
logfile="$WORKDIR"/outputs/"$hostkey"-schema-attach-$(date +%F-%T)-failure.log
"$CFE_BIN_DIR"/psql -U $CFE_FR_DB_USER -d cfdb --set "ON_ERROR_STOP=1" \
-c "SET SCHEMA 'public'; SELECT attach_feeder_schema('$hostkey', ARRAY[$table_whitelist]);" \
> schema_attach.log 2>&1 || failed=1
> "$logfile" 2>&1 || one_failed=1
if [ "$one_failed" = "0" ]; then
rm -f "$logfile"
else
any_failed=1
log "Attaching schemas: FAILED for $hostkey, check $logfile for details"
log "last 10 lines of $logfile"
tail -n 10 "$logfile"
fi
one_failed=0
else
rm -f "${file}.failed"
fi
done
if [ "$failed" = "0" ]; then
if [ "$any_failed" = "0" ]; then
log "Attaching schemas: DONE"
else
# attach_feeder_schema() makes sure the feeder's import schema is removed in
# case of failure
log "Attaching schemas: FAILED"
log "last 10 lines of schema_attach.log"
tail -n 10 schema_attach.log
exit 1
fi

Expand Down

0 comments on commit 2311970

Please sign in to comment.