-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*: add json tag to RunnerMetricReport
* Do not show key/value if value is empty * Add BuildPercentileLatencies back into metrics pkg * Render time.Duration into string Signed-off-by: Wei Fu <weifu@microsoft.com>
- Loading branch information
Showing
4 changed files
with
75 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package metrics | ||
|
||
import ( | ||
"math" | ||
"sort" | ||
) | ||
|
||
// BuildPercentileLatencies builds percentile latencies. | ||
func BuildPercentileLatencies(latencies []float64) [][2]float64 { | ||
if len(latencies) == 0 { | ||
return nil | ||
} | ||
|
||
var percentiles = []float64{0, 0.5, 0.90, 0.95, 0.99, 1} | ||
|
||
res := make([][2]float64, len(percentiles)) | ||
|
||
n := len(latencies) | ||
sort.Float64s(latencies) | ||
for pi, pv := range percentiles { | ||
idx := int(math.Ceil(float64(n) * pv)) | ||
if idx > 0 { | ||
idx-- | ||
} | ||
res[pi] = [2]float64{pv, latencies[idx]} | ||
} | ||
return res | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package metrics | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBuildPercentileLatencies(t *testing.T) { | ||
ls := make([]float64, 100) | ||
ls[0] = 50 | ||
ls[1] = 49 | ||
ls[2] = 1 | ||
res := BuildPercentileLatencies(ls) | ||
assert.Equal(t, [2]float64{0, 0}, res[0]) | ||
assert.Equal(t, [2]float64{0.5, 0}, res[1]) | ||
assert.Equal(t, [2]float64{0.9, 0}, res[2]) | ||
assert.Equal(t, [2]float64{0.95, 0}, res[3]) | ||
assert.Equal(t, [2]float64{0.99, 49}, res[4]) | ||
assert.Equal(t, [2]float64{1, 50}, res[5]) | ||
|
||
ls = make([]float64, 1000) | ||
ls[0] = 50 | ||
ls[1] = 49 | ||
ls[2] = -1 | ||
res = BuildPercentileLatencies(ls) | ||
assert.Equal(t, [2]float64{0, -1}, res[0]) | ||
assert.Equal(t, [2]float64{0.5, 0}, res[1]) | ||
assert.Equal(t, [2]float64{0.9, 0}, res[2]) | ||
assert.Equal(t, [2]float64{0.95, 0}, res[3]) | ||
assert.Equal(t, [2]float64{0.99, 0}, res[4]) | ||
assert.Equal(t, [2]float64{1, 50}, res[5]) | ||
} |