From a35de6820758c4bf2eb6d793d0509c7aa1152c7d Mon Sep 17 00:00:00 2001 From: black-dragon74 Date: Fri, 29 Mar 2024 15:24:04 +0530 Subject: [PATCH 1/2] Add support for --since and --since-time flags The must-gather now filters its logs based on the above parameters. The said parameters are provided by the OC cli as ENV values. Signed-off-by: black-dragon74 --- collection-scripts/gather | 7 +++++ .../gather_namespaced_resources | 16 +++++------ collection-scripts/gather_noobaa_resources | 2 +- collection-scripts/gather_odf_client | 8 +++--- collection-scripts/utils.sh | 27 +++++++++++++++++++ 5 files changed, 47 insertions(+), 13 deletions(-) diff --git a/collection-scripts/gather b/collection-scripts/gather index 3d17c57..657f360 100755 --- a/collection-scripts/gather +++ b/collection-scripts/gather @@ -124,11 +124,18 @@ mkdir -p ${BASE_COLLECTION_PATH} # shellcheck disable=SC1091 . utils.sh +# Parse the ENV for collection filters +parse_since_time + # timestamp for starting of the script START_TIME=$(date +%r) start=$(date +%s) dbglog "collection started at: ${START_TIME}" +if [ -n "${LOG_FILTER_ARGS:-}" ]; then + dbglog "Logs will be filtered using: ${LOG_FILTER_ARGS}" +fi + # Call pre-install.sh, see commit msg pre-install.sh ${BASE_COLLECTION_PATH} diff --git a/collection-scripts/gather_namespaced_resources b/collection-scripts/gather_namespaced_resources index 2b393a5..0f8f909 100755 --- a/collection-scripts/gather_namespaced_resources +++ b/collection-scripts/gather_namespaced_resources @@ -76,11 +76,11 @@ oc_yamls+=("alertmanagerconfig") for INSTALL_NAMESPACE in $PRODUCT_NAMESPACE $INSTALL_NAMESPACES $MANAGED_FUSION_NAMESPACE $OPERATOR_NAMESPACE; do dbglog "collecting dump of namespace ${INSTALL_NAMESPACE}" - { oc adm inspect --dest-dir="${BASE_COLLECTION_PATH}" ns/"${INSTALL_NAMESPACE}" 2>&1; } | dbglog + { oc adm inspect --dest-dir="${BASE_COLLECTION_PATH}" "${LOG_FILTER_ARGS}" ns/"${INSTALL_NAMESPACE}" 2>&1; } | dbglog dbglog "collecting dump of clusterresourceversion" for oc_yaml in "${oc_yamls[@]}"; do # shellcheck disable=SC2129 - { oc adm inspect -n "${INSTALL_NAMESPACE}" --dest-dir="${BASE_COLLECTION_PATH}" "${oc_yaml}" 2>&1; } | dbglog + { oc adm inspect -n "${INSTALL_NAMESPACE}" --dest-dir="${BASE_COLLECTION_PATH}" "${LOG_FILTER_ARGS}" "${oc_yaml}" 2>&1; } | dbglog done # Create the dir for oc_output @@ -122,34 +122,34 @@ mkdir -p "${BASE_COLLECTION_PATH}/namespaces/all/" # Run the Collection of Resources using must-gather for resource in "${resources[@]}"; do dbglog "collecting dump of ${resource}" - { oc adm inspect --all-namespaces --dest-dir="${BASE_COLLECTION_PATH}/namespaces/all/" "${resource}" 2>&1; } | dbglog + { oc adm inspect --all-namespaces --dest-dir="${BASE_COLLECTION_PATH}/namespaces/all/" "${LOG_FILTER_ARGS}" "${resource}" 2>&1; } | dbglog done # For pvc of all namespaces dbglog "collecting dump of oc get pvc all namespaces" { oc get pvc --all-namespaces; } >>"${BASE_COLLECTION_PATH}/namespaces/all/pvc_all_namespaces" -{ oc adm inspect --all-namespaces --dest-dir="${BASE_COLLECTION_PATH}/namespaces/all/" pvc 2>&1; } | dbglog +{ oc adm inspect --all-namespaces --dest-dir="${BASE_COLLECTION_PATH}/namespaces/all/" "${LOG_FILTER_ARGS}" pvc 2>&1; } | dbglog # For volumesnapshot of all namespaces dbglog "collecting dump of oc get volumesnapshot all namespaces" { oc get volumesnapshot --all-namespaces; } >>"${BASE_COLLECTION_PATH}/namespaces/all/get_volumesnapshot_all_namespaces" { oc describe volumesnapshot --all-namespaces; } >>"${BASE_COLLECTION_PATH}/namespaces/all/desc_volumesnapshot_all_namespaces" -{ oc adm inspect --all-namespaces --dest-dir="${BASE_COLLECTION_PATH}/namespaces/all/" volumesnapshot 2>&1; } | dbglog +{ oc adm inspect --all-namespaces --dest-dir="${BASE_COLLECTION_PATH}/namespaces/all/" "${LOG_FILTER_ARGS}" volumesnapshot 2>&1; } | dbglog # For obc of all namespaces dbglog "collecting dump of oc get obc all namespaces" { oc get obc --all-namespaces; } >>"${BASE_COLLECTION_PATH}/namespaces/all/obc_all_namespaces" -{ oc adm inspect --all-namespaces --dest-dir="${BASE_COLLECTION_PATH}/namespaces/all/" obc 2>&1; } | dbglog +{ oc adm inspect --all-namespaces --dest-dir="${BASE_COLLECTION_PATH}/namespaces/all/" "${LOG_FILTER_ARGS}" obc 2>&1; } | dbglog # For VolumeReplication of all namespaces dbglog "collecting dump of oc get volumereplication all namespaces" { oc get volumereplication --all-namespaces; } >>"${BASE_COLLECTION_PATH}/namespaces/all/vr_all_namespaces" -{ oc adm inspect --all-namespaces --dest-dir="${BASE_COLLECTION_PATH}/namespaces/all/" volumereplication 2>&1; } | dbglog +{ oc adm inspect --all-namespaces --dest-dir="${BASE_COLLECTION_PATH}/namespaces/all/" "${LOG_FILTER_ARGS}" volumereplication 2>&1; } | dbglog # For VolumeReplicationGroups of all namespaces dbglog "collecting dump of oc get volumereplicationgroups all namespaces" { oc get volumereplicationgroups --all-namespaces; } >>"${BASE_COLLECTION_PATH}/namespaces/all/vrg_all_namespaces" -{ oc adm inspect --all-namespaces --dest-dir="${BASE_COLLECTION_PATH}/namespaces/all/" vrg 2>&1; } | dbglog +{ oc adm inspect --all-namespaces --dest-dir="${BASE_COLLECTION_PATH}/namespaces/all/" "${LOG_FILTER_ARGS}" vrg 2>&1; } | dbglog # Collect details of storageclassclaim of all namespaces for managed services dbglog "collecting dump of oc get storageclassclaim all namespaces" diff --git a/collection-scripts/gather_noobaa_resources b/collection-scripts/gather_noobaa_resources index 906f4c2..c043a9d 100755 --- a/collection-scripts/gather_noobaa_resources +++ b/collection-scripts/gather_noobaa_resources @@ -47,7 +47,7 @@ noobaa diagnose --dir "${NOOBAA_COLLLECTION_PATH}"/raw_output/ --namespace opens # Run the Collection of NooBaa Resources using must-gather for resource in "${noobaa_resources[@]}"; do dbglog "collecting dump of ${resource}" - { oc adm inspect --all-namespaces --dest-dir="${NOOBAA_COLLLECTION_PATH}" "${resource}"; } >>"${BASE_COLLECTION_PATH}"/gather-debug.log 2>&1 + { oc adm inspect --all-namespaces --dest-dir="${NOOBAA_COLLLECTION_PATH}" "${LOG_FILTER_ARGS}" "${resource}"; } >>"${BASE_COLLECTION_PATH}"/gather-debug.log 2>&1 done # Collect logs for all noobaa pods using oc logs diff --git a/collection-scripts/gather_odf_client b/collection-scripts/gather_odf_client index cdfa20b..5523265 100755 --- a/collection-scripts/gather_odf_client +++ b/collection-scripts/gather_odf_client @@ -53,11 +53,11 @@ client_commands_desc+=("storageclassclaims") for INSTALL_NAMESPACE in $CLIENT_OPERATOR_NAMESPACE; do dbglog "collecting dump of namespace ${INSTALL_NAMESPACE}" - { oc adm inspect --dest-dir="${BASE_COLLECTION_PATH}" ns/"${INSTALL_NAMESPACE}" 2>&1; } | dbglog + { oc adm inspect --dest-dir="${BASE_COLLECTION_PATH}" "${LOG_FILTER_ARGS}" ns/"${INSTALL_NAMESPACE}" 2>&1; } | dbglog # Run the Collection of oc yaml outputs for oc_yaml in "${oc_yamls[@]}"; do # shellcheck disable=SC2129 - { oc adm inspect -n "${INSTALL_NAMESPACE}" --dest-dir="${BASE_COLLECTION_PATH}" "${oc_yaml}" 2>&1; } | dbglog + { oc adm inspect -n "${INSTALL_NAMESPACE}" --dest-dir="${BASE_COLLECTION_PATH}" "${LOG_FILTER_ARGS}" "${oc_yaml}" 2>&1; } | dbglog done # Create the dir for oc_output @@ -82,11 +82,11 @@ done for INSTALL_NAMESPACE in $STORAGE_CLIENT_NAMESPACE; do dbglog "collecting dump of namespace ${INSTALL_NAMESPACE}" - { oc adm inspect --dest-dir="${BASE_COLLECTION_PATH}" ns/"${INSTALL_NAMESPACE}" 2>&1; } | dbglog + { oc adm inspect --dest-dir="${BASE_COLLECTION_PATH}" "${LOG_FILTER_ARGS}" ns/"${INSTALL_NAMESPACE}" 2>&1; } | dbglog # Run the Collection of oc yaml outputs for oc_yaml in "${client_oc_yamls[@]}"; do # shellcheck disable=SC2129 - { oc adm inspect -n "${INSTALL_NAMESPACE}" --dest-dir="${BASE_COLLECTION_PATH}" "${oc_yaml}" 2>&1; } | dbglog + { oc adm inspect -n "${INSTALL_NAMESPACE}" --dest-dir="${BASE_COLLECTION_PATH}" "${LOG_FILTER_ARGS}" "${oc_yaml}" 2>&1; } | dbglog done # Create the dir for oc_output diff --git a/collection-scripts/utils.sh b/collection-scripts/utils.sh index d9d8d08..227e6bb 100755 --- a/collection-scripts/utils.sh +++ b/collection-scripts/utils.sh @@ -32,6 +32,33 @@ dbglogf() { echo -e "${msg}" | tee -a "${1}" } +# Read the `MUST_GATHER_SINCE` and `MUST_GATHER_SINCE_TIME` +# from the ENV and export it for use in the gather scripts +# +# Acc to spec, only one of `MUST_GATHER_SINCE` +# or `MUST_GATHER_SINCE_TIME` can be used. +parse_since_time() { + local FILTER_ARGS="" + + # We do not need to validate the values here, they are validated + # by the oc cli. + # Ref: https://github.com/openshift/oc/commit/1fc5c7d79ff5c2fa19c35b7a004dc99eb3330806 + if [ -n "${MUST_GATHER_SINCE:-}" ]; then + FILTER_ARGS="--since=${MUST_GATHER_SINCE}" + fi + + if [ -n "${MUST_GATHER_SINCE_TIME:-}" ]; then + FILTER_ARGS="--since-time=${MUST_GATHER_SINCE_TIME}" + fi + + # It is possible that user is not providing any filters + # We do not export the variable in that case + if [ -n "${FILTER_ARGS}" ]; then + export LOG_FILTER_ARGS="${FILTER_ARGS}" + fi +} + # Export the functions so that the file needs to be sourced only once export -f dbglog export -f dbglogf +export -f parse_since_time From fb57ee3c0f7c7cac14fb4413060212fc2a25bd9f Mon Sep 17 00:00:00 2001 From: black-dragon74 Date: Thu, 4 Apr 2024 15:11:12 +0530 Subject: [PATCH 2/2] Add since time support to journalctl logs Signed-off-by: black-dragon74 --- collection-scripts/gather_ceph_logs | 6 +++--- collection-scripts/utils.sh | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/collection-scripts/gather_ceph_logs b/collection-scripts/gather_ceph_logs index d84f27c..320112a 100755 --- a/collection-scripts/gather_ceph_logs +++ b/collection-scripts/gather_ceph_logs @@ -34,8 +34,8 @@ for ns in $namespaces; do oc debug nodes/"${node}" < journal_"${node}".gz - journalctl -k -o short-iso-precise --utc --no-hostname | gzip > kernel_"${node}".gz + journalctl --since "${JCTL_FILTER_ARGS}" | gzip > journal_"${node}".gz + journalctl --since "${JCTL_FILTER_ARGS}" -k -o short-iso-precise --utc --no-hostname | gzip > kernel_"${node}".gz exit CMDS done @@ -75,4 +75,4 @@ CMDS done dbglog "ceph core dump collection completed" -done \ No newline at end of file +done diff --git a/collection-scripts/utils.sh b/collection-scripts/utils.sh index 227e6bb..e9892a6 100755 --- a/collection-scripts/utils.sh +++ b/collection-scripts/utils.sh @@ -56,6 +56,27 @@ parse_since_time() { if [ -n "${FILTER_ARGS}" ]; then export LOG_FILTER_ARGS="${FILTER_ARGS}" fi + + # Journalctl doesn't support the same type of since and + # since-time args. Adapt the logic for journalctl + local JRNL_FILTER="" + + if [ -n "${MUST_GATHER_SINCE:-}" ]; then + JRNL_FILTER="${MUST_GATHER_SINCE} ago" + fi + + # This section adapts an ISO time like: 2024-04-04T09:23:26Z + # To 2024-04-04 09:23:26, a format that journalctl is happy with + if [ -n "${MUST_GATHER_SINCE_TIME:-}" ]; then + JRNL_FILTER=$(echo "${MUST_GATHER_SINCE_TIME}" | sed 's/T/ /; s/Z//') + fi + + # If the var is unset, export the default as 2 days ago + if [ -n "${JRNL_FILTER}" ]; then + export JCTL_FILTER_ARGS="${JRNL_FILTER}" + else + export JCTL_FILTER_ARGS="2 days ago" + fi } # Export the functions so that the file needs to be sourced only once