From be987ac247b5694ef43a14c65b7845ec1f4d7b59 Mon Sep 17 00:00:00 2001 From: gmarek Date: Wed, 19 Apr 2017 14:53:56 +0200 Subject: [PATCH] Allow summaries to be printed out to ReportDir instead of stdout --- test/e2e/framework/framework.go | 27 ++++++++++++++++--- test/e2e/framework/log_size_monitoring.go | 4 +++ test/e2e/framework/metrics_util.go | 4 +++ test/e2e/framework/resource_usage_gatherer.go | 4 +++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 32ccf5feac..08e8dcf5f6 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -20,6 +20,8 @@ import ( "bytes" "encoding/json" "fmt" + "io/ioutil" + "path" "reflect" "strings" "sync" @@ -89,6 +91,7 @@ type Framework struct { } type TestDataSummary interface { + SummaryKind() string PrintHumanReadable() string PrintJSON() string } @@ -317,17 +320,33 @@ func (f *Framework) AfterEach() { } outputTypes := strings.Split(TestContext.OutputPrintType, ",") + now := time.Now() for _, printType := range outputTypes { switch printType { case "hr": for i := range summaries { - Logf(summaries[i].PrintHumanReadable()) + if TestContext.ReportDir == "" { + Logf(summaries[i].PrintHumanReadable()) + } else { + // TODO: learn to extract test name and append it to the kind instead of timestamp. + filePath := path.Join(TestContext.ReportDir, summaries[i].SummaryKind()+now.Format(time.RFC3339)+".txt") + if err := ioutil.WriteFile(filePath, []byte(summaries[i].PrintHumanReadable()), 0644); err != nil { + Logf("Failed to write file %v with test performance data: %v", filePath, err) + } + } } case "json": for i := range summaries { - typeName := reflect.TypeOf(summaries[i]).String() - Logf("%v JSON\n%v", typeName[strings.LastIndex(typeName, ".")+1:], summaries[i].PrintJSON()) - Logf("Finished") + if TestContext.ReportDir == "" { + Logf("%v JSON\n%v", summaries[i].SummaryKind(), summaries[i].PrintJSON()) + Logf("Finished") + } else { + // TODO: learn to extract test name and append it to the kind instead of timestamp. + filePath := path.Join(TestContext.ReportDir, summaries[i].SummaryKind()+now.Format(time.RFC3339)+".json") + if err := ioutil.WriteFile(filePath, []byte(summaries[i].PrintJSON()), 0644); err != nil { + Logf("Failed to write file %v with test performance data: %v", filePath, err) + } + } } default: Logf("Unknown output type: %v. Skipping.", printType) diff --git a/test/e2e/framework/log_size_monitoring.go b/test/e2e/framework/log_size_monitoring.go index c913cf39ab..c578b8a353 100644 --- a/test/e2e/framework/log_size_monitoring.go +++ b/test/e2e/framework/log_size_monitoring.go @@ -104,6 +104,10 @@ func (s *LogsSizeDataSummary) PrintJSON() string { return PrettyPrintJSON(*s) } +func (s *LogsSizeDataSummary) SummaryKind() string { + return "LogSizeSummary" +} + type LogsSizeData struct { data LogSizeDataTimeseries lock sync.Mutex diff --git a/test/e2e/framework/metrics_util.go b/test/e2e/framework/metrics_util.go index 3dca060f14..3424042f3c 100644 --- a/test/e2e/framework/metrics_util.go +++ b/test/e2e/framework/metrics_util.go @@ -105,6 +105,10 @@ func (m *MetricsForE2E) PrintJSON() string { return PrettyPrintJSON(*m) } +func (m *MetricsForE2E) SummaryKind() string { + return "MetricsForE2E" +} + var InterestingApiServerMetrics = []string{ "apiserver_request_count", "apiserver_request_latencies_summary", diff --git a/test/e2e/framework/resource_usage_gatherer.go b/test/e2e/framework/resource_usage_gatherer.go index efaf69a413..24d2120c03 100644 --- a/test/e2e/framework/resource_usage_gatherer.go +++ b/test/e2e/framework/resource_usage_gatherer.go @@ -70,6 +70,10 @@ func (s *ResourceUsageSummary) PrintJSON() string { return PrettyPrintJSON(*s) } +func (s *ResourceUsageSummary) SummaryKind() string { + return "ResourceUsageSummary" +} + func computePercentiles(timeSeries []ResourceUsagePerContainer, percentilesToCompute []int) map[int]ResourceUsagePerContainer { if len(timeSeries) == 0 { return make(map[int]ResourceUsagePerContainer)