fix: strips URI scheme prefixes from DD_DOGSTATSD_URL - #556
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Gunicorn configuration used in containerized deployments to normalize DD_DOGSTATSD_URL into a value suitable for Gunicorn’s StatsD/DogStatsD configuration, aiming to prevent metrics initialization errors when the environment variable includes a URI scheme.
Changes:
- Adds scheme-stripping/normalization logic for
DD_DOGSTATSD_URLbefore assigningstatsd_host. - Adds startup logging to record the configured
statsd_host.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
commerce_coordinator/docker_gunicorn_configuration.py:29
- PR title/description say this change strips the
unix://scheme fromDD_DOGSTATSD_URL, but this implementation preservesunix://(and normalizesunixgram://->unix://) when configuringstatsd_host. Please update the PR title/description to reflect the actual behavior (normalization +udp://stripping) so the change is not misrepresented in release notes/backports.
if _dogstatsd_url.startswith(("unix://", "unixgram://")):
# Normalize unixgram:// -> unix:// (Gunicorn's validator expects unix://)
_socket_path = _dogstatsd_url.split("://", 1)[1]
if _socket_path:
# Pass as a string; Gunicorn validator detects this and sets address_family = AF_UNIX
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
commerce_coordinator/docker_gunicorn_configuration.py:28
- PR title/description says it "strips protocol prefixes (unix://) from DD_DOGSTATSD_URL", but this code path keeps/normalizes the unix socket scheme (it rebuilds
statsd_hostasunix://{path}and only stripsudp://). This is a discrepancy that can confuse reviewers/operators trying to reason about the expected env var format.
# 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://", "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:// if present; pass plain HOST:PORT string to Gunicorn
Fixes metrics error by stripping protocol prefixes (unix://) from DD_DOGSTATSD_URL.
Merge checklist:
Check off if complete or not applicable:
Post-merge: