Skip to content

Commit c608346

Browse files
committed
PR feedback
1 parent 37f5db4 commit c608346

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

operator/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ cover-html: test-cover
9393
# make test-e2e TEST_PATTERN=Test_GS # Run all gang scheduling tests
9494
# make test-e2e TEST_PATTERN=Test_GS1 # Run specific test
9595
# make test-e2e TEST_PATTERN=Test_TAS # Run all topology tests
96+
#
97+
# Diagnostics: On test failure, diagnostics are written to timestamped .log files.
98+
# The GROVE_E2E_DIAG_DIR env var controls the output directory (default: operator/).
99+
# Set GROVE_E2E_DIAG_TO_STDOUT=1 to print diagnostics to stdout instead.
96100
.PHONY: test-e2e
101+
test-e2e: export GROVE_E2E_DIAG_DIR = $(MODULE_ROOT)
97102
test-e2e:
98103
@echo "> Preparing charts (copying CRDs)..."
99104
@$(MODULE_HACK_DIR)/prepare-charts.sh

operator/e2e/tests/debug_utils.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ const (
4646
// If set to any non-empty value, diagnostics are printed to stdout.
4747
// If not set or empty, diagnostics are written to a timestamped file.
4848
DiagnosticsToStdoutEnvVar = "GROVE_E2E_DIAG_TO_STDOUT"
49+
50+
// DiagnosticsDirEnvVar is the environment variable that specifies the directory
51+
// where diagnostics files should be written. If not set, files are written to
52+
// the current directory. This is ignored if DiagnosticsToStdoutEnvVar is set.
53+
DiagnosticsDirEnvVar = "GROVE_E2E_DIAG_DIR"
4954
)
5055

5156
// isPodReady checks if a pod is ready
@@ -74,8 +79,10 @@ var groveResourceTypes = []groveResourceType{
7479
}
7580

7681
// createDiagnosticsWriter creates an io.Writer for diagnostics output.
77-
// If GROVE_E2E_DIAG_TO_STDOUT is set, returns os.Stdout.
78-
// Otherwise, creates a timestamped file using the test name in the current directory.
82+
// If DiagnosticsToStdoutEnvVar env is set, returns os.Stdout.
83+
// Otherwise, creates a timestamped file using the test name.
84+
// If DiagnosticsToStdoutEnvVar env var is set, the file is created in that directory.
85+
// Otherwise, the file is created in the current directory (with fallback to temp dir).
7986
// The caller is responsible for closing the returned io.Closer (may be nil for stdout).
8087
func createDiagnosticsWriter(testName string) (io.Writer, io.Closer, string, error) {
8188
if os.Getenv(DiagnosticsToStdoutEnvVar) != "" {
@@ -87,28 +94,42 @@ func createDiagnosticsWriter(testName string) (io.Writer, io.Closer, string, err
8794

8895
// Create a timestamped file with test name
8996
timestamp := time.Now().Format("2006-01-02_15-04-05")
90-
filename := fmt.Sprintf("%s_%s.log", sanitizedName, timestamp)
97+
baseFilename := fmt.Sprintf("%s_%s.log", sanitizedName, timestamp)
98+
99+
// Determine the directory for the diagnostics file
100+
diagDir := os.Getenv(DiagnosticsDirEnvVar)
101+
if diagDir != "" {
102+
// Use the specified directory
103+
filename := filepath.Join(diagDir, baseFilename)
104+
file, err := os.Create(filename)
105+
if err != nil {
106+
return nil, nil, "", fmt.Errorf("failed to create diagnostics file in %s: %w", diagDir, err)
107+
}
108+
return file, file, filename, nil
109+
}
91110

92111
// Try to create the file in the current directory
93-
file, err := os.Create(filename)
112+
file, err := os.Create(baseFilename)
94113
if err != nil {
95114
// Fall back to a temp directory if we can't write to current dir
96-
filename = filepath.Join(os.TempDir(), filename)
115+
filename := filepath.Join(os.TempDir(), baseFilename)
97116
file, err = os.Create(filename)
98117
if err != nil {
99118
return nil, nil, "", fmt.Errorf("failed to create diagnostics file: %w", err)
100119
}
120+
return file, file, filename, nil
101121
}
102122

103-
return file, file, filename, nil
123+
return file, file, baseFilename, nil
104124
}
105125

106126
// CollectAllDiagnostics collects and prints all diagnostic information at INFO level.
107127
// This should be called when a test fails, before cleanup runs.
108128
// All output is at INFO level to ensure visibility regardless of log level settings.
109129
//
110130
// Diagnostics are written to a timestamped file using the test name (e.g., TestRollingUpdate_2025-01-22_15-04-05.log).
111-
// Set the DiagnosticsToStdoutEnvVar environment variable to output to stdout instead.
131+
// Set DiagnosticsDirEnvVar env var to specify the output directory for diagnostics files.
132+
// Set DiagnosticsToStdoutEnvVar env var to output to stdout instead of a file.
112133
func CollectAllDiagnostics(tc TestContext) {
113134
// Get test name for the diagnostics file
114135
testName := "unknown_test"

0 commit comments

Comments
 (0)