Skip to content

Commit d28cd4a

Browse files
author
Joe Talerico
committed
Add confidence metric to csv and json
Adding the confidence metric to the csv and json output. closes #108 Signed-off-by: Joe Talerico <rook@redhat.com>
1 parent 017b0dd commit d28cd4a

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

pkg/archive/archive.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Doc struct {
4444
ClientPodCPU []metrics.PodCPU `json:"clientPods"`
4545
ClientNodeLabels map[string]string `json:"clientNodeLabels"`
4646
ServerNodeLabels map[string]string `json:"serverNodeLabels"`
47+
Confidence []float64 `json:"confidence"`
4748
}
4849

4950
// Connect returns a client connected to the desired cluster.
@@ -80,6 +81,11 @@ func BuildDocs(sr result.ScenarioResults, uuid string) ([]interface{}, error) {
8081
if len(r.Driver) < 1 {
8182
continue
8283
}
84+
var lo, hi float64
85+
if r.Samples > 1 {
86+
_, lo, hi = result.ConfidenceInterval(r.ThroughputSummary, 0.95)
87+
}
88+
c := []float64{lo, hi}
8389
d := Doc{
8490
UUID: uuid,
8591
Timestamp: time,
@@ -101,6 +107,7 @@ func BuildDocs(sr result.ScenarioResults, uuid string) ([]interface{}, error) {
101107
ServerNodeLabels: r.ServerNodeLabels,
102108
ClientNodeLabels: r.ClientNodeLabels,
103109
AcrossAZ: r.AcrossAZ,
110+
Confidence: c,
104111
}
105112
UDPLossPercent, e := result.Average(r.LossSummary)
106113
if e != nil {
@@ -147,11 +154,17 @@ func commonCsvHeaderFields() []string {
147154
"Parallelism",
148155
"# of Samples",
149156
"Message Size",
157+
"Confidence metric - low",
158+
"Confidence metric - high",
150159
}
151160
}
152161

153162
// Common csv data fields.
154-
func commonCsvDataFeilds(row result.Data) []string {
163+
func commonCsvDataFields(row result.Data) []string {
164+
var lo, hi float64
165+
if row.Samples > 1 {
166+
_, lo, hi = result.ConfidenceInterval(row.ThroughputSummary, 0.95)
167+
}
155168
return []string{
156169
fmt.Sprint(row.Driver),
157170
fmt.Sprint(row.Profile),
@@ -162,15 +175,17 @@ func commonCsvDataFeilds(row result.Data) []string {
162175
strconv.Itoa(row.Parallelism),
163176
strconv.Itoa(row.Samples),
164177
strconv.Itoa(row.MessageSize),
178+
strconv.FormatFloat(lo, 'f', -1, 64),
179+
strconv.FormatFloat(hi, 'f', -1, 64),
165180
}
166181
}
167182

168-
// Writes all the mertic feilds to the archive.
183+
// Writes all the mertics to the archive.
169184
func writeArchive(cpuarchive, podarchive *csv.Writer, role string, row result.Data, podResults []metrics.PodCPU) error {
170185
roleFieldData := []string{role}
171186
for _, pod := range podResults {
172187
if err := podarchive.Write(append(append(roleFieldData,
173-
commonCsvDataFeilds(row)...),
188+
commonCsvDataFields(row)...),
174189
pod.Name,
175190
fmt.Sprintf("%f", pod.Value),
176191
)); err != nil {
@@ -183,7 +198,7 @@ func writeArchive(cpuarchive, podarchive *csv.Writer, role string, row result.Da
183198
cpu = row.ServerMetrics
184199
}
185200
if err := cpuarchive.Write(append(append(roleFieldData,
186-
commonCsvDataFeilds(row)...),
201+
commonCsvDataFields(row)...),
187202
fmt.Sprintf("%f", cpu.Idle),
188203
fmt.Sprintf("%f", cpu.User),
189204
fmt.Sprintf("%f", cpu.System),
@@ -265,7 +280,7 @@ func WriteSpecificCSV(r result.ScenarioResults) error {
265280
if strings.Contains(row.Profile, "UDP_STREAM") {
266281
loss, _ := result.Average(row.LossSummary)
267282
header := []string{"UDP Percent Loss"}
268-
data := append(header, commonCsvDataFeilds(row)...)
283+
data := append(header, commonCsvDataFields(row)...)
269284
iperfdata = append(data, fmt.Sprintf("%f", loss))
270285
if err := archive.Write(iperfdata); err != nil {
271286
return fmt.Errorf("failed to write result archive to file")
@@ -274,7 +289,7 @@ func WriteSpecificCSV(r result.ScenarioResults) error {
274289
if strings.Contains(row.Profile, "TCP_STREAM") {
275290
rt, _ := result.Average(row.RetransmitSummary)
276291
header := []string{"TCP Retransmissions"}
277-
data := append(header, commonCsvDataFeilds(row)...)
292+
data := append(header, commonCsvDataFields(row)...)
278293
iperfdata = append(data, fmt.Sprintf("%f", rt))
279294
if err := archive.Write(iperfdata); err != nil {
280295
return fmt.Errorf("failed to write result archive to file")
@@ -322,7 +337,7 @@ func WriteCSVResult(r result.ScenarioResults) error {
322337
for _, row := range r.Results {
323338
avg, _ := result.Average(row.ThroughputSummary)
324339
lavg, _ := result.Average(row.LatencySummary)
325-
data := append(commonCsvDataFeilds(row),
340+
data := append(commonCsvDataFields(row),
326341
fmt.Sprintf("%f", avg),
327342
row.Metric,
328343
fmt.Sprint(lavg),

pkg/results/result.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func Percentile(vals []float64, ptile float64) (float64, error) {
7474
}
7575

7676
// Confidence accepts array of floats to calculate average
77-
func confidenceInterval(vals []float64, ci float64) (float64, float64, float64) {
77+
func ConfidenceInterval(vals []float64, ci float64) (float64, float64, float64) {
7878
return math.MeanCI(vals, ci)
7979
}
8080

@@ -250,7 +250,7 @@ func renderResults(s ScenarioResults, testType string) {
250250
avg, _ := Average(r.ThroughputSummary)
251251
var lo, hi float64
252252
if r.Samples > 1 {
253-
_, lo, hi = confidenceInterval(r.ThroughputSummary, 0.95)
253+
_, lo, hi = ConfidenceInterval(r.ThroughputSummary, 0.95)
254254
}
255255
table.Append([]string{fmt.Sprintf("📊 %s Results", caser.String(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)})
256256
}

0 commit comments

Comments
 (0)