Skip to content

refactor(linux): allow synchronous log bundle uploads before cleanup - #10209

Open
Abigail Liang (abigailliang-aks-sig-node) wants to merge 1 commit into
devfrom
abigailliang/log-collector-sync-upload
Open

Abigail Liang (abigailliang-aks-sig-node) wants to merge 1 commit into
devfrom
abigailliang/log-collector-sync-upload

Conversation

@abigailliang-aks-sig-node

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Allow a caller to consume/upload the node-log bundle synchronously, before the collector's existing EXIT cleanup removes it. This supports test harnesses without rewriting the installed collector or maintaining another copy of its collection logic.

  • Wrap the existing collection body in collectLogs(), using a subshell so its EXIT trap runs before returning to a sourced caller and does not replace the caller's trap or working directory.
  • Extract the existing Host upload invocation into uploadLogBundle. Direct script execution still uses the same Python sender. A trusted caller may source the script using its existing __SOURCED__ guard, override this function, and invoke collectLogs.
  • Pass the published bundle's path as $1. The override must finish consuming/uploading it before returning and return a nonzero status on failure.

Example caller structure:

__SOURCED__=1 . /opt/azure/containers/aks-log-collector.sh
uploadLogBundle() {
    upload_to_test_storage "$1" # Caller-provided synchronous implementation.
}
collectLogs

The protections from #9783 are retained: owner-only publishing and the existing published-bundle/temporary-directory cleanup are unchanged. This adds no CLI upload options, IMDS-configured command execution, persistent-export mode, or additional upload transport. The collection/configuration body is unchanged apart from indentation and the upload-function call; hide whitespace when reviewing.

This is the producer-side hook only. Consumers still need to adopt it, and existing images without these functions are not repaired by this source change. No workload failure or live end-to-end log recovery is claimed.

Validation:

  • Focused ShellSpec suite: 10 examples, 0 failures on Linux Bash 5.2 in an isolated cached container, macOS Bash 5.3, and macOS Bash 3.2.
  • Covers unchanged default Host uploader, default/custom upload failure status, a readable 0600 bundle during custom upload, cleanup before returning, SIGTERM cleanup, failed publication, and caller trap/working-directory preservation.
  • Tests use fixture collection/upload commands and real file publishing, permissions and cleanup; no node logs or Azure endpoints are accessed.
  • Repository make validate-shell and git diff --check passed.
  • No VHD build, deployment, or live E2E run performed.

Which issue(s) this PR fixes:

No linked issue. Follow-up integration support for #9783; it does not revert that change.

Expose a sourceable collection entry point and synchronous upload function while retaining the existing Host sender and bundle cleanup. Scope the collection EXIT trap to a subshell so a sourced caller regains control only after cleanup, with upload failure status preserved.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1b5a8171-5163-48fa-810e-1054bb3eada0
@github-actions

Copy link
Copy Markdown
Contributor

Windows Unit Test Results

  3 files   21 suites   1m 22s ⏱️
817 tests 817 ✅ 0 💤 0 ❌
844 runs  844 ✅ 0 💤 0 ❌

Results for commit bb972b4.

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
test 0% ❌
windows 27% ❌
parts_windows Package 1 74% ➖
staging_cse_windows Package 1 72% ➖
debug 0% ❌
provisioningscripts 2% ❌
Summary 40% (2077 / 7284) ❌

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
shellspec spec 31% ❌
Summary 31% (5235 / 16921) ❌

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Package Line Rate Health
github.com/Azure/agentbaker/aks-live-patching/pkg/status 100% ✔
github.com/Azure/agentbaker/apiserver 52% ❌
github.com/Azure/agentbaker/cmd 0% ❌
github.com/Azure/agentbaker/cmd/starter 0% ❌
github.com/Azure/agentbaker/fuzz/api 0% ❌
github.com/Azure/agentbaker/hotfix/render-nodecustomdata 35% ❌
github.com/Azure/agentbaker/pkg/agent 79% ➖
github.com/Azure/agentbaker/pkg/agent/datamodel 78% ➖
github.com/Azure/agentbaker/pkg/agent/toggles 0% ❌
github.com/Azure/agentbaker/pkg/vhdbuilder/datamodel 87% ✔
github.com/Azure/agentbaker/aks-node-controller 73% ➖
github.com/Azure/agentbaker/aks-node-controller/common 100% ✔
github.com/Azure/agentbaker/aks-node-controller/helpers 68% ➖
github.com/Azure/agentbaker/aks-node-controller/parser 88% ✔
github.com/Azure/agentbaker/aks-node-controller/pkg/gpu 100% ✔
github.com/Azure/agentbaker/aks-node-controller/pkg/nodeconfigutils 91% ✔
github.com/Azure/agentbaker/aks-node-controller/utils 0% ❌
Summary 84% (6297 / 8227) ✔

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The ZIP test fixture can overwrite host archives, while signal-handling, inherited strict-mode options, and cleanup-function conflicts can abort uploads, leave collection running, or prevent cleanup.

4 open issues
What changed in this PR

Adds a synchronous upload hook to AgentBaker’s Linux node-log collector so sourced callers can consume bundles before cleanup without duplicating collection logic.

Changes:

  • Wraps collection in a subshell-based collectLogs() to isolate its working directory and EXIT trap.
  • Extracts an overridable uploadLogBundle() while retaining the default Host uploader.
  • Adds ShellSpec coverage for upload results, bundle permissions, cleanup, interruption, and caller state.
File Description
spec/​parts/​linux/​cloud-init/​artifacts/​aks_log_collector_spec.sh Adds fixture-based tests for synchronous uploads and collection lifecycle behavior.
parts/​linux/​cloud-init/​artifacts/​aks-log-collector.sh Introduces the sourced collection entry point and overridable upload hook.

Review effort: Max

zip)
# Consume only relative fixture FIFOs, never the host's log files.
for arg; do
if [[ "$arg" == *.zip ]]; then
exit 255
}
# Keep EXIT cleanup scoped to collection, including when called after sourcing.
collectLogs() (
exit 255
}
# Keep EXIT cleanup scoped to collection, including when called after sourcing.
collectLogs() (

# Execute the cleanup function if the script terminates
trap "exit 1" HUP INT PIPE QUIT TERM
trap "cleanup" EXIT

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants