You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by Felix Schumacher <fe...@internetallee.de> on 2017/07/16 13:13:04 UTC

Checking values of properties more thoroughly

While looking for easy enhancements and bugs I stumbled upon:

https://bz.apache.org/bugzilla/show_bug.cgi?id=56862

I have to admit, that the error messages for wrong values are not always 
that helpful. Especially, when those values are used very late.

To help things, we could either add a validate function (lambda?) to the 
JMeterUtils#getPropDefault family of functions, or surround those calls 
by a validator.

I was thinking of something like

  private static int TIMEOUT = 
JMeterUtils.getPropDefault("some.timeout", 5 * 1000, i -> i >= 0);

  private static int TIMEOUT = 
JMeterUtils.getPropDefault("some.timeout", 5 * 1000, 
Validator::notNegative);

or

  private static int TIMEOUT = 
Validator.notNegative(JMeterUtils.getPropDefault("some.timeout", 5 * 
1000), "some.timeout must not be negative");

At the moment I prefer the first variants.

What do you think?

Felix


Re: Checking values of properties more thoroughly

Posted by Felix Schumacher <fe...@internetallee.de>.
Am 16.07.2017 um 15:44 schrieb Emilian Bold:
> I don't know the codebase well, but I wouldn't add a validator to
> getPropDefault.
>
> The reason being that I expect getPropDefault to already return a
> valid value or *my* default which I also know it's valid.
The getPropDefault looks for values inside text files and tries to find 
one matching the name of the first argument. If it can't find one, it 
gives back the default value (which is the second argument).
>
> So, validation should happen at a layer bellow getPropDefault.
>
> Also, having the validator in there is not very good if you don't have
> a constant. For example, I see in JMeter the call:
>
>> RemoteJMeterEngineImpl.startServer(JMeterUtils.getPropDefault("server_port", 0));
Than this is more an argument against this specific usage of 
getPropDefault, isn't it?
> If you have the same key accessed multiple times with getPropDefault
> they each would have to register a potentially different validator.
>
> A solution would be to validate the whole configuration file at start up.
Where would you register/configure the validators? What happens with 
third party modules, that would want to be checked, too?
>
> In order to have the validators you could use an annotation processor
> to gather some validation annotations from the codebase. Eg.
>
> @PositiveOrZero
> private static int TIMEOUT =
> JMeterUtils.getPropDefault("some.timeout", 5 * 1000);
>
> Where @ PositiveOrZero is something I took from BeanValidation but we
> don't have to use that (
> http://beanvalidation.org/latest-draft/spec/#builtinconstraints-positiveorzero
> ).
Right a annotation would have been my first choice.
But it would basically have the same issues like my proposed first 
version and we don't use annotations in jmeter (that is up to now).

How would you integrate these annotations into our codebase?

Felix
>
>
> --emi
>
>
> On Sun, Jul 16, 2017 at 4:13 PM, Felix Schumacher
> <fe...@internetallee.de> wrote:
>> While looking for easy enhancements and bugs I stumbled upon:
>>
>> https://bz.apache.org/bugzilla/show_bug.cgi?id=56862
>>
>> I have to admit, that the error messages for wrong values are not always
>> that helpful. Especially, when those values are used very late.
>>
>> To help things, we could either add a validate function (lambda?) to the
>> JMeterUtils#getPropDefault family of functions, or surround those calls by a
>> validator.
>>
>> I was thinking of something like
>>
>>   private static int TIMEOUT = JMeterUtils.getPropDefault("some.timeout", 5 *
>> 1000, i -> i >= 0);
>>
>>   private static int TIMEOUT = JMeterUtils.getPropDefault("some.timeout", 5 *
>> 1000, Validator::notNegative);
>>
>> or
>>
>>   private static int TIMEOUT =
>> Validator.notNegative(JMeterUtils.getPropDefault("some.timeout", 5 * 1000),
>> "some.timeout must not be negative");
>>
>> At the moment I prefer the first variants.
>>
>> What do you think?
>>
>> Felix
>>


Re: Checking values of properties more thoroughly

Posted by Emilian Bold <em...@gmail.com>.
> The getPropDefault looks for values inside text files and tries to find one matching the name of the first argument. If it can't find one, it gives back the default value (which is the second argument).

