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

Implement JSON printing for test summaries #19402

Merged
merged 1 commit into from
Jan 8, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (f *Framework) afterEach() {

summaries := make([]TestDataSummary, 0)
if testContext.GatherKubeSystemResourceUsageData {
summaries = append(summaries, f.gatherer.stopAndSummarize([]int{50, 90, 99, 100}, f.addonResourceConstraints))
summaries = append(summaries, f.gatherer.stopAndSummarize([]int{90, 99}, f.addonResourceConstraints))
}

if testContext.GatherLogsSizes {
Expand Down
43 changes: 30 additions & 13 deletions test/e2e/log_size_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,15 @@ type LogsSizeVerifier struct {
workers []*LogSizeGatherer
}

type SingleLogSummary struct {
AverageGenerationRate int
NumberOfProbes int
}

type LogSizeDataTimeseries map[string]map[string][]TimestampedSize

// node -> file -> data
type LogsSizeDataSummary map[string]map[string][]TimestampedSize
type LogsSizeDataSummary map[string]map[string]SingleLogSummary

// TODO: make sure that we don't need locking here
func (s *LogsSizeDataSummary) PrintHumanReadable() string {
Expand All @@ -86,24 +93,19 @@ func (s *LogsSizeDataSummary) PrintHumanReadable() string {
for k, v := range *s {
fmt.Fprintf(w, "%v\t\t\t\n", k)
for path, data := range v {
if len(data) > 1 {
last := data[len(data)-1]
first := data[0]
rate := (last.size - first.size) / int(last.timestamp.Sub(first.timestamp)/time.Second)
fmt.Fprintf(w, "\t%v\t%v\t%v\n", path, rate, len(data))
}
fmt.Fprintf(w, "\t%v\t%v\t%v\n", path, data.AverageGenerationRate, data.NumberOfProbes)
}
}
w.Flush()
return buf.String()
}

func (s *LogsSizeDataSummary) PrintJSON() string {
return "JSON printer not implemented for LogsSizeDataSummary"
return prettyPrintJSON(*s)
}

type LogsSizeData struct {
data LogsSizeDataSummary
data LogSizeDataTimeseries
lock sync.Mutex
}

Expand All @@ -116,7 +118,7 @@ type WorkItem struct {
}

func prepareData(masterAddress string, nodeAddresses []string) LogsSizeData {
data := make(LogsSizeDataSummary)
data := make(LogSizeDataTimeseries)
ips := append(nodeAddresses, masterAddress)
for _, ip := range ips {
data[ip] = make(map[string][]TimestampedSize)
Expand Down Expand Up @@ -170,9 +172,24 @@ func NewLogsVerifier(c *client.Client, stopChannel chan bool) *LogsSizeVerifier
return verifier
}

// PrintData returns a string with formated results
func (v *LogsSizeVerifier) GetSummary() *LogsSizeDataSummary {
return &v.data.data
// GetSummary returns a summary (average generation rate and number of probes) of the data gathered by LogSizeVerifier
func (s *LogsSizeVerifier) GetSummary() *LogsSizeDataSummary {
result := make(LogsSizeDataSummary)
for k, v := range s.data.data {
result[k] = make(map[string]SingleLogSummary)
for path, data := range v {
if len(data) > 1 {
last := data[len(data)-1]
first := data[0]
rate := (last.size - first.size) / int(last.timestamp.Sub(first.timestamp)/time.Second)
result[k][path] = SingleLogSummary{
AverageGenerationRate: rate,
NumberOfProbes: len(data),
}
}
}
}
return &result
}

// Run starts log size gathering. It starts a gorouting for every worker and then blocks until stopChannel is closed
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/metrics_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (m *metricsForE2E) PrintHumanReadable() string {
}

func (m *metricsForE2E) PrintJSON() string {
return "JSON printer not implemented for Metrics"
return prettyPrintJSON(*m)
}

var InterestingApiServerMetrics = []string{
Expand Down Expand Up @@ -402,10 +402,12 @@ func VerifySchedulerLatency(c *client.Client) error {
func prettyPrintJSON(metrics interface{}) string {
output := &bytes.Buffer{}
if err := json.NewEncoder(output).Encode(metrics); err != nil {
Logf("Error building encoder: %v", err)
return ""
}
formatted := &bytes.Buffer{}
if err := json.Indent(formatted, output.Bytes(), "", " "); err != nil {
Logf("Error indenting: %v", err)
return ""
}
return string(formatted.Bytes())
Expand Down
22 changes: 12 additions & 10 deletions test/e2e/resource_usage_gatherer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"math"
"sort"
"strconv"
"strings"
"sync"
"text/tabwriter"
Expand Down Expand Up @@ -48,12 +49,13 @@ type containerResourceGatherer struct {
}

type singleContainerSummary struct {
name string
cpu float64
mem int64
Name string
Cpu float64
Mem int64
}

type ResourceUsageSummary map[int][]singleContainerSummary
// we can't have int here, as JSON does not accept integer keys.
type ResourceUsageSummary map[string][]singleContainerSummary

func (s *ResourceUsageSummary) PrintHumanReadable() string {
buf := &bytes.Buffer{}
Expand All @@ -62,15 +64,15 @@ func (s *ResourceUsageSummary) PrintHumanReadable() string {
buf.WriteString(fmt.Sprintf("%v percentile:\n", perc))
fmt.Fprintf(w, "container\tcpu(cores)\tmemory(MB)\n")
for _, summary := range summaries {
fmt.Fprintf(w, "%q\t%.3f\t%.2f\n", summary.name, summary.cpu, float64(summary.mem)/(1024*1024))
fmt.Fprintf(w, "%q\t%.3f\t%.2f\n", summary.Name, summary.Cpu, float64(summary.Mem)/(1024*1024))
}
w.Flush()
}
return buf.String()
}

func (s *ResourceUsageSummary) PrintJSON() string {
return "JSON printer not implemented for ResourceUsageSummary"
return prettyPrintJSON(*s)
}

func (g *containerResourceGatherer) startGatheringData(c *client.Client, period time.Duration) {
Expand Down Expand Up @@ -115,10 +117,10 @@ func (g *containerResourceGatherer) stopAndSummarize(percentiles []int, constrai
for _, perc := range percentiles {
for _, name := range sortedKeys {
usage := stats[perc][name]
summary[perc] = append(summary[perc], singleContainerSummary{
name: name,
cpu: usage.CPUUsageInCores,
mem: usage.MemoryWorkingSetInBytes,
summary[strconv.Itoa(perc)] = append(summary[strconv.Itoa(perc)], singleContainerSummary{
Name: name,
Cpu: usage.CPUUsageInCores,
Mem: usage.MemoryWorkingSetInBytes,
})
// Verifying 99th percentile of resource usage
if perc == 99 {
Expand Down