-
Notifications
You must be signed in to change notification settings - Fork 300
add HAPROXY_GLOBAL_DEFAULT_OPTIONS via environment variable #367
Conversation
Can one of the admins verify this patch? |
Add |
@@ -21,6 +21,11 @@ def add_template(self, template): | |||
self.t[template.name] = template | |||
|
|||
def load(self): | |||
httplog = os.getenv('HTTPLOG', default='') | |||
option_httplog = '' | |||
if httplog not in ['no', '0', 'false', '']: |
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.
if httplog.lower() not in ['no', '0', 'false', '']:
|
||
def setUp(self): | ||
self.maxDiff = None | ||
os.environ['HTTPLOG'] = 'true' |
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.
Miss a test with values ['no', '0', 'false']
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.
In UPPER case too
Ok; added 'TCPLOG' option as well, and updated tests to cover various cases of 'disabled' |
test this please |
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.
Can we make this a little more generic? How about we have an env var like HAPROXY_DEFAULT_OPTIONS
which takes a comma separated list of default options that get appended to the default template?
Also, we need to document this and especially note that it will only apply if the default template has not been overridden.
Ok, guys; take#3, now with |
@@ -20,6 +21,17 @@ class ConfigTemplater(object): | |||
def add_template(self, template): | |||
self.t[template.name] = template | |||
|
|||
def additional_default_options(self): |
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.
LGTM, but just a suggestion:
def additional_default_options(self):
base_options = ['redispatch', 'http-server-close', 'dontlognull']
opts = set(s.strip() for s in os.getenv('HAPROXY_DEFAULT_OPTIONS', '').split(','))
template = ' option {opt}\n'
lines = [template.format(opt=opt) for opt in opts if opt not in base_options]
return ''.join(lines)
And remove the re
import
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.
Updating my suggestion after all @brndnmtthws suggestions:
def additional_default_options(self):
default = 'redispatch,http-server-close,dontlognull'
options = os.getenv('HAPROXY_GLOAL_DEFAULT_OPTIONS', default)
template = ' option {opt}\n'
lines = set(template.format(opt=opt.strip()) for opt in options.split(','))
return ''.join(lines)
if 'HAPROXY_DEFAULT_OPTIONS' in os.environ: | ||
opts = set(re.split('\s*,\s', | ||
os.getenv('HAPROXY_DEFAULT_OPTIONS'))) | ||
for opt in [x for x in opts if x not in base_options]: |
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.
How about we remove the default options from the base template, and then set redispatch,http-server-close,dontlognull
as the default option set. This way, if someone wants to remove some of the options, they can.
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.
But we need to keep it very clear on documentation.
def additional_default_options(self): | ||
output = '' | ||
base_options = ['redispatch', 'http-server-close', 'dontlognull'] | ||
if 'HAPROXY_DEFAULT_OPTIONS' in os.environ: |
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.
Another nit: maybe instead of HAPROXY_DEFAULT_OPTIONS
we could call it HAPROXY_GLOAL_DEFAULT_OPTIONS
.
Alright; we good now? |
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.
LGTM. Just small fix
list of options may be specified via the `HAPROXY_GLOBAL_DEFAULT_OPTIONS` environment variable. | ||
The default value when not specified is `redispatch,http-server-close,dontlognull`; as an example, to add the | ||
`httplog` option (and keep the existing defaults), one should specify `HAPROXY_GLOBAL_DEFAULT_OPTIONS=redispatch,http-server-close,dontlognull,httplog`. | ||
- _Note that this setting has no effect when the `HAPROXY_HEAD` tmeplate has been overridden._ |
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.
tmeplate -> template
@@ -2,6 +2,7 @@ | |||
|
|||
import logging | |||
import os | |||
import re |
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.
Delete this line
os.environ['HAPROXY_GLOBAL_DEFAULT_OPTIONS'] = \ | ||
'httplog,tcplog,dontlognull,tcplog' | ||
base_config = base_config_prefix | ||
# base_config += template_option('redispatch') |
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.
Remove commented code
self.maxDiff = None | ||
os.environ['HAPROXY_GLOBAL_DEFAULT_OPTIONS'] = 'httplog,tcplog' | ||
base_config = base_config_prefix | ||
# base_config += template_option('redispatch') |
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.
Remove commented code
added 'TCPLOG' option more tests, and 'is_option_enabled' update tests implemented HAPROXY_DEFAULT_OPTIONS update docs applied latest suggestions rename to global_default_options code & doc cleanup
Perfect 👌 |
Hi guys, not sure if you saw in there was a bug introduced in one of the On Saturday, November 12, 2016, Brenden Matthews [email protected]
|
This allows for setting global default haproxy options via the
HAPROXY_GLOBAL_DEFAULT_OPTIONS
environment variable as a comma-separated list.