Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions commerce_coordinator/docker_gunicorn_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,29 @@


# StatsD / DogStatsD configuration
# Gunicorn's statsd_host validator (validate_statsd_address) accepts a STRING:
# "HOST:PORT" -> Gunicorn parses into (host, port) tuple -> AF_INET UDP
# "unix://PATH" -> Gunicorn parses into a bare string path -> AF_UNIX SOCK_DGRAM
_dogstatsd_url = os.environ.get("DD_DOGSTATSD_URL", "").strip()

if _dogstatsd_url:
if _dogstatsd_url.startswith("unix://"):
# Gunicorn accepts unix socket directly as "unix:///path".
_statsd_host = _dogstatsd_url if _dogstatsd_url != "unix://" else ""
if _dogstatsd_url.startswith(("unix://", "unixgram://")):
# Normalize unixgram:// -> unix:// (Gunicorn's validator expects unix://)
_socket_path = _dogstatsd_url.split("://", 1)[1]
if _socket_path: # guard against bare "unix://" with no path
statsd_host = f"unix://{_socket_path}"
statsd_prefix = "commerce-coordinator"
else:
# Strip "udp://" when present; Gunicorn expects plain "HOST:PORT".
# Strip udp:// if present; pass plain HOST:PORT string to Gunicorn
_statsd_host = (
_dogstatsd_url[len("udp://"):]
if _dogstatsd_url.startswith("udp://")
else _dogstatsd_url
).strip()

if _statsd_host:
statsd_host = _statsd_host
statsd_prefix = "commerce-coordinator"
if _statsd_host:
statsd_host = _statsd_host
statsd_prefix = "commerce-coordinator"


def pre_request(worker, req):
Expand Down
Loading