fixed percentiles not being able to be ints (#9447)
This commit is contained in:
parent
2a72295734
commit
ff8ed37762
|
|
@ -37,6 +37,19 @@ const (
|
||||||
|
|
||||||
var errParsing = errors.New("error parsing statsd line")
|
var errParsing = errors.New("error parsing statsd line")
|
||||||
|
|
||||||
|
// Number will get parsed as an int or float depending on what is passed
|
||||||
|
type Number float64
|
||||||
|
|
||||||
|
func (n *Number) UnmarshalTOML(b []byte) error {
|
||||||
|
value, err := strconv.ParseFloat(string(b), 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
*n = Number(value)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Statsd allows the importing of statsd and dogstatsd data.
|
// Statsd allows the importing of statsd and dogstatsd data.
|
||||||
type Statsd struct {
|
type Statsd struct {
|
||||||
// Protocol used on listener - udp or tcp
|
// Protocol used on listener - udp or tcp
|
||||||
|
|
@ -51,7 +64,7 @@ type Statsd struct {
|
||||||
|
|
||||||
// Percentiles specifies the percentiles that will be calculated for timing
|
// Percentiles specifies the percentiles that will be calculated for timing
|
||||||
// and histogram stats.
|
// and histogram stats.
|
||||||
Percentiles []float64
|
Percentiles []Number
|
||||||
PercentileLimit int
|
PercentileLimit int
|
||||||
|
|
||||||
DeleteGauges bool
|
DeleteGauges bool
|
||||||
|
|
@ -307,7 +320,7 @@ func (s *Statsd) Gather(acc telegraf.Accumulator) error {
|
||||||
fields[prefix+"count"] = stats.Count()
|
fields[prefix+"count"] = stats.Count()
|
||||||
for _, percentile := range s.Percentiles {
|
for _, percentile := range s.Percentiles {
|
||||||
name := fmt.Sprintf("%s%v_percentile", prefix, percentile)
|
name := fmt.Sprintf("%s%v_percentile", prefix, percentile)
|
||||||
fields[name] = stats.Percentile(percentile)
|
fields[name] = stats.Percentile(float64(percentile))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -397,7 +397,7 @@ func TestParse_Counters(t *testing.T) {
|
||||||
// Tests low-level functionality of timings
|
// Tests low-level functionality of timings
|
||||||
func TestParse_Timings(t *testing.T) {
|
func TestParse_Timings(t *testing.T) {
|
||||||
s := NewTestStatsd()
|
s := NewTestStatsd()
|
||||||
s.Percentiles = []float64{90.0}
|
s.Percentiles = []Number{90.0}
|
||||||
acc := &testutil.Accumulator{}
|
acc := &testutil.Accumulator{}
|
||||||
|
|
||||||
// Test that timings work
|
// Test that timings work
|
||||||
|
|
@ -1186,7 +1186,7 @@ func TestParse_MeasurementsWithMultipleValues(t *testing.T) {
|
||||||
func TestParse_TimingsMultipleFieldsWithTemplate(t *testing.T) {
|
func TestParse_TimingsMultipleFieldsWithTemplate(t *testing.T) {
|
||||||
s := NewTestStatsd()
|
s := NewTestStatsd()
|
||||||
s.Templates = []string{"measurement.field"}
|
s.Templates = []string{"measurement.field"}
|
||||||
s.Percentiles = []float64{90.0}
|
s.Percentiles = []Number{90.0}
|
||||||
acc := &testutil.Accumulator{}
|
acc := &testutil.Accumulator{}
|
||||||
|
|
||||||
validLines := []string{
|
validLines := []string{
|
||||||
|
|
@ -1234,7 +1234,7 @@ func TestParse_TimingsMultipleFieldsWithTemplate(t *testing.T) {
|
||||||
func TestParse_TimingsMultipleFieldsWithoutTemplate(t *testing.T) {
|
func TestParse_TimingsMultipleFieldsWithoutTemplate(t *testing.T) {
|
||||||
s := NewTestStatsd()
|
s := NewTestStatsd()
|
||||||
s.Templates = []string{}
|
s.Templates = []string{}
|
||||||
s.Percentiles = []float64{90.0}
|
s.Percentiles = []Number{90.0}
|
||||||
acc := &testutil.Accumulator{}
|
acc := &testutil.Accumulator{}
|
||||||
|
|
||||||
validLines := []string{
|
validLines := []string{
|
||||||
|
|
@ -1664,3 +1664,12 @@ func TestUdp(t *testing.T) {
|
||||||
testutil.IgnoreTime(),
|
testutil.IgnoreTime(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParse_Ints(t *testing.T) {
|
||||||
|
s := NewTestStatsd()
|
||||||
|
s.Percentiles = []Number{90}
|
||||||
|
acc := &testutil.Accumulator{}
|
||||||
|
|
||||||
|
require.NoError(t, s.Gather(acc))
|
||||||
|
require.Equal(t, s.Percentiles, []Number{90.0})
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue