Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

add HAPROXY_GLOBAL_DEFAULT_OPTIONS via environment variable #367

Merged
merged 1 commit into from
Nov 12, 2016
Merged

add HAPROXY_GLOBAL_DEFAULT_OPTIONS via environment variable #367

merged 1 commit into from
Nov 12, 2016

Conversation

matt-deboer
Copy link
Contributor

@matt-deboer matt-deboer commented Nov 9, 2016

This allows for setting global default haproxy options via the HAPROXY_GLOBAL_DEFAULT_OPTIONS environment variable as a comma-separated list.

@mesosphere-ci
Copy link

Can one of the admins verify this patch?

@robsonpeixoto
Copy link
Contributor

Add option tcplog would be great, too =D

@@ -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', '']:
Copy link
Contributor

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'
Copy link
Contributor

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']

Copy link
Contributor

Choose a reason for hiding this comment

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

In UPPER case too

@matt-deboer
Copy link
Contributor Author

Ok; added 'TCPLOG' option as well, and updated tests to cover various cases of 'disabled'

@brndnmtthws
Copy link
Contributor

test this please

Copy link
Contributor

@brndnmtthws brndnmtthws left a 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.

@matt-deboer matt-deboer changed the title add HTTPLOG default via environment variable add HAPROXY_DEFAULT_OPTIONS via environment variable Nov 11, 2016
@matt-deboer
Copy link
Contributor Author

Ok, guys; take#3, now with HAPROXY_DEFAULT_OPTIONS and docs!

@@ -20,6 +21,17 @@ class ConfigTemplater(object):
def add_template(self, template):
self.t[template.name] = template

def additional_default_options(self):
Copy link
Contributor

@robsonpeixoto robsonpeixoto Nov 11, 2016

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

Copy link
Contributor

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]:
Copy link
Contributor

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.

Copy link
Contributor

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:
Copy link
Contributor

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.

@matt-deboer matt-deboer changed the title add HAPROXY_DEFAULT_OPTIONS via environment variable add HAPROXY_GLOBAL_DEFAULT_OPTIONS via environment variable Nov 11, 2016
@matt-deboer
Copy link
Contributor Author

Alright; we good now?

Copy link
Contributor

@robsonpeixoto robsonpeixoto left a 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._
Copy link
Contributor

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
Copy link
Contributor

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')
Copy link
Contributor

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')
Copy link
Contributor

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
@brndnmtthws
Copy link
Contributor

Perfect 👌

@brndnmtthws brndnmtthws merged commit 1c400ff into d2iq-archive:master Nov 12, 2016
@matt-deboer
Copy link
Contributor Author

Hi guys, not sure if you saw in there was a bug introduced in one of the
last updates; I added a new PR to fix it...sorry about that :/

On Saturday, November 12, 2016, Brenden Matthews [email protected]
wrote:

Merged #367 #367.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#367 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABbBtaH6TZOFHwB2No9dfLZIr-4KG8xrks5q9epPgaJpZM4KuC0h
.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants