Skip to content
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

Upload E2E logs on failure as GHA artifacts #11514

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ jobs:
chmod +x ./dist/artifacts/k3s
cd tests/e2e/${{ matrix.etest }}
go test -v -timeout=45m ./${{ matrix.etest}}_test.go -ci -local
- name: On Failure, Upload Journald Logs
uses: actions/upload-artifact@v4
if: ${{ failure() }}
with:
name: ${{ matrix.etest}}-journald-logs
path: tests/e2e/${{ matrix.etest }}/*-jlog.txt
retention-days: 30
- name: On Failure, Launch Debug Session
uses: lhotari/action-upterm@v1
if: ${{ failure() }}
Expand Down Expand Up @@ -159,6 +166,9 @@ jobs:
fi
elif [ -z "${{ github.base_ref }}" ]; then
# We are in a fork, and need some git history to determine the branch name
# For some reason, the first fetch doesn't always get the full history, so we sleep and fetch again
git fetch origin --depth=100 +refs/heads/*:refs/remotes/origin/*
sleep 5
git fetch origin --depth=100 +refs/heads/*:refs/remotes/origin/*
BRANCH_NAME=$(git show-branch -a 2> /dev/null | grep '\*' | grep -v `git rev-parse --abbrev-ref HEAD` | head -n1 | sed 's/.*\[\(.*\/\)\(.*\)\].*/\2/' | sed 's/[\^~].*//')
else
Expand All @@ -171,6 +181,7 @@ jobs:
run: |
if [[ ! ${{ steps.branch_step.outputs.branch_name }} =~ ^(master|release-[0-9]+\.[0-9]+)$ ]]; then
echo "Branch name ${{ steps.branch_step.outputs.branch_name }} does not match pattern"
echo "If this is a PR/fork, ensure you have recently rebased off master/release-1.XX branch"
exit 1
fi

Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/btrfs/btrfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ var _ = AfterEach(func() {
})

var _ = AfterSuite(func() {
if failed {
Expect(e2e.SaveJournalLogs(serverNodeNames)).To(Succeed())
}
if !failed || *ci {
Expect(e2e.DestroyCluster()).To(Succeed())
Expect(os.Remove(kubeConfigFile)).To(Succeed())
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/embeddedmirror/embeddedmirror_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var _ = AfterEach(func() {

var _ = AfterSuite(func() {
if failed {
AddReportEntry("journald-logs", e2e.TailJournalLogs(1000, append(serverNodeNames, agentNodeNames...)))
Expect(e2e.SaveJournalLogs(append(serverNodeNames, agentNodeNames...))).To(Succeed())
} else {
Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed())
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/externalip/externalip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ var _ = AfterEach(func() {

var _ = AfterSuite(func() {
if failed {
AddReportEntry("journald-logs", e2e.TailJournalLogs(1000, append(serverNodeNames, agentNodeNames...)))
Expect(e2e.SaveJournalLogs(append(serverNodeNames, agentNodeNames...))).To(Succeed())
} else {
Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed())
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/privateregistry/privateregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ var _ = AfterEach(func() {

var _ = AfterSuite(func() {
if failed {
AddReportEntry("journald-logs", e2e.TailJournalLogs(1000, append(serverNodeNames, agentNodeNames...)))
Expect(e2e.SaveJournalLogs(append(serverNodeNames, agentNodeNames...))).To(Succeed())
} else {
Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed())
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ var _ = AfterEach(func() {

var _ = AfterSuite(func() {
if failed {
AddReportEntry("journald-logs", e2e.TailJournalLogs(1000, append(serverNodeNames, agentNodeNames...)))
Expect(e2e.SaveJournalLogs(append(serverNodeNames, agentNodeNames...))).To(Succeed())
} else {
Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed())
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/startup/startup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ var _ = AfterEach(func() {
var _ = AfterSuite(func() {
if failed {
AddReportEntry("config", e2e.GetConfig(append(serverNodeNames, agentNodeNames...)))
AddReportEntry("journald-logs", e2e.TailJournalLogs(1000, append(serverNodeNames, agentNodeNames...)))
Expect(e2e.SaveJournalLogs(append(serverNodeNames, agentNodeNames...))).To(Succeed())
} else {
Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed())
}
Expand Down
20 changes: 20 additions & 0 deletions tests/e2e/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,26 @@ func TailJournalLogs(lines int, nodes []string) string {
return logs.String()
}

// SaveJournalLogs saves the journal logs of each node to a <NAME>-jlog.txt file.
// When used in GHA CI, the logs are uploaded as an artifact on failure.
func SaveJournalLogs(nodeNames []string) error {
for _, node := range nodeNames {
lf, err := os.Create(node + "-jlog.txt")
if err != nil {
return err
}
defer lf.Close()
logs, err := GetJournalLogs(node)
if err != nil {
return err
}
if _, err := lf.Write([]byte(logs)); err != nil {
return fmt.Errorf("failed to write %s node logs: %v", node, err)
}
}
return nil
}

func GetConfig(nodes []string) string {
config := &strings.Builder{}
for _, node := range nodes {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/wasm/wasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ var _ = AfterEach(func() {

var _ = AfterSuite(func() {
if failed {
AddReportEntry("journald-logs", e2e.TailJournalLogs(1000, append(serverNodeNames, agentNodeNames...)))
Expect(e2e.SaveJournalLogs(append(serverNodeNames, agentNodeNames...))).To(Succeed())
} else {
Expect(e2e.GetCoverageReport(append(serverNodeNames, agentNodeNames...))).To(Succeed())
}
Expand Down
Loading