-
Notifications
You must be signed in to change notification settings - Fork 235
MG-233: compress service and window node logs #554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
bd488df
6ac1d3e
e8ce490
49394e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,19 +32,34 @@ get_log_collection_args() { | |||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| # REDUCE_LOGS: unset = default (--rotated-pod-logs). If set, only skip_rotated_logs is allowed. | ||||||||||||||||||
| rotated_pod_logs_arg="--rotated-pod-logs" | ||||||||||||||||||
| # REDUCE_LOGS: unset = defaults. Comma or space separated list of: | ||||||||||||||||||
| # skip_rotated_logs - omit --rotated-pod-logs from oc adm inspect | ||||||||||||||||||
| # compress_service_logs - gzip host service logs (see gather_service_logs_util) | ||||||||||||||||||
| # shellcheck disable=SC2034 | ||||||||||||||||||
| rotated_pod_logs_arg="--rotated-pod-logs" | ||||||||||||||||||
| # shellcheck disable=SC2034 | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason of this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running Hence added the |
||||||||||||||||||
| compress_service_logs="" | ||||||||||||||||||
|
|
||||||||||||||||||
| if [ -n "${REDUCE_LOGS:-}" ]; then | ||||||||||||||||||
| case "${REDUCE_LOGS}" in | ||||||||||||||||||
| skip_rotated_logs) | ||||||||||||||||||
| rotated_pod_logs_arg="" | ||||||||||||||||||
| ;; | ||||||||||||||||||
| *) | ||||||||||||||||||
| echo "ERROR: REDUCE_LOGS must be unset or skip_rotated_logs (got: [${REDUCE_LOGS}])." >&2 | ||||||||||||||||||
| exit 1 | ||||||||||||||||||
| ;; | ||||||||||||||||||
| esac | ||||||||||||||||||
| # Normalize commas to spaces, then validate each option. | ||||||||||||||||||
| # Intentional word-splitting of comma/space separated options. | ||||||||||||||||||
| # shellcheck disable=SC2086 | ||||||||||||||||||
| for reduce_logs_option in ${REDUCE_LOGS//,/ }; do | ||||||||||||||||||
|
Comment on lines
+44
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Avoid pathname expansion while parsing The unquoted expansion on Line 47 performs pathname expansion after word splitting. A value such as Suggested fix- # Normalize commas to spaces, then validate each option.
- # Intentional word-splitting of comma/space separated options.
- # shellcheck disable=SC2086
- for reduce_logs_option in ${REDUCE_LOGS//,/ }; do
+ # Normalize commas to spaces without pathname expansion.
+ local -a reduce_logs_options
+ read -r -a reduce_logs_options <<< "${REDUCE_LOGS//,/ }"
+ for reduce_logs_option in "${reduce_logs_options[@]}"; do📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| case "${reduce_logs_option}" in | ||||||||||||||||||
| skip_rotated_logs) | ||||||||||||||||||
| rotated_pod_logs_arg="" | ||||||||||||||||||
| ;; | ||||||||||||||||||
| compress_service_logs) | ||||||||||||||||||
| compress_service_logs=true | ||||||||||||||||||
| ;; | ||||||||||||||||||
| "") | ||||||||||||||||||
| ;; | ||||||||||||||||||
| *) | ||||||||||||||||||
| echo "ERROR: REDUCE_LOGS unknown value '${reduce_logs_option}'. Allowed: skip_rotated_logs, compress_service_logs (got: [${REDUCE_LOGS}])." >&2 | ||||||||||||||||||
| exit 1 | ||||||||||||||||||
| ;; | ||||||||||||||||||
| esac | ||||||||||||||||||
| done | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| # oc adm node-logs `--since` parameter is not the same as oc adm inspect `--since`. | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,13 +22,21 @@ function collect_service_logs { | |
| fi | ||
|
|
||
| mkdir -p "${DIR_PATH}" | ||
| # Default: uncompressed .log for compatibility with existing tooling. | ||
| # Opt in via REDUCE_LOGS=compress_service_logs (parsed by get_log_collection_args). | ||
| LOG_SUFFIX=".log" | ||
| LOG_PIPE="cat" | ||
| if [[ "${compress_service_logs:-}" == "true" ]]; then | ||
| LOG_SUFFIX=".log.gz" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would this be problematic for customers with existing scripts who rely on these assumptions? should we gate it behind a flag?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added it behind the flag REDUCE_LOGS. It not accepts both |
||
| LOG_PIPE="gzip" | ||
| fi | ||
| for service in "${@}"; do | ||
| echo "INFO: Collecting host service logs for $service" | ||
| if [[ ${selector} =~ '--role=' ]]; then | ||
| oc adm node-logs "${node_log_collection_args:---since=${SINCE_TIMEFRAME:--7d}}" "${selector}" -l kubernetes.io/os=linux -u "${service}" >"${DIR_PATH}/${service}_service.log" & | ||
| oc adm node-logs "${node_log_collection_args:---since=${SINCE_TIMEFRAME:--7d}}" "${selector}" -l kubernetes.io/os=linux -u "${service}" | ${LOG_PIPE} >"${DIR_PATH}/${service}_service${LOG_SUFFIX}" & | ||
| PIDS+=($!) | ||
| else | ||
| oc adm node-logs "${node_log_collection_args:---since=${SINCE_TIMEFRAME:--7d}}" "${selector}" -u "${service}" >"${DIR_PATH}/${service}_service.log" & | ||
| oc adm node-logs "${node_log_collection_args:---since=${SINCE_TIMEFRAME:--7d}}" "${selector}" -u "${service}" | ${LOG_PIPE} >"${DIR_PATH}/${service}_service${LOG_SUFFIX}" & | ||
|
Comment on lines
33
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Because Line 36 and Line 39 run in a pipeline and are backgrounded, Suggested fix for service in "${@}"; do
echo "INFO: Collecting host service logs for $service"
if [[ ${selector} =~ '--role=' ]]; then
- oc adm node-logs "${node_log_collection_args:---since=${SINCE_TIMEFRAME:--7d}}" "${selector}" -l kubernetes.io/os=linux -u "${service}" | ${LOG_PIPE} >"${DIR_PATH}/${service}_service${LOG_SUFFIX}" &
+ if [[ "${LOG_PIPE}" == "cat" ]]; then
+ oc adm node-logs "${node_log_collection_args:---since=${SINCE_TIMEFRAME:--7d}}" "${selector}" -l kubernetes.io/os=linux -u "${service}" >"${DIR_PATH}/${service}_service${LOG_SUFFIX}" &
+ else
+ oc adm node-logs "${node_log_collection_args:---since=${SINCE_TIMEFRAME:--7d}}" "${selector}" -l kubernetes.io/os=linux -u "${service}" | gzip >"${DIR_PATH}/${service}_service${LOG_SUFFIX}" &
+ fi
PIDS+=($!)
else
- oc adm node-logs "${node_log_collection_args:---since=${SINCE_TIMEFRAME:--7d}}" "${selector}" -u "${service}" | ${LOG_PIPE} >"${DIR_PATH}/${service}_service${LOG_SUFFIX}" &
+ if [[ "${LOG_PIPE}" == "cat" ]]; then
+ oc adm node-logs "${node_log_collection_args:---since=${SINCE_TIMEFRAME:--7d}}" "${selector}" -u "${service}" >"${DIR_PATH}/${service}_service${LOG_SUFFIX}" &
+ else
+ oc adm node-logs "${node_log_collection_args:---since=${SINCE_TIMEFRAME:--7d}}" "${selector}" -u "${service}" | gzip >"${DIR_PATH}/${service}_service${LOG_SUFFIX}" &
+ fi
PIDS+=($!)
fi
done🤖 Prompt for AI Agents
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '== gather_service_logs_util outline =='
ast-grep outline collection-scripts/gather_service_logs_util --items all || true
printf '%s\n' '== collect_service_logs call sites and PID waits =='
rg -n -C 4 '\bcollect_service_logs\s*\(|\bwait\b|\bPIDS\b|set\s+(-o\s+pipefail|-[A-Za-z]*o?[A-Za-z]*\b)' \
-g '*.sh' -g '*.bats' .
printf '%s\n' '== pipefail declarations =='
rg -n -C 3 'pipefail' -g '*.sh' -g '*.bats' .Length of output: 5638 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '== Files related to the service-log utility =='
fd -HI -t f . | rg '(^|/)(gather_service_logs_util|gather_service_logs|common)(\.[^/]+)?$|service_logs'
printf '%s\n' '== Source/call sites, PID initialization, and waits (all text files) =='
rg -n -i -C 5 \
'source[[:space:]].*gather_service_logs_util|(^|[[:space:];])\.[[:space:]].*gather_service_logs_util|\bcollect_service_logs[[:space:]]|(^|[^[:alnum:]_])PIDS=\(|\bwait[[:space:]].*PIDS|set[[:space:]]+(-[[:alpha:]]*o[[:alpha:]]*|-[[:space:]]*o[[:space:]]+pipefail)' \
--glob '!**/.git/**' .
printf '%s\n' '== Relevant production-script headers =='
for f in $(rg -l -i \
'source[[:space:]].*gather_service_logs_util|(^|[[:space:];])\.[[:space:]].*gather_service_logs_util|\bcollect_service_logs[[:space:]]' \
--glob '!**/.git/**' .); do
echo "--- $f"
sed -n '1,100p' "$f"
doneLength of output: 53367
One important correction: adding only
The robust minimal approach is to enable You are interacting with an AI system. |
||
| PIDS+=($!) | ||
| fi | ||
| done | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ echo INFO: Collecting logs for all Windows nodes | |
| for log in "${LOGS[@]}"; do | ||
| LOG_FILE_DIR=${WINDOWS_NODE_LOGS}/log_files/$(dirname "$log") | ||
| mkdir -p "${LOG_FILE_DIR}" | ||
| /usr/bin/oc adm node-logs ${node_log_collection_args:+"$node_log_collection_args"} -l kubernetes.io/os=windows --path="$log" >"${LOG_FILE_DIR}/$(basename "$log")" & | ||
| /usr/bin/oc adm node-logs ${node_log_collection_args:+"$node_log_collection_args"} -l kubernetes.io/os=windows --path="$log" | gzip >"${LOG_FILE_DIR}/$(basename "$log").gz" & | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we directly use gzip here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the CI requires .log files for host_service_logs, added the flag for service logs only. Do you think this also needs to be flagged? We already have this gzip functionality in gather_kas_startup_termination_logs. Hence, add the gzip here to reduce the log size of windows node logs. |
||
| PIDS+=($!) | ||
| done | ||
| wait "${PIDS[@]}" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,13 +115,57 @@ load test_helper | |
| source \"$SCRIPT_DIR/common.sh\" | ||
| get_log_collection_args | ||
| echo \"rotated_pod_logs_arg=[\$rotated_pod_logs_arg]\" | ||
| echo \"compress_service_logs=[\$compress_service_logs]\" | ||
| " | ||
|
|
||
| assert_success | ||
| assert_output --partial "rotated_pod_logs_arg=[]" | ||
| assert_output --partial "compress_service_logs=[]" | ||
| } | ||
|
|
||
| @test "get_log_collection_args fails when REDUCE_LOGS is comma-separated" { | ||
| @test "get_log_collection_args enables compress_service_logs when REDUCE_LOGS is compress_service_logs" { | ||
| run bash -c " | ||
| export REDUCE_LOGS='compress_service_logs' | ||
| source \"$SCRIPT_DIR/common.sh\" | ||
| get_log_collection_args | ||
| echo \"rotated_pod_logs_arg=\$rotated_pod_logs_arg\" | ||
| echo \"compress_service_logs=\$compress_service_logs\" | ||
| " | ||
|
|
||
| assert_success | ||
| assert_output --partial "rotated_pod_logs_arg=--rotated-pod-logs" | ||
| assert_output --partial "compress_service_logs=true" | ||
| } | ||
|
|
||
| @test "get_log_collection_args accepts both REDUCE_LOGS tokens" { | ||
| run bash -c " | ||
| export REDUCE_LOGS='skip_rotated_logs,compress_service_logs' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. Examples: Skip rotated pod logsoc adm must-gather -- REDUCE_LOGS=skip_rotated_logs /usr/bin/gather Compress host service logsoc adm must-gather -- REDUCE_LOGS=compress_service_logs /usr/bin/gather Bothoc adm must-gather -- REDUCE_LOGS=skip_rotated_logs,compress_service_logs /usr/bin/gather |
||
| source \"$SCRIPT_DIR/common.sh\" | ||
| get_log_collection_args | ||
| echo \"rotated_pod_logs_arg=[\$rotated_pod_logs_arg]\" | ||
| echo \"compress_service_logs=\$compress_service_logs\" | ||
| " | ||
|
|
||
| assert_success | ||
| assert_output --partial "rotated_pod_logs_arg=[]" | ||
| assert_output --partial "compress_service_logs=true" | ||
| } | ||
|
|
||
| @test "get_log_collection_args accepts both REDUCE_LOGS tokens in either order" { | ||
| run bash -c " | ||
| export REDUCE_LOGS='compress_service_logs,skip_rotated_logs' | ||
| source \"$SCRIPT_DIR/common.sh\" | ||
| get_log_collection_args | ||
| echo \"rotated_pod_logs_arg=[\$rotated_pod_logs_arg]\" | ||
| echo \"compress_service_logs=\$compress_service_logs\" | ||
| " | ||
|
|
||
| assert_success | ||
| assert_output --partial "rotated_pod_logs_arg=[]" | ||
| assert_output --partial "compress_service_logs=true" | ||
| } | ||
|
|
||
| @test "get_log_collection_args fails when REDUCE_LOGS contains an unknown token" { | ||
| run bash -c " | ||
| export REDUCE_LOGS='skip_rotated_logs,other' | ||
| source \"$SCRIPT_DIR/common.sh\" | ||
|
|
@@ -130,7 +174,7 @@ load test_helper | |
|
|
||
| assert_failure | ||
| assert_output --partial "ERROR" | ||
| assert_output --partial "skip_rotated_logs,other" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason of this change?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That assertion was narrowed when comma-separated REDUCE_LOGS became valid. Before: REDUCE_LOGS accepted only a single value. The test was essentially “comma-separated fails,” and it checked for the whole string:
After: lists are allowed (skip_rotated_logs,compress_service_logs).
So it checks that the bad token is reported, not that commas are rejected. The error still includes the full got: [...] value; the test just no longer keys off that older “no commas” meaning. |
||
| assert_output --partial "other" | ||
| } | ||
|
|
||
| @test "get_log_collection_args fails when REDUCE_LOGS is unknown" { | ||
|
|
@@ -142,7 +186,9 @@ load test_helper | |
|
|
||
| assert_failure | ||
| assert_output --partial "ERROR" | ||
| assert_output --partial "invalid" | ||
| assert_output --partial "skip_rotated_logs" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason of this change? |
||
| assert_output --partial "compress_service_logs" | ||
| } | ||
|
|
||
| @test "get_log_collection_args formats node_log_collection_args from MUST_GATHER_SINCE" { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,3 +149,52 @@ run_service_logs_test() { | |
| assert_success | ||
| assert_output --partial "INFO: Collecting host service logs for testservice" | ||
| } | ||
|
|
||
| @test "collect_service_logs writes uncompressed .log by default" { | ||
| run_service_logs_test " | ||
| unset REDUCE_LOGS | ||
| source \"$SCRIPT_DIR/common.sh\" | ||
| get_log_collection_args | ||
| collect_service_logs --role=master testservice 2>&1 | ||
| wait \"\${PIDS[@]}\" 2>/dev/null || true | ||
| PIDS=() | ||
| [[ -f \"$TEST_TMPDIR/service_logs/masters/testservice_service.log\" ]] && echo 'uncompressed log present' | ||
| [[ ! -f \"$TEST_TMPDIR/service_logs/masters/testservice_service.log.gz\" ]] && echo 'gzip absent' | ||
|
Comment on lines
+159
to
+162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Make compression tests validate the collection result. Each test suppresses Also applies to: 176-179, 193-195 🤖 Prompt for AI Agents |
||
| " | ||
|
|
||
| assert_success | ||
| assert_output --partial "uncompressed log present" | ||
| assert_output --partial "gzip absent" | ||
| } | ||
|
|
||
| @test "collect_service_logs writes .log.gz when REDUCE_LOGS is compress_service_logs" { | ||
| run_service_logs_test " | ||
| export REDUCE_LOGS='compress_service_logs' | ||
| source \"$SCRIPT_DIR/common.sh\" | ||
| get_log_collection_args | ||
| collect_service_logs --role=master testservice 2>&1 | ||
| wait \"\${PIDS[@]}\" 2>/dev/null || true | ||
| PIDS=() | ||
| [[ -f \"$TEST_TMPDIR/service_logs/masters/testservice_service.log.gz\" ]] && echo 'gzip log present' | ||
| [[ ! -f \"$TEST_TMPDIR/service_logs/masters/testservice_service.log\" ]] && echo 'uncompressed absent' | ||
| " | ||
|
|
||
| assert_success | ||
| assert_output --partial "gzip log present" | ||
| assert_output --partial "uncompressed absent" | ||
| } | ||
|
|
||
| @test "collect_service_logs writes .log.gz when REDUCE_LOGS includes compress_service_logs with skip_rotated_logs" { | ||
| run_service_logs_test " | ||
| export REDUCE_LOGS='skip_rotated_logs,compress_service_logs' | ||
| source \"$SCRIPT_DIR/common.sh\" | ||
| get_log_collection_args | ||
| collect_service_logs --role=master testservice 2>&1 | ||
| wait \"\${PIDS[@]}\" 2>/dev/null || true | ||
| PIDS=() | ||
| [[ -f \"$TEST_TMPDIR/service_logs/masters/testservice_service.log.gz\" ]] && echo 'gzip log present' | ||
| " | ||
|
|
||
| assert_success | ||
| assert_output --partial "gzip log present" | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason of this?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running
make lintgives the warning.Hence added the
shellcheck disable=SC2034line to avoid this warning.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't failing. Why now it started failing?