-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
output/cloud/v2: Dedicated Sink implementations
- Loading branch information
Showing
9 changed files
with
126 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,78 @@ | ||
package expv2 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.k6.io/k6/metrics" | ||
) | ||
|
||
func newSink(mt metrics.MetricType) metrics.Sink { | ||
if mt == metrics.Trend { | ||
return &histogram{} | ||
type metricValue interface { | ||
Add(v float64) | ||
} | ||
|
||
func newMetricValue(mt metrics.MetricType) metricValue { | ||
var am metricValue | ||
switch mt { | ||
case metrics.Counter: | ||
am = &counter{} | ||
case metrics.Gauge: | ||
am = &gauge{} | ||
case metrics.Rate: | ||
am = &rate{} | ||
case metrics.Trend: | ||
am = &histogram{} | ||
default: | ||
// Should not be possible to create | ||
// an invalid metric type except for specific | ||
// and controlled tests | ||
panic(fmt.Sprintf("MetricType %q is not supported", mt)) | ||
} | ||
return am | ||
} | ||
|
||
// TODO: add unit tests for the Add methods | ||
|
||
type counter struct { | ||
Sum float64 | ||
} | ||
|
||
func (c *counter) Add(v float64) { | ||
c.Sum += v | ||
} | ||
|
||
type gauge struct { | ||
Last float64 | ||
Sum float64 | ||
Min, Max float64 | ||
Avg float64 | ||
Count uint32 | ||
|
||
minSet bool | ||
} | ||
|
||
func (g *gauge) Add(v float64) { | ||
g.Last = v | ||
g.Count++ | ||
g.Sum += v | ||
g.Avg = g.Sum / float64(g.Count) | ||
|
||
if v > g.Max { | ||
g.Max = v | ||
} | ||
if !g.minSet || v < g.Min { | ||
g.Min = v | ||
g.minSet = true | ||
} | ||
} | ||
|
||
return metrics.NewSink(mt) | ||
type rate struct { | ||
Trues uint32 | ||
Total uint32 | ||
} | ||
|
||
func (r *rate) Add(v float64) { | ||
r.Total++ | ||
if v != 0 { | ||
r.Trues++ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters