From 2c86ac75094925ad1ca4d7f8d678c4adfbcecce8 Mon Sep 17 00:00:00 2001 From: Dylan Stephano-Shachter Date: Thu, 26 Oct 2023 12:31:00 +0000 Subject: [PATCH 1/4] allow user to set listen address and port --- cos_alerter/alerter.py | 2 +- cos_alerter/config-defaults.yaml | 4 ++++ cos_alerter/daemon.py | 7 ++++++- pyproject.toml | 2 +- snap/snapcraft.yaml | 2 +- tox.ini | 2 ++ 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cos_alerter/alerter.py b/cos_alerter/alerter.py index 429c9a7..7acf7bb 100644 --- a/cos_alerter/alerter.py +++ b/cos_alerter/alerter.py @@ -55,7 +55,7 @@ def deep_update(base: dict, new: typing.Optional[dict]): if new is None: return for key in base: - if key in new and type(base[key]) == dict: + if key in new and isinstance(base[key], dict): deep_update(base[key], new[key]) elif key in new: base[key] = new[key] diff --git a/cos_alerter/config-defaults.yaml b/cos_alerter/config-defaults.yaml index 8a53535..6e81a03 100644 --- a/cos_alerter/config-defaults.yaml +++ b/cos_alerter/config-defaults.yaml @@ -35,3 +35,7 @@ notify: # The logging level of COS Alerter # Levels available: critical, error, warning, info, debug log_level: "info" + +# The address to listen on for http traffic. +# Format HOST:PORT +web_listen_addr: "0.0.0.0:8080" diff --git a/cos_alerter/daemon.py b/cos_alerter/daemon.py index 2163ca3..057c918 100644 --- a/cos_alerter/daemon.py +++ b/cos_alerter/daemon.py @@ -95,7 +95,12 @@ def main(run_for: Optional[int] = None, argv: List[str] = sys.argv): # from the daemon. It also facilitates communication over memory rather than files. # clear_untrusted_proxy_headers is set to suppress a DeprecationWarning. server_thread = threading.Thread( - target=waitress.serve, args=(app,), kwargs={"clear_untrusted_proxy_headers": True} + target=waitress.serve, + args=(app,), + kwargs={ + "clear_untrusted_proxy_headers": True, + "listen": config["web_listen_addr"], + }, ) server_thread.daemon = True # Makes this thread exit when the main thread exits. logger.info("Starting the web server thread.") diff --git a/pyproject.toml b/pyproject.toml index e85702a..bafb5c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "cos-alerter" -version = "0.4.0" +version = "0.5.0" authors = [ { name="Dylan Stephano-Shachter", email="dylan.stephano-shachter@canonical.com" } ] diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 065954b..9a41063 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: cos-alerter -version: '0.4.0' +version: '0.5.0' summary: A watchdog alerting on alertmanager notification failures. license: Apache-2.0 contact: simon.aronsson@canonical.com diff --git a/tox.ini b/tox.ini index 5772d29..7f1e633 100644 --- a/tox.ini +++ b/tox.ini @@ -32,6 +32,8 @@ commands = [testenv:static] description = Run static analysis checks deps = + types-pyyaml + types-waitress pyright commands = pyright From 1c218cb7d4ee4dbd8e171e08c78d0a3beaf7680c Mon Sep 17 00:00:00 2001 From: Dylan Stephano-Shachter Date: Thu, 26 Oct 2023 13:59:18 +0000 Subject: [PATCH 2/4] bump rock version --- rockcraft.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rockcraft.yaml b/rockcraft.yaml index 9855feb..9d445f9 100644 --- a/rockcraft.yaml +++ b/rockcraft.yaml @@ -1,7 +1,7 @@ name: cos-alerter summary: A liveness checker for self-monitoring. description: Receive regular pings from the cos stack and alert when they stop. -version: "0.4.0" # NOTE: Make sure this matches `cos-alerter` below +version: "0.5.0" # NOTE: Make sure this matches `cos-alerter` below base: ubuntu:22.04 license: Apache-2.0 platforms: @@ -11,7 +11,7 @@ parts: plugin: python source: . python-packages: - - cos-alerter==0.4.0 # NOTE: Make sure this matches `version` above + - cos-alerter==0.5.0 # NOTE: Make sure this matches `version` above stage-packages: - python3-venv services: From 7e8001b1d2bddce8546a76556cb136387e44abc2 Mon Sep 17 00:00:00 2001 From: Dylan Stephano-Shachter Date: Thu, 26 Oct 2023 14:02:05 +0000 Subject: [PATCH 3/4] changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b332c10..768f175 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.5.0] - 2023-10-26 + - Added usage instructions to the readme (#51). - Added snapcraft build recipes and automation. (#52) +- Added the ability to set the listen address and port for the web server. (#55) ## [0.4.0] - 2023-05-31 From 9745846a6a3a6930acf8cb7f2a9e688d78b428c6 Mon Sep 17 00:00:00 2001 From: Dylan Stephano-Shachter Date: Thu, 26 Oct 2023 14:04:04 +0000 Subject: [PATCH 4/4] update codeowners --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index 0f45ae9..40f9f33 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1 +1 @@ -* @abuelodelanada @dstathis @lucabello @PietroPasotti @rbarry82 @sed-i @simskij +* @abuelodelanada @dstathis @lucabello @PietroPasotti @sed-i @simskij @mmkay @IbraAoad