Skip to content

Commit

Permalink
Upload E2E logs on failure as GHA artifacts (#11514)
Browse files Browse the repository at this point in the history
* Upload E2E journald logs as artifacts in GHA

Signed-off-by: Derek Nola <[email protected]>

* Improve fork information for parent extraction

Signed-off-by: Derek Nola <[email protected]>

---------

Signed-off-by: Derek Nola <[email protected]>
  • Loading branch information
dereknola committed Jan 13, 2025
1 parent 668f7f1 commit 436bce7
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 7 deletions.
20 changes: 19 additions & 1 deletion .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 @@ -155,14 +162,25 @@ jobs:
BRANCH_NAME=$(echo ${{ github.base_ref || github.ref_name }})
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
BRANCH_NAME=${{ github.base_ref }}
fi
echo "Branch Name is $BRANCH_NAME"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT
# branch name should be either master or release-1.XX
- name: Fail if branch name does not match pattern
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
docker-go:
needs: [build, build-go-tests]
name: Docker Tests In GO
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 @@ -395,7 +395,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

0 comments on commit 436bce7

Please sign in to comment.