-
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.
Prometheus client doesn't allow us to export observed data. kperf needs to support export raw data for aggregated result. In order to avoid append, this patch uses container/list to maintain latencies. Signed-off-by: Wei Fu <weifu@microsoft.com>
- Loading branch information
Showing
7 changed files
with
100 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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, float64(0), res[0]) | ||
assert.Equal(t, float64(0), res[50]) | ||
assert.Equal(t, float64(0), res[90]) | ||
assert.Equal(t, float64(0), res[95]) | ||
assert.Equal(t, float64(49), res[99]) | ||
assert.Equal(t, float64(50), res[100]) | ||
|
||
ls = make([]float64, 1000) | ||
ls[0] = 50 | ||
ls[1] = 49 | ||
ls[2] = -1 | ||
res = buildPercentileLatencies(ls) | ||
assert.Equal(t, float64(-1), res[0]) | ||
assert.Equal(t, float64(0), res[50]) | ||
assert.Equal(t, float64(0), res[90]) | ||
assert.Equal(t, float64(0), res[95]) | ||
assert.Equal(t, float64(0), res[99]) | ||
assert.Equal(t, float64(50), res[100]) | ||
} | ||
|
||
func TestResponseMetric(t *testing.T) { | ||
c := NewResponseMetric() | ||
for i := 100; i > 0; i-- { | ||
c.ObserveLatency(float64(i)) | ||
} | ||
|
||
_, res, _ := c.Gather() | ||
assert.Equal(t, float64(1), res[0]) | ||
assert.Equal(t, float64(50), res[50]) | ||
assert.Equal(t, float64(90), res[90]) | ||
assert.Equal(t, float64(95), res[95]) | ||
assert.Equal(t, float64(99), res[99]) | ||
assert.Equal(t, float64(100), res[100]) | ||
} |
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