Skip to content

Commit

Permalink
Merge pull request #12 from vimc/cleanup-proxy-metrics
Browse files Browse the repository at this point in the history
Remove custom proxy-metrics code.
  • Loading branch information
plietar authored Dec 6, 2024
2 parents d8b6856 + 62ffa2d commit f8fe27a
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 193 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ jobs:
- name: Pull images
run: |
docker pull mher/flower:0.9.5
docker pull nginx/nginx-prometheus-exporter:0.10.0
docker pull nginx/nginx-prometheus-exporter:0.4.1
docker pull nginx/nginx-prometheus-exporter:1.3.0
docker pull reachfive/fake-smtp-server:latest
docker pull redis
docker pull redis:5.0
Expand Down
2 changes: 1 addition & 1 deletion config/basic/montagu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ proxy:
metrics:
repo: nginx
name: nginx-prometheus-exporter
tag: 0.10.0
tag: 1.3.0
contrib:
name: montagu-contrib-portal
tag: master
Expand Down
4 changes: 2 additions & 2 deletions config/ci/montagu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ vault:
## a list, which is currently
##
## azure, github, gcp, kubernetes, ldap, mfa, okta
method: github
method: token

## Prefix for container names; we'll use {container_prefix}-(container_name)
container_prefix: montagu
Expand Down Expand Up @@ -89,7 +89,7 @@ proxy:
metrics:
repo: nginx
name: nginx-prometheus-exporter
tag: 0.10.0
tag: 1.3.0
contrib:
name: montagu-contrib-portal
tag: master
Expand Down
2 changes: 1 addition & 1 deletion config/complete/montagu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ proxy:
metrics:
repo: nginx
name: nginx-prometheus-exporter
tag: 0.4.1
tag: 1.3.0
## This section describes how to get the certificate in. We
## support two sources:
##
Expand Down
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ style = [
]
fmt = [
"black {args:.}",
"ruff --fix {args:.}",
"ruff check --fix {args:.}",
"style",
]
all = [
Expand All @@ -105,6 +105,8 @@ skip-string-normalization = true
[tool.ruff]
target-version = "py37"
line-length = 120

[tool.ruff.lint]
select = [
"A",
"ARG",
Expand Down Expand Up @@ -149,13 +151,13 @@ unfixable = [
"F401",
]

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party = ["montagu_deploy"]

[tool.ruff.flake8-tidy-imports]
[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252"]

Expand Down
4 changes: 2 additions & 2 deletions src/montagu_deploy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import montagu_deploy.__about__ as about
from montagu_deploy.config import MontaguConfig
from montagu_deploy.montagu_constellation import MontaguConstellation
from montagu_deploy.montagu_constellation import montagu_constellation


def main(argv=None):
Expand All @@ -35,7 +35,7 @@ def main(argv=None):
return about.__version__
else:
cfg = MontaguConfig(path, extra, options)
obj = MontaguConstellation(cfg)
obj = montagu_constellation(cfg)
if args.action == "start":
montagu_start(obj, args)
elif args.action == "status":
Expand Down
99 changes: 26 additions & 73 deletions src/montagu_deploy/montagu_constellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,26 @@
from montagu_deploy import database


class MontaguConstellation:
def __init__(self, cfg):
api = api_container(cfg)
db = db_container(cfg)
admin = admin_container(cfg)
contrib = contrib_container(cfg)
proxy = proxy_container(cfg)
mq = mq_container(cfg)
flower = flower_container(cfg)
task_queue = task_queue_container(cfg)

containers = [api, db, admin, contrib, proxy, mq, flower, task_queue]

if cfg.fake_smtp_ref:
fake_smtp = fake_smtp_container(cfg)
containers.append(fake_smtp)

self.cfg = cfg
self.obj = constellation.Constellation(
"montagu", cfg.container_prefix, containers, cfg.network, cfg.volumes, data=cfg, vault_config=cfg.vault
)

def start(self, **kwargs):
self.obj.start(**kwargs)
# The proxy metrics container cannot be started via constellation, because
# it has to belong to the same network as the proxy as soon as it is started
# and constellation starts containers on the 'none' network. So we provide
# start/stop/status methods for the metrics container that mimic the
# constellation behaviour
start_proxy_metrics(self.cfg)

def stop(self, **kwargs):
stop_proxy_metrics(self.cfg)
self.obj.stop(**kwargs)

def status(self):
self.obj.status()
status_proxy_metrics(self.cfg)
def montagu_constellation(cfg):
containers = [
api_container(cfg),
db_container(cfg),
admin_container(cfg),
contrib_container(cfg),
proxy_container(cfg),
proxy_metrics_container(cfg),
mq_container(cfg),
flower_container(cfg),
task_queue_container(cfg),
]

if cfg.fake_smtp_ref:
fake_smtp = fake_smtp_container(cfg)
containers.append(fake_smtp)

return constellation.Constellation(
"montagu", cfg.container_prefix, containers, cfg.network, cfg.volumes, data=cfg, vault_config=cfg.vault
)


def admin_container(cfg):
Expand Down Expand Up @@ -250,40 +232,11 @@ def proxy_configure(container, cfg):
docker_util.string_into_container(cfg.dhparam, container, join(ssl_path, "dhparam.pem"))


def start_proxy_metrics(cfg):
name = "{}-{}".format(cfg.container_prefix, cfg.containers["metrics"])
def proxy_metrics_container(cfg):
proxy_name = cfg.containers["proxy"]
image = str(cfg.proxy_metrics_ref)
print("Starting {} ({})".format(cfg.containers["metrics"], image))
docker.from_env().containers.run(
image,
restart_policy={"Name": "always"},
ports={"9113/tcp": 9113},
command=f'-nginx.scrape-uri "http://{proxy_name}/basic_status"',
network=cfg.network,
name=name,
detach=True,
return constellation.ConstellationContainer(
cfg.containers["metrics"],
cfg.proxy_metrics_ref,
ports=[9113],
args=["-nginx.scrape-uri", f"http://{proxy_name}/basic_status"],
)


def stop_proxy_metrics(cfg):
name = "{}-{}".format(cfg.container_prefix, cfg.containers["metrics"])
container = get_container(name)
if container:
print(f"Killing '{name}'")
container.remove(force=True)


def status_proxy_metrics(cfg):
name = "{}-{}".format(cfg.container_prefix, cfg.containers["metrics"])
container = get_container(name)
status = container.status if container else "missing"
print(" - {} ({}): {}".format(cfg.containers["metrics"], name, status))


def get_container(name):
client = docker.client.from_env()
try:
return client.containers.get(name)
except docker.errors.NotFound:
return None
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_config_basic():
assert str(cfg.images["mq"]) == "docker.io/redis:latest"
assert str(cfg.images["flower"]) == "mher/flower:0.9.5"
assert str(cfg.images["task_queue"]) == "vimc/task-queue-worker:master"
assert str(cfg.images["metrics"]) == "nginx/nginx-prometheus-exporter:0.10.0"
assert str(cfg.images["metrics"]) == "nginx/nginx-prometheus-exporter:1.3.0"
assert str(cfg.images["db_migrate"]) == "vimc/montagu-migrate:master"
assert str(cfg.images["fake_smtp"]) == "reachfive/fake-smtp-server:latest"

Expand Down
Loading

0 comments on commit f8fe27a

Please sign in to comment.