mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-23 18:04:34 +00:00
fix: dependencies and deprecated code (#390)
This commit is contained in:
co-authored by
GitHub
parent
14cab08024
commit
dddd130e79
@@ -11,13 +11,13 @@ class IrHttp(models.AbstractModel):
|
||||
_inherit = 'ir.http'
|
||||
|
||||
@classmethod
|
||||
def _dispatch(cls):
|
||||
def _dispatch(cls, endpoint):
|
||||
if not statsd:
|
||||
return super()._dispatch()
|
||||
return super()._dispatch(endpoint)
|
||||
|
||||
path_info = request.httprequest.environ.get('PATH_INFO')
|
||||
if path_info.startswith('/longpolling/'):
|
||||
return super()._dispatch()
|
||||
return super()._dispatch(endpoint)
|
||||
|
||||
parts = ['http', ]
|
||||
if path_info.startswith('/web/dataset/call_button'):
|
||||
@@ -38,4 +38,4 @@ class IrHttp(models.AbstractModel):
|
||||
]
|
||||
|
||||
with statsd.timer('.'.join(parts)):
|
||||
return super()._dispatch()
|
||||
return super()._dispatch(endpoint)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
_MAP = {
|
||||
'y': True,
|
||||
'yes': True,
|
||||
't': True,
|
||||
'true': True,
|
||||
'on': True,
|
||||
'1': True,
|
||||
'n': False,
|
||||
'no': False,
|
||||
'f': False,
|
||||
'false': False,
|
||||
'off': False,
|
||||
'0': False
|
||||
}
|
||||
|
||||
|
||||
def strtobool(value):
|
||||
try:
|
||||
return _MAP[str(value).lower()]
|
||||
except KeyError:
|
||||
raise ValueError('"{}" is not a valid bool value'.format(value))
|
||||
@@ -4,9 +4,7 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from distutils.util import strtobool
|
||||
|
||||
from odoo.tools.config import config
|
||||
from .strtobool import strtobool
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -14,40 +12,39 @@ try:
|
||||
from statsd import defaults
|
||||
from statsd.client import StatsClient
|
||||
except ImportError:
|
||||
_logger.warning('statds must be installed')
|
||||
_logger.warning("statds must be installed")
|
||||
defaults = None # noqa
|
||||
StatsClient = None # noqa
|
||||
|
||||
|
||||
def is_true(strval):
|
||||
return bool(strtobool(strval or '0'.lower()))
|
||||
return bool(strtobool(strval or "0".lower()))
|
||||
|
||||
|
||||
statsd_active = is_true(os.environ.get('ODOO_STATSD'))
|
||||
statsd_active = is_true(os.environ.get("ODOO_STATSD"))
|
||||
|
||||
statsd = None
|
||||
customer = None
|
||||
environment = None
|
||||
if statsd_active and statsd is None and StatsClient is not None:
|
||||
if not os.environ.get('STATSD_CUSTOMER'):
|
||||
raise Exception(
|
||||
'STATSD_CUSTOMER must contain the name of the customer'
|
||||
)
|
||||
customer = os.environ.get('STATSD_CUSTOMER')
|
||||
if os.environ.get('STATSD_ENVIRONMENT'):
|
||||
environment = os.environ['STATSD_ENVIRONMENT']
|
||||
elif config.get('running_env'):
|
||||
environment = config['running_env']
|
||||
if not os.environ.get("STATSD_CUSTOMER"):
|
||||
raise Exception("STATSD_CUSTOMER must contain the name of the customer")
|
||||
customer = os.environ.get("STATSD_CUSTOMER")
|
||||
if os.environ.get("STATSD_ENVIRONMENT"):
|
||||
environment = os.environ["STATSD_ENVIRONMENT"]
|
||||
elif config.get("running_env"):
|
||||
environment = config["running_env"]
|
||||
else:
|
||||
raise Exception(
|
||||
'Either STATSD_ENVIRONMENT or configuration option running_env '
|
||||
'must contain the environment (prod, integration, ...)'
|
||||
"Either STATSD_ENVIRONMENT or configuration option running_env "
|
||||
"must contain the environment (prod, integration, ...)"
|
||||
)
|
||||
|
||||
host = os.getenv('STATSD_HOST', defaults.HOST)
|
||||
port = int(os.getenv('STATSD_PORT', defaults.PORT))
|
||||
prefix = os.getenv('STATSD_PREFIX', defaults.PREFIX)
|
||||
maxudpsize = int(os.getenv('STATSD_MAXUDPSIZE', defaults.MAXUDPSIZE))
|
||||
ipv6 = bool(int(os.getenv('STATSD_IPV6', defaults.IPV6)))
|
||||
statsd = StatsClient(host=host, port=port, prefix='odoo',
|
||||
maxudpsize=maxudpsize, ipv6=ipv6)
|
||||
host = os.getenv("STATSD_HOST", defaults.HOST)
|
||||
port = int(os.getenv("STATSD_PORT", defaults.PORT))
|
||||
prefix = os.getenv("STATSD_PREFIX", defaults.PREFIX)
|
||||
maxudpsize = int(os.getenv("STATSD_MAXUDPSIZE", defaults.MAXUDPSIZE))
|
||||
ipv6 = bool(int(os.getenv("STATSD_IPV6", defaults.IPV6)))
|
||||
statsd = StatsClient(
|
||||
host=host, port=port, prefix="odoo", maxudpsize=maxudpsize, ipv6=ipv6
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user