-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
fixed percentiles not being able to be ints #9447
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work, overall it looks good but can you add another unit test that reads from a toml config with a int instead of a float to verify this change works? Something like this:
func TestConfig(t *testing.T) {
// Load a sample toml config
c := config.NewConfig()
require.NoError(t, c.LoadConfig("./testdata/statsd_int.toml"))
// Create a statsd input plugin struct and load it with expected values
s := inputs.Inputs["statsd"]().(*Statsd)
s.Percentiles = 90.0
require.Equal(t, s, c.Inputs[0].Input)
}
Hey @MyaLongmire, thanks for looking into this. IMO the problem here is an issue in the TOML parser as |
I added a test that ensures ints can be added in the config, although I changed your idea so I wouldn't have to add a test data folder |
How would we know that 90 is supposed to be a float while parsing it? I feel like putting it in config copies how it used to be in internal. |
case reflect.Float32, reflect.Float64:
f := float64(i)
if fv.OverflowFloat(f) {
return &errorOutOfRange{fv.Kind(), f}
}
fv.SetFloat(f)
Right, and you can do this as it restores the functionality. However, it is a workaround and the problem occurs for any |
@srebhan @MyaLongmire I don't think we want to make this change apply to all float64 fields in the config. TOML's design intentionally has a separate float and int type so making a toml int field initialize a telegraf float setting feels wrong. I think this change should be a very isolated workaround only for the statsd plugin. Statsd is special only for backward compatibility. I'd prefer not to put Number in config/types.go because I don't want other plugins to do this in the future. What do you think about moving Number from config/ into plugins/inputs/statsd/ and putting in a comment saying it is for backward compatibility and asking people not to do the same thing elsewhere? |
@reimda: Fine with me, I just wanted to avoid spreading of In general I think using a TOML int as float is a valid use-case. Maybe the parser could have a |
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect. Thanks @MyaLongmire for fixing this one!
(cherry picked from commit ff8ed37)
Required for all PRs:
resolves #9441
added a Number struct and an unmarshal that will allow for ints or floats