fix: correctly read the SYNC_STATSD_HOST/PORT settings (#1601)

Closes SYNC-4417
This commit is contained in:
Philip Jenvey 2024-09-23 17:31:51 -07:00 committed by GitHub
parent be23e39135
commit 3675c9387b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 28 deletions

View File

@ -181,18 +181,7 @@ def main(args=None):
help="Control verbosity of log messages")
parser.add_option("", "--human_logs", action="store_true",
help="Human readable logs")
parser.add_option(
"",
"--metric_host",
default=None,
help="Metric host name"
)
parser.add_option(
"",
"--metric_port",
default=None,
help="Metric host port"
)
util.add_metric_options(parser)
opts, args = parser.parse_args(args)
# set up logging

View File

@ -386,18 +386,7 @@ def main(args=None):
action="store_true",
help="Human readable logs"
)
parser.add_option(
"",
"--metric_host",
default=None,
help="Metric host name"
)
parser.add_option(
"",
"--metric_port",
default=None,
help="Metric host port"
)
util.add_metric_options(parser)
opts, args = parser.parse_args(args)

View File

@ -11,6 +11,7 @@ import sys
import time
import logging
import base64
import optparse
import os
import json
from datetime import datetime
@ -104,13 +105,27 @@ class Metrics():
options = dict(
namespace=namespace,
statsd_namespace=namespace,
statsd_host=getattr(
opts, "metric_host", os.environ.get("SYNC_STATSD_HOST")),
statsd_port=getattr(
opts, "metric_port", os.environ.get("SYNC_STATSD_PORT")),
statsd_host=getattr(opts, "metric_host"),
statsd_port=getattr(opts, "metric_port"),
)
self.prefix = options.get("namespace")
initialize(**options)
def incr(self, label, tags=None):
statsd.increment(label, tags=tags)
def add_metric_options(parser: optparse.OptionParser):
"""Add generic metric related options to an OptionParser"""
parser.add_option(
"",
"--metric_host",
default=os.environ.get("SYNC_STATSD_HOST"),
help="Metric host name"
)
parser.add_option(
"",
"--metric_port",
default=os.environ.get("SYNC_STATSD_PORT"),
help="Metric host port"
)