Skip to content

Commit

Permalink
test: add output_dir env variable for timestamp exports (#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
njtran authored Jun 20, 2024
1 parent 599c146 commit 1d7877c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
14 changes: 9 additions & 5 deletions test/pkg/debug/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,17 @@ func PrintTestTimes(times map[string][]TimeInterval) map[string][][]string {
}

// WriteTimestamps will create a temp directory and a .csv file for each suite test
func WriteTimestamps(path string, timestamps *TimeIntervalCollector) error {
directory, err := os.MkdirTemp("/tmp", "")
if err != nil {
return err
// If the OUTPUT_DIR environment variable is set, we'll print the csvs to that directory.
func WriteTimestamps(outputDir string, timestamps *TimeIntervalCollector) error {
var err error
if outputDir == "" {
outputDir, err = os.MkdirTemp("/tmp", "")
if err != nil {
return err
}
}
for name, table := range PrintTestTimes(timestamps.suiteTimeIntervals) {
file, err := os.CreateTemp(directory, fmt.Sprintf("*-%s.csv", name))
file, err := os.CreateTemp(outputDir, fmt.Sprintf("*-%s.csv", name))
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions test/pkg/environment/common/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type Environment struct {
KubeClient kubernetes.Interface
Monitor *Monitor

OutputDir string
StartingNodeCount int
}

Expand All @@ -81,6 +82,8 @@ func NewEnvironment(t *testing.T) *Environment {
if val, ok := os.LookupEnv("GIT_REF"); ok {
ctx = context.WithValue(ctx, GitRefContextKey, val)
}
// Get the output dir if it's set
outputDir, _ := os.LookupEnv("OUTPUT_DIR")

gomega.SetDefaultEventuallyTimeout(5 * time.Minute)
gomega.SetDefaultEventuallyPollingInterval(1 * time.Second)
Expand All @@ -92,6 +95,7 @@ func NewEnvironment(t *testing.T) *Environment {
KubeClient: kubernetes.NewForConfigOrDie(config),
Monitor: NewMonitor(ctx, client),
TimeIntervalCollector: debug.NewTimestampCollector(),
OutputDir: outputDir,
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/suites/perf/scheduling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"sigs.k8s.io/karpenter/pkg/test"
)

var replicas int = 100
var replicas int = 10

var _ = Describe("Performance", func() {
Context("Provisioning", func() {
Expand Down
2 changes: 1 addition & 1 deletion test/suites/perf/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestPerf(t *testing.T) {
})
AfterSuite(func() {
// Write out the timestamps from our tests
if err := debug.WriteTimestamps("path", env.TimeIntervalCollector); err != nil {
if err := debug.WriteTimestamps(env.OutputDir, env.TimeIntervalCollector); err != nil {
log.FromContext(env).Info(fmt.Sprintf("Failed to write timestamps to files, %s", err))
}
env.Stop()
Expand Down

0 comments on commit 1d7877c

Please sign in to comment.