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

Use uniform accessors #752

Merged
merged 18 commits into from May 3, 2021
Merged

Conversation

mattias-p
Copy link
Member

Context

This PR is a follow-up to #749.

Scope

Included:

  • Cleaning up after Uniform config property getter methods #749.
  • Documentation is added for the new getters from Uniform config property getter methods #749.
  • Documentation for the database connection related properties is updated for consistency.
  • Relevant pieces of cleaned up documentation is integrated into the backend config format specification.
  • SQL-queries adjacent to uses of the new property getters are refactored to use the ?-syntax instead of string concatenation. To facilitate a few other refactorings are also included.

Excluded:

  • Functional changes.

Changes

Security:

  • In a couple of places another layer of security is added by using SQL-injection resistant ? syntax. This also makes the code easier to review with regard to security.

Documentation:

  • The backend config format specification gets a tiny improvement by adopting a wording from the getter POD.
  • The POD for the uniform getters is made very light for easier maintenance and higher reliability by not duplicating information provided in the format specification. The idea is to make the format specification a single source of truth. Implementation details are still kept in the getter POD, e.g. the form in which the property values are returned.

Clean-up:

How to test this PR

This PR contains no functional changes. It should be enough that the automatic tests pass.

@mattias-p mattias-p marked this pull request as ready for review April 27, 2021 10:04
@mattias-p mattias-p requested review from matsduf and a user April 27, 2021 10:04
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great ! Thanks
I have few remarks and questions to make it even greater ;)

Comment on lines 295 to 296
How old (in seconds) a previous test of the same zone name and parameters can be
when it is reused instead of starting a new test.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if can conveys the right meaning. From my understanding if the time limit is reached, then a new test is run, otherwise the old test's results are displayed. And the usage of can here make it sounds like there is a possibility to run the test even if the time limit is not reached.

I understand that there might be something unclear with the current sentence.
If you feel we need to rewrite this sentence, I tried to formulate it another way (but I'm still not satisfied)
-> Time (in seconds) to wait before running a new test instead of reusing the results of a previous test of the same zone name and parameter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried to look for a real life analogy to what we're trying to express and the closes I came was "shelf life". I'll come up with a new wording based on that.


'max_zonemaster_execution_time' from [ZONEMASTER] section in ini file. See
L<https://github.com/zonemaster/zonemaster-backend/blob/master/docs/Configuration.md#max_zonemaster_execution_time>.
=head2 DB_engine
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move all these POD (DB_engine ... ZONEMASTER_age_reuse_previous_test) above line 266 with the other ones ? I think it will make more sense to have them all together (however I should say that I don't know much on POD, so if there is a reason to keep them here, I can live with that :) )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POD doesn't care about order. There are coverage tools for verifying that every named subroutine has a corresponding POD heading but otherwise you may do as you please.

For this PR I've mainly tried to do something at least half-way reasonable regarding the placement of the POD while also keeping down the size of the diff. But I'll take another look.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just to have the POD close to the code (if you prefer reading the code file directly). Thanks for the update

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely agree. The only reason I didn't make it so in the first place was a practical one. I had a large set of changes that I was trying to rebase into a series of PRs, so having smaller diffs made a big difference at the time. But I'm glad I got to set it straight.


'number_of_processes_for_frontend_testing' from [ZONEMASTER] section in ini file. See
L<https://github.com/zonemaster/zonemaster-backend/blob/master/docs/Configuration.md#number_of_processes_for_frontend_testing>.
Returns an integer (number of seconds).
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why specifying what kind of value is returned here and not for all the other one ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove it for consistency.

AND progress > 0
AND progress < 100
AND queue = ".$self->config->lock_on_queue();
AND queue = ?" );
$sth->execute( #
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the trailing empty comment mandatory ?
(this question applies to all following execute() calls)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it there to coax perltidy into doing something reasonable. If I leave it out perltidy just pulls all the arguments up on the same line making it harder to read :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for the explanation. And I do agree that it is better to have them on several lines.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a trick! I will remember that.

lib/Zonemaster/Backend/DB/SQLite.pm Outdated Show resolved Hide resolved
@mattias-p
Copy link
Member Author

This looks great ! Thanks
I have few remarks and questions to make it even greater ;)

Of course! Great is great but greater is greater :)

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the updates. Sadly a small mistake slipped in ^^'

Comment on lines 297 to 306
Default value: `600`.

The shelf life of a test in seconds after its creation.
If a new test is requested for the same zone name and parameters within the
shelf life of a previous test result, that test result is reused.
Otherwise a new test request is enqueued.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you removed the default value line by mistake.
(I like the rewording btw)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spotting! I added it back.
I also also made a small edit to make age_reuse_previous_test to make its formatting more like the other simple properties.

(I like the rewording btw)

I'm glad to hear that :)

@mattias-p
Copy link
Member Author

@pnax Thanks for reviewing.

@matsduf Could you review this too?

@ghost ghost mentioned this pull request Apr 29, 2021
@ghost ghost self-requested a review April 29, 2021 14:51

=head2 DB_engine

Get the value of L<DB.engine|https://github.com/zonemaster/zonemaster-backend/blob/master/docs/Configuration.md#polling_interval>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not be "polling_interval" here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I fixed it.

AND progress > 0
AND progress < 100
AND queue = ".$self->config->lock_on_queue();
AND queue = ?" );
$sth->execute( #
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a trick! I will remember that.

@matsduf
Copy link
Contributor

matsduf commented Apr 29, 2021

Just one small change.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While going through the code, I realize that the way some deprecated values are handled is not right. I am referring to number_of_processes_for_frontend_testing and number_of_processes_for_batch_testing. The code on line 183 and 192 of Config.pm will never be used because we set a default value to 20. So the value is always defined at this stage and will never be overridden by the config value.

If we care about stability for deprecated values, I think this needs to be reworked.

And to see the problem, you can update t/config.t with number_of_professes_for_frontend_testing instead of number_of_processes_for_frontend_testing and see the test fail.

@mattias-p
Copy link
Member Author

Thanks for your reviews!

I must say I didn't see the default value problem coming. Getting the order right in this kind of code is surprisingly tricky. Unfortunately I can't fix it the way I want to without conflicting with #753, and I'd rather merge that one first.

After #753 is merged I'll rebase this one and fix the problems you guys found. I'll also add the unit tests I for number_of_processes_for_{frontend,batch}_testing that I forgot to add earlier.

@ghost
Copy link

ghost commented Apr 29, 2021

Yes I agree that this looks tricky. I discovered this while trying to look how to properly deprecate the number_of_processes_for_* keys. And I said to myself, well let's see if @mattias-p can come up with a solution ;-p

@mattias-p
Copy link
Member Author

mattias-p commented Apr 30, 2021

Yeah, having test coverage of all the cases is key, though. Once you get the tests to pass you also want to make it look easy. It's so much more satisfying when the tricky stuff shows up in more glamorous places. Configuration file validation just doesn't get enough hype these days.

But I rebased the commits and fixed the problems. I ended up assigning the private fields multiple times going from least to most prioritized source instead of going the other way around and using guards. I think it turned out pretty good. I just hope I didn't forget more tests.

Copy link
Contributor

@matsduf matsduf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a large and complex PR. It looks fine, but will have to test it thoroughly.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done ! You came up with a very nice solution :)

@mattias-p mattias-p merged commit 163cc68 into zonemaster:develop May 3, 2021
@mattias-p mattias-p deleted the use-uniform-accessors branch May 12, 2021 16:28
@matsduf matsduf added this to the v2021.1 milestone Sep 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants