-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Make config values more strictly and enable to set nil or default #2685
Conversation
This PR adds a new option My first question is "where should I add the global option"?
I think the command line option is the desired place. The second question is: "The I have some more questions. I'll post it later. |
IMO, 3 would be ideal. 2 would be better.
Looks workable in my environment: diff --git a/lib/fluent/plugin/in_udp.rb b/lib/fluent/plugin/in_udp.rb
index c2d43611..ac3d0bc3 100644
--- a/lib/fluent/plugin/in_udp.rb
+++ b/lib/fluent/plugin/in_udp.rb
@@ -25,7 +25,7 @@ module Fluent::Plugin
desc 'Tag of output events.'
config_param :tag, :string
desc 'The port to listen to.'
- config_param :port, :integer, default: 5160
+ config_param :port, :integer, default: 5160, strict: true
desc 'The bind address to listen to.'
config_param :bind, :string, default: '0.0.0.0' <source>
@type udp
format none
bind 0.0.0.0
port invalid
body_size_limit 4KB
source_host_key "host"
tag test
</source>
<match test>
@type stdout
</match>
And it would be preferable just adding strict checking. |
I've commented the my first impression. |
I think |
684f9d3
to
dfff109
Compare
dfff109
to
7b2e9ec
Compare
e07c550
to
23761f0
Compare
Oops, sorry I missed some comments. |
We should ensure to put only 1 assertion in 1 test because an failed assertion stops to continue the test, remaining assertions in it aren't evaluated. It's not convenient on modifying existing features. Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Add a new config option :strict to Config::INTERGER_VALUE and Config::FLOAT_VALUE. Config.size_value and Config.time_value also support it. Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Example config: <system> strict_config_value true </system> When this option is set to true, ambiguous values for config parameters aren't accepted. For example, an empty string or not a number like "abc" aren't accepted as an integer or a float, an exception will be raised instead. Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Should raise ConfigError on unrecognized strings or any other value types to notify mistakes in user's config as early as possible. Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Example setting: username: "#{ENV['USERNAME'] || raise(SetNil)}" Although many users expect nil for "#{ENV{'FOOBAR']}" with empty FOOBAR environemnt variable, it's converted to an empty string "" since it's Ruby's specification. Instead we are going to add a helper method for it. The helper method will be added in a later commit. Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Example setting: username: "#{ENV['USERNAME'] || raise(SetDefault)}" Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Example settings: username: "#{ENV['USERNAME'] || use_nil}" or username: "#{ENV['USERNAME'] || use_default}" Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
The new argument `strict_config_value` should be added to the last of arguments of the method. Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Default config values should be taken from ConfigProxy::defaults. Otherwise a default value overwritten by config_set_default isn't taken correctly. Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
Signed-off-by: Takuro Ashie <ashie@clear-code.com>
0c4b8a9
to
f13d48b
Compare
Since the first argument inherits Hash class, it's confusing. Signed-off-by: Takuro Ashie <ashie@clear-code.com>
6e187f7
to
3ae212b
Compare
Looks good for me. Does anyone have other concerns? |
Thanks for your review! |
Looks good for me, too. I have no concern for these patches. |
Merged. Thanks! |
Which issue(s) this PR fixes:
Fixes #2616
What this PR does / why we need it:
Add a new command line option
--strict-config-value
to parseinteger
,float
andbool
values in a config file more strictly. A system config itemstrict_config_value
is also added.Since non-numerical (or unrecognized values for
bool
) values for them in config values are implicitly parsed as0
, sometimes it makes troubleshooting hard. This option will raise an error for such values to clarify such issues in a config file.In addition, this PR also adds helper methods to set
nil
or default value to parameters in config files, since many users expectnil
for"#{ENV['SOME_ENV_VAR']}"
with emptySOME_ENV_VAR
environment variable (but it's converted to an empty string in actual).Docs Changes:
--strict-config-value
toCommand Line Options
inDeployment - System Configuration
.strict_config_value
to system config inConfiguration - Config File Syntax
andDeployment - System Configuration
.use_nil
anduse_default
toEmbedding Ruby Expressions
inConfig File Syntax
.Release Note:
Same with the title.