jsocol / pystatsd

A Python client for statsd
http://statsd.readthedocs.io/
MIT License
542 stars 177 forks source link

STATSD_IPV6 is not working #187

Closed ischedrov closed 2 months ago

ischedrov commented 2 months ago

Hi there,

I'm trying to configure statsd client on k8s pod. STATSD_IPV6=1 was configured during pod initialization. The statsd exporter pod placed behind the service in the same namespace and available via service name 'statsd-exporter' on 9125 UDP port. When I'm trying to connect to statsd exporter using the code below:

import logging
from statsd import StatsClient

logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)

try:
    statsd_client = StatsClient(host='statsd-exporter', port=9125)
    log.info("Successfully connected to StatsD over IPv6")
except Exception as e:
    log.error("Error connecting to StatsD over IPv6: %s", e)

I received an error: ERROR:main:Error connecting to StatsD over IPv6: [Errno -5] No address associated with hostname

root@pod: echo $STATSD_IPV6
1

But if I specify parameter ipv6=True like that statsd_client = StatsClient(host='statsd-exporter', port=9125, ipv6=True) everything works correctly:

INFO:main:Successfully connected to StatsD over IPv6

From my perspective, the environment where I'm testing looks correct. DNS correctly resolves the names and 9125 is available (tested via netcat utility).

jsocol commented 2 months ago

The constructor on the client doesn’t automatically read environment variables. There is a default client configured via the environment in from statsd.defaults.env import statsd, which pulls all of the configuration from the environment, if you don’t mind setting STATSD_HOST="statsd-exporter" and STATSD_PORT=9125 too

ischedrov commented 2 months ago

@jsocol thank you! It works