The text file is an implementation detail. The API getPropDefault
should allow me to think the value is validated already.

>> RemoteJMeterEngineImpl.startServer(JMeterUtils.getPropDefault("server_port", 0));
> Than this is more an argument against this specific usage of getPropDefault, isn't it?

Well, yes, it is rare to have non-constants.

> Where would you register/configure the validators?

Via annotations would be the most simple. Some service registration
would work too.

> What happens with third party modules, that would want to be checked, too?

Third party modules that define their own properties should do their
own validation. If they just use official JMeter properties, they
should expect the getPropDefault API call to return valid values.

> How would you integrate these annotations into our codebase?

I think the most "basic" way would be with code generation. Use the
annotations but then generate code with an annotation processor. The
generated code would be used to validate the properties file at
startup.


--emi


On Sun, Jul 16, 2017 at 5:10 PM, Felix Schumacher
<fe...@internetallee.de> wrote:
> Am 16.07.2017 um 15:59 schrieb Vladimir Sitnikov:
>>
>> Emilian>The reason being that I expect getPropDefault to already return a
>> valid value or *my* default which I also know it's valid.
>>
>> +1
>>
>>
>> Emilian>A solution would be to validate the whole configuration file at
>> start up.
>>
>> There always might be "runtime validations", so we can't rely on "validate
>> everything at startup time".
>>
>> JMeter has lots of features and lots of options. Should it warn user if
>> some unused feature is misconfigured?
>>
>> Alternative (additional) option is to define properties via  some
>> class-interface like entities.
>> That is tie validator to the property, and not to the call site.
>
> Something like find all classes with interface PropertyValidatorInitializer
> (or something like that) and run them on startup. These classes could
> register (in a central registry) validators for property names.
>
> Than getPropDefault (or other getProp-variants) could ask the central
> registry to validate the values and even give specific error messages on
> failure.
>
>>
>> Note: "string -> whatever" conversion might need to use original string
>> value in order to make error message clear.
>>
>> Do you think error messages should be localizable?
>
> Might be nice, so I think it would definitely be a plus.
>>
>> Do you think error messages should refer to the relevant documentation
>> sections and/or provide corrective actions?
>
> Would be nice, too.
>
> Felix
>
>>
>> PS. Here's a relevant quote:
>> https://twitter.com/mezzoblue/status/878336246996647938
>>
>> Vladimir
>>
>

Re: Checking values of properties more thoroughly

Posted by Felix Schumacher <fe...@internetallee.de>.
Am 16.07.2017 um 15:59 schrieb Vladimir Sitnikov:
> Emilian>The reason being that I expect getPropDefault to already return a
> valid value or *my* default which I also know it's valid.
>
> +1
>
>
> Emilian>A solution would be to validate the whole configuration file at
> start up.
>
> There always might be "runtime validations", so we can't rely on "validate
> everything at startup time".
>
> JMeter has lots of features and lots of options. Should it warn user if
> some unused feature is misconfigured?
>
> Alternative (additional) option is to define properties via  some
> class-interface like entities.
> That is tie validator to the property, and not to the call site.
Something like find all classes with interface 
PropertyValidatorInitializer (or something like that) and run them on 
startup. These classes could register (in a central registry) validators 
for property names.

Than getPropDefault (or other getProp-variants) could ask the central 
registry to validate the values and even give specific error messages on 
failure.

>
> Note: "string -> whatever" conversion might need to use original string
> value in order to make error message clear.
>
> Do you think error messages should be localizable?
Might be nice, so I think it would definitely be a plus.
> Do you think error messages should refer to the relevant documentation
> sections and/or provide corrective actions?
Would be nice, too.

Felix
>
> PS. Here's a relevant quote:
> https://twitter.com/mezzoblue/status/878336246996647938
>
> Vladimir
>


Re: Checking values of properties more thoroughly

Posted by Vladimir Sitnikov <si...@gmail.com>.
Emilian>The reason being that I expect getPropDefault to already return a
valid value or *my* default which I also know it's valid.

+1


Emilian>A solution would be to validate the whole configuration file at
start up.

There always might be "runtime validations", so we can't rely on "validate
everything at startup time".

JMeter has lots of features and lots of options. Should it warn user if
some unused feature is misconfigured?

Alternative (additional) option is to define properties via  some
class-interface like entities.
That is tie validator to the property, and not to the call site.

Note: "string -> whatever" conversion might need to use original string
value in order to make error message clear.

Do you think error messages should be localizable?
Do you think error messages should refer to the relevant documentation
sections and/or provide corrective actions?

PS. Here's a relevant quote:
https://twitter.com/mezzoblue/status/878336246996647938

Vladimir

Re: Checking values of properties more thoroughly

Posted by Emilian Bold <em...@gmail.com>.
I don't know the codebase well, but I wouldn't add a validator to
getPropDefault.

The reason being that I expect getPropDefault to already return a
valid value or *my* default which I also know it's valid.

So, validation should happen at a layer bellow getPropDefault.

Also, having the validator in there is not very good if you don't have
a constant. For example, I see in JMeter the call:

> RemoteJMeterEngineImpl.startServer(JMeterUtils.getPropDefault("server_port", 0));

If you have the same key accessed multiple times with getPropDefault
they each would have to register a potentially different validator.

A solution would be to validate the whole configuration file at start up.

In order to have the validators you could use an annotation processor
to gather some validation annotations from the codebase. Eg.

@PositiveOrZero
private static int TIMEOUT =
JMeterUtils.getPropDefault("some.timeout", 5 * 1000);

Where @ PositiveOrZero is something I took from BeanValidation but we
don't have to use that (
http://beanvalidation.org/latest-draft/spec/#builtinconstraints-positiveorzero
).


--emi


On Sun, Jul 16, 2017 at 4:13 PM, Felix Schumacher
<fe...@internetallee.de> wrote:
> While looking for easy enhancements and bugs I stumbled upon:
>
> https://bz.apache.org/bugzilla/show_bug.cgi?id=56862
>
> I have to admit, that the error messages for wrong values are not always
> that helpful. Especially, when those values are used very late.
>
> To help things, we could either add a validate function (lambda?) to the
> JMeterUtils#getPropDefault family of functions, or surround those calls by a
> validator.
>
> I was thinking of something like
>
>  private static int TIMEOUT = JMeterUtils.getPropDefault("some.timeout", 5 *
> 1000, i -> i >= 0);
>
>  private static int TIMEOUT = JMeterUtils.getPropDefault("some.timeout", 5 *
> 1000, Validator::notNegative);
>
> or
>
>  private static int TIMEOUT =
> Validator.notNegative(JMeterUtils.getPropDefault("some.timeout", 5 * 1000),
> "some.timeout must not be negative");
>
> At the moment I prefer the first variants.
>
> What do you think?
>
> Felix
>

Re: Checking values of properties more thoroughly

Posted by Philippe Mouawad <ph...@gmail.com>.
Hello,
Looks like a good idea.

First variant looks nicer to me too

Thanks

On Sun, Jul 16, 2017 at 3:13 PM, Felix Schumacher <
felix.schumacher@internetallee.de> wrote:

> While looking for easy enhancements and bugs I stumbled upon:
>
> https://bz.apache.org/bugzilla/show_bug.cgi?id=56862
>
> I have to admit, that the error messages for wrong values are not always
> that helpful. Especially, when those values are used very late.
>
> To help things, we could either add a validate function (lambda?) to the
> JMeterUtils#getPropDefault family of functions, or surround those calls by
> a validator.
>
> I was thinking of something like
>
>  private static int TIMEOUT = JMeterUtils.getPropDefault("some.timeout",
> 5 * 1000, i -> i >= 0);
>
>  private static int TIMEOUT = JMeterUtils.getPropDefault("some.timeout",
> 5 * 1000, Validator::notNegative);
>
> or
>
>  private static int TIMEOUT = Validator.notNegative(JMeterUt
> ils.getPropDefault("some.timeout", 5 * 1000), "some.timeout must not be
> negative");
>
> At the moment I prefer the first variants.
>
> What do you think?
>
> Felix
>
>


-- 
Cordialement.
Philippe Mouawad.