Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floats in statsd percentiles #5528

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plugins/inputs/statsd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
## Reset timings & histograms every interval (default=true)
delete_timings = true

## Percentiles to calculate for timing & histogram stats
percentiles = [90]
## Percentiles to calculate for timing & histogram stats.
## These always have to be passed as floating-point numbers.
percentiles = [90.0]

## separator to use between elements of a statsd metric
metric_separator = "_"
Expand Down
12 changes: 6 additions & 6 deletions plugins/inputs/statsd/running_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (rs *RunningStats) Count() int64 {
return rs.n
}

func (rs *RunningStats) Percentile(n int) float64 {
func (rs *RunningStats) Percentile(n float64) float64 {
if n > 100 {
n = 100
}
Expand All @@ -109,16 +109,16 @@ func (rs *RunningStats) Percentile(n int) float64 {
rs.sorted = true
}

i := int(float64(len(rs.perc)) * float64(n) / float64(100))
i := float64(len(rs.perc)) * n / float64(100)
return rs.perc[clamp(i, 0, len(rs.perc)-1)]
}

func clamp(i int, min int, max int) int {
if i < min {
func clamp(i float64, min int, max int) int {
if i < float64(min) {
return min
}
if i > max {
if i > float64(max) {
return max
}
return i
return int(i)
}
4 changes: 2 additions & 2 deletions plugins/inputs/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Statsd struct {

// Percentiles specifies the percentiles that will be calculated for timing
// and histogram stats.
Percentiles []int
Percentiles []float64
PercentileLimit int

DeleteGauges bool
Expand Down Expand Up @@ -206,7 +206,7 @@ const sampleConfig = `
delete_timings = true

## Percentiles to calculate for timing & histogram stats
percentiles = [90]
percentiles = [90.0]

## separator to use between elements of a statsd metric
metric_separator = "_"
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/statsd/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func TestParse_Counters(t *testing.T) {
// Tests low-level functionality of timings
func TestParse_Timings(t *testing.T) {
s := NewTestStatsd()
s.Percentiles = []int{90}
s.Percentiles = []float64{90.0}
acc := &testutil.Accumulator{}

// Test that counters work
Expand Down Expand Up @@ -1156,7 +1156,7 @@ func TestParse_MeasurementsWithMultipleValues(t *testing.T) {
func TestParse_Timings_MultipleFieldsWithTemplate(t *testing.T) {
s := NewTestStatsd()
s.Templates = []string{"measurement.field"}
s.Percentiles = []int{90}
s.Percentiles = []float64{90.0}
acc := &testutil.Accumulator{}

validLines := []string{
Expand Down Expand Up @@ -1207,7 +1207,7 @@ func TestParse_Timings_MultipleFieldsWithTemplate(t *testing.T) {
func TestParse_Timings_MultipleFieldsWithoutTemplate(t *testing.T) {
s := NewTestStatsd()
s.Templates = []string{}
s.Percentiles = []int{90}
s.Percentiles = []float64{90.0}
acc := &testutil.Accumulator{}

validLines := []string{
Expand Down