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

improve ordering of options #224

Merged
merged 2 commits into from
Mar 10, 2016
Merged

improve ordering of options #224

merged 2 commits into from
Mar 10, 2016

Conversation

vicinus
Copy link

@vicinus vicinus commented Feb 20, 2016

I'm aware that the ordering of options is relevant for haproxy and there are cases were you have to configure the ordering via an array. But I'm lazy and I want the module to do as much work by itself as is possible and custom sorting will remove a lot of warnings automatically.

I think the change will not break existing haproxy setups because the options are already sorted and the change only reorders the options like haproxy internally does in https://github.com/haproxy/haproxy/blob/master/src/cfgparse.c. But I'm no expert so I can be mistaken.

I'm willing to improve the change like make it optional per haproxy instance, add tests or any other improvement necessary.

@antaflos
Copy link

This looks interesting and useful IMO! But can you maybe add a comment or two explaining the sort code block for those of us not that well versed in Ruby?

I think the existing tests should pretty much cover this, but there should be probably a parameter added to the haproxy class to enable and disable this more advanced sorting, and it should default to disabled for now, lest it disrupt any running HAProxy setups when upgrading this module.

And I think the server "option" should also be considered when sorting, and always put last. This is useful for cases where haproxy::balancermember is not used but the backend servers are specified directly as options to the haproxy::backend type, as in:

haproxy::backend { 'bk_example_app':
  options => {
    'acl'          => 'allowed_networks src 10.1.0.0/16',
    'http-request' => 'deny unless allowed_networks',
    'server'       => [
      'app01 app01.backend.example.com:8080 check', 
      'app02 app02.backend.example.com:8080 check',
    ]
  }
}

@vicinus
Copy link
Author

vicinus commented Feb 20, 2016

As I have often trouble finding the right amount of explanation here my first try explaining how the sorting is working:

<%# ruby sorts arrays like strings: the first elements are compared, if they -%>
<%# are equal the next elements are compared and so on. The following sort -%>
<%# provides a two element array, the first element a classification of the -%>
<%# option with a default value of 0 if the option is not found in the -%>
<%# option_order hash and the second element the option itself. -%>

I would add the explanation before the first sort.

I have trouble coming up with a name for the option to enable the "new sorting". At the moment I'm going with sort_options_alphabetic. The default would be true and not use the "new sorting". If someone has a better/shorter idea I'm all ears.

@vicinus
Copy link
Author

vicinus commented Feb 25, 2016

I added, that the option server is sorted to the end if present. I also added a short documentation how the custom sorting works. Add last and most extensive I added the parameter sort_options_alphabetic to enable the new sorting and updated the documentation regarding the new parameter.

@hunner
Copy link

hunner commented Mar 3, 2016

I think this looks good! Could you provide an acceptance test similar to one of the existing ones, but pass sort_options_alphabetic => false to make sure that it works? And a unit test that passes that as well to verify that it compiles.

@vicinus vicinus force-pushed the master branch 3 times, most recently from 01b572d to 558955b Compare March 4, 2016 22:09
@vicinus
Copy link
Author

vicinus commented Mar 6, 2016

I have added a unit test and an acceptance test.

I'm not very happy how the option to enable sort_options_alphabetic globally is coded, but the problem is, that it is possible to only use haproxy::instance without using the class haproxy. So the only class used then is haproxy::params. Another option would be to add another class. I can change the code accordingly if that's preferred.

@@ -4,7 +4,9 @@
# currently, only the Redhat family is supported, but this can be easily
# extended by changing package names and configuration file paths.
#
class haproxy::params {
class haproxy::params (
$sort_options_alphabetic = true,
Copy link

Choose a reason for hiding this comment

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

You're talking about putting the parameter here to globally modify it? Yeah, passing parameters to *::params is not a pattern we use. If we HAVE to have global parameters that apply to all defines, we try to put it in the base class. If that doesn't work for some reason, then we use a *::globals class (iirc, postgresql and mongodb do this).

But yeah, moving it somewhere else would be nice.

@hunner
Copy link

hunner commented Mar 7, 2016

Looks like there is a merge conflict also, so can't be merged currently. Thanks for working on this!

@vicinus
Copy link
Author

vicinus commented Mar 8, 2016

Ok, I have created the class haproxy::globals and moved the parameter sort_options_alphabetic there. I also resolved the merge conflict, but as I never had to resolve a merge conflict in my pull request, I'm not sure if there is anything more to do. Is it possible to squash the merge commit in the previous commit?

@@ -77,6 +82,8 @@
$instance_name = "haproxy-${instance}"
$config_file = inline_template($haproxy::params::config_file_tmpl)
}
include haproxy::globals
$_sort_options_alphabetic = pick($sort_options_alphabetic, $haproxy::globals::sort_options_alphabetic)
Copy link

Choose a reason for hiding this comment

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

Is it impossible to put the sort_options_alphabetic parameter in the base haproxy class and follow this pattern as usual, instead of having a haproxy::globals class? We only use globals when it is otherwise impossible to use the base class.

Copy link
Author

Choose a reason for hiding this comment

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

It is impossible because you can use the haproxy module without using the haproxy class, only using haproxy::instance resources.

Copy link

Choose a reason for hiding this comment

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

Ah right, because the base class declares a default instance.

hunner added a commit that referenced this pull request Mar 10, 2016
improve ordering of options
@hunner hunner merged commit d66a33b into puppetlabs:master Mar 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants