Skip to content

Commit

Permalink
statsd: get host and port from config
Browse files Browse the repository at this point in the history
  • Loading branch information
nosahama committed Aug 23, 2024
1 parent 99c1046 commit 44b578f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
4 changes: 4 additions & 0 deletions karapace/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class Config(TypedDict):
name_strategy_validation: bool
master_election_strategy: str
protobuf_runtime_directory: str
statsd_host: str
statsd_port: int

sentry: NotRequired[Mapping[str, object]]
tags: NotRequired[Mapping[str, object]]
Expand Down Expand Up @@ -150,6 +152,8 @@ class ConfigDefaults(Config, total=False):
"name_strategy_validation": True,
"master_election_strategy": "lowest",
"protobuf_runtime_directory": "runtime",
"statsd_host": "127.0.0.1",
"statsd_port": 8125,
}
SECRET_CONFIG_OPTIONS = [SASL_PLAIN_PASSWORD]

Expand Down
11 changes: 2 additions & 9 deletions karapace/statsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,12 @@
import socket
import time

STATSD_HOST: Final = "127.0.0.1"
STATSD_PORT: Final = 8125
LOG = logging.getLogger(__name__)


class StatsClient:
def __init__(
self,
config: Config,
host: str = STATSD_HOST,
port: int = STATSD_PORT,
) -> None:
self._dest_addr: Final = (host, port)
def __init__(self, config: Config) -> None:
self._dest_addr: Final = (config["statsd_host"], config["statsd_port"])
self._socket: Final = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self._tags: Final = config.get("tags", {})
self.sentry_client: Final = get_sentry_client(sentry_config=config.get("sentry", None))
Expand Down

0 comments on commit 44b578f

Please sign in to comment.