diff --git a/go.mod b/go.mod index 629f6405..4ec1b158 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,16 @@ module github.com/jtaleric/k8s-netperf go 1.18 require ( + github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 github.com/google/uuid v1.1.2 github.com/montanaflynn/stats v0.6.6 + github.com/olekukonko/tablewriter v0.0.5 github.com/opensearch-project/opensearch-go v1.1.0 github.com/openshift/client-go v0.0.0-20221213131518-7aec8d54188a github.com/prometheus/client_golang v1.14.0 github.com/prometheus/common v0.41.0 github.com/sirupsen/logrus v1.9.0 + github.com/spf13/cobra v1.6.1 gopkg.in/yaml.v2 v2.4.0 k8s.io/api v0.26.0 k8s.io/apimachinery v0.26.0 @@ -39,9 +42,7 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/openshift/api v0.0.0-20230111143458-54592eea5539 // indirect - github.com/spf13/cobra v1.6.1 // indirect github.com/spf13/pflag v1.0.5 // indirect golang.org/x/net v0.7.0 // indirect golang.org/x/oauth2 v0.5.0 // indirect diff --git a/go.sum b/go.sum index 5be0f0b7..7eea5170 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 h1:xlwdaKcTNVW4PtpQb8aKA4Pjy0CdJHEqvFbAnvR5m2g= +github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794/go.mod h1:7e+I0LQFUI9AXWxOfsQROs9xPhoJtbsyWcjJqDd4KPY= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/aws/aws-sdk-go v1.42.27/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= diff --git a/pkg/results/result.go b/pkg/results/result.go index 49f777d3..4ca59974 100644 --- a/pkg/results/result.go +++ b/pkg/results/result.go @@ -13,6 +13,7 @@ import ( "github.com/jtaleric/k8s-netperf/pkg/sample" stats "github.com/montanaflynn/stats" "github.com/olekukonko/tablewriter" + math "github.com/aclements/go-moremath/stats" ) // Data describes the result data @@ -62,6 +63,11 @@ func Percentile(vals []float64, ptile float64) (float64, error) { return stats.Percentile(vals, ptile) } +// Confidence accepts array of floats to calculate average +func confidenceInterval(vals []float64, ci float64) (float64, float64, float64) { + return math.MeanCI(vals, ci) +} + // CheckResults will check to see if there are results with a specific Profile like TCP_STREAM // returns true if there are results with provided string func checkResults(s ScenarioResults, check string) bool { @@ -163,12 +169,16 @@ func ShowNodeCPU(s ScenarioResults) { // Abstracts out the common code for results func renderResults(s ScenarioResults, testType string) { - table := initTable([]string{"Result Type", "Driver", "Scenario", "Parallelism", "Host Network", "Service", "Message Size", "Same node", "Duration", "Samples", "Avg value"}) + table := initTable([]string{"Result Type", "Driver", "Scenario", "Parallelism", "Host Network", "Service", "Message Size", "Same node", "Duration", "Samples", "Avg value", "95% Confidence Interval"}) for _, r := range s.Results { if strings.Contains(r.Profile, testType) { if len(r.Driver) > 0 { avg, _ := Average(r.ThroughputSummary) - table.Append([]string{fmt.Sprintf("📊 %s Results", strings.Title(strings.ToLower(testType))), r.Driver, r.Profile, strconv.Itoa(r.Parallelism), strconv.FormatBool(r.HostNetwork), strconv.FormatBool(r.Service), strconv.Itoa(r.MessageSize), strconv.FormatBool(r.SameNode), strconv.Itoa(r.Duration), strconv.Itoa(r.Samples), fmt.Sprintf("%f (%s)", avg, r.Metric)}) + var lo, hi float64 + if r.Samples > 1 { + _, lo, hi = confidenceInterval(r.ThroughputSummary, 0.95) + } + table.Append([]string{fmt.Sprintf("📊 %s Results", strings.Title(strings.ToLower(testType))), r.Driver, r.Profile, strconv.Itoa(r.Parallelism), strconv.FormatBool(r.HostNetwork), strconv.FormatBool(r.Service), strconv.Itoa(r.MessageSize), strconv.FormatBool(r.SameNode), strconv.Itoa(r.Duration), strconv.Itoa(r.Samples), fmt.Sprintf("%f (%s)", avg, r.Metric), fmt.Sprintf("%f-%f (%s)", lo, hi, r.Metric)}) } } } diff --git a/vendor/modules.txt b/vendor/modules.txt index fd79df90..5ff2e8c2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,3 +1,8 @@ +# github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 +## explicit; go 1.12 +github.com/aclements/go-moremath/mathx +github.com/aclements/go-moremath/stats +github.com/aclements/go-moremath/vec # github.com/davecgh/go-spew v1.1.1 ## explicit github.com/davecgh/go-spew/spew