Skip to content

Commit

Permalink
setup registry_url, metrics_port, env vars and CLI args
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbara Miller committed Sep 13, 2024
1 parent 80ce6c0 commit b3e08b9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 14 deletions.
53 changes: 53 additions & 0 deletions brozzler/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ def _get_help_string(self, action):
return super()._get_help_string(action)


class Env(str, enum.Enum):
"""Values of the Prometheus ``env`` label applied to a
:py:class:`.Registration` indicating the deployment environment in which
the service being advertised is operating.
"""

qa = "qa"
prod = "prod"
dev = "dev"


def brozzle_page(argv=None):
"""
Command line utility entry point for brozzling a single page. Opens url in
Expand Down Expand Up @@ -234,6 +245,24 @@ def brozzle_page(argv=None):
action="store_true",
help="Try to avoid web bot detection",
)
arg_parser.add_argument(
"--registry_url",
dest="registry_url",
default=None,
help="Prometheus registry url",
)
arg_parser.add_argument(
"--metrics_port",
dest=metrics_port,
default=8889,
help="Prometheus metrics port",
)
arg_parser.add_argument(
"--env",
dest=env,
default=Env.dev,
help="Prometheus env value",
)
arg_parser.add_argument(
"--screenshot-full-page", dest="screenshot_full_page", action="store_true"
)
Expand Down Expand Up @@ -279,6 +308,9 @@ def brozzle_page(argv=None):
window_height=args.window_height,
window_width=args.window_width,
stealth=args.stealth,
registry_url=args.registry_url,
metrics_port=args.metrics_port,
env=args.env,
)

def on_screenshot(screenshot_jpeg):
Expand Down Expand Up @@ -517,6 +549,24 @@ def brozzler_worker(argv=None):
action="store_true",
help="Try to avoid web bot detection",
)
arg_parser.add_argument(
"--registry_url",
dest="registry_url",
default=None,
help="Prometheus registry url",
)
arg_parser.add_argument(
"--metrics_port",
dest=metrics_port,
default=8888,
help="Prometheus metrics port",
)
arg_parser.add_argument(
"--env",
dest=env,
default=Env.qa,
help="Prometheus env value",
)
add_common_options(arg_parser, argv)

args = arg_parser.parse_args(args=argv[1:])
Expand Down Expand Up @@ -573,6 +623,9 @@ def get_skip_av_seeds():
skip_visit_hashtags=args.skip_visit_hashtags,
skip_youtube_dl=args.skip_youtube_dl,
stealth=args.stealth,
registry_url=args.registry_url,
metrics_port=args.metrics_port,
env=args.env,
)

signal.signal(signal.SIGQUIT, dump_state)
Expand Down
2 changes: 1 addition & 1 deletion brozzler/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class Env(str, enum.Enum):
"""Values of the Prometheus ``env`` label applied to a
:py:class:`.Registration` indicating the deployment environment in which
the the service being advertised is operating.
the service being advertised is operating.
"""

qa = "qa"
Expand Down
25 changes: 12 additions & 13 deletions brozzler/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import PIL.Image
import io
import socket
import platform
import random
import requests
import doublethink
Expand All @@ -42,18 +41,6 @@
r = rdb.RethinkDB()


# Setup metrics
registry_url = None
metrics_port = 8090
env = metrics.Env.dev
hostname = platform.node()
if hostname.endswith("archive.org"):
registry_url = "http://wbgrp-svc283.us.archive.org:8888"
metrics_port = settings.metrics_port
env = metrics.Env.qa
metrics.register_prom_metrics(registry_url, metrics_port, env)


class BrozzlerWorker:
logger = logging.getLogger(__module__ + "." + __qualname__)

Expand Down Expand Up @@ -85,6 +72,9 @@ def __init__(
stealth=False,
window_height=900,
window_width=1400,
registry_url=None,
metrics_port=None,
env=None,
):
self._frontier = frontier
self._service_registry = service_registry
Expand All @@ -107,6 +97,9 @@ def __init__(
self._window_height = window_height
self._window_width = window_width
self._stealth = stealth
self._registry_url = registry_url
self._metrics_port = metrics_port
self._env = env

self._browser_pool = brozzler.browser.BrowserPool(
max_browsers, chrome_exe=chrome_exe, ignore_cert_errors=True
Expand All @@ -118,6 +111,12 @@ def __init__(
self._start_stop_lock = threading.Lock()
self._shutdown = threading.Event()

# Setup metrics
registry_url = self._registry_url
metrics_port = self._metrics_port
env = self._env
metrics.register_prom_metrics(registry_url, metrics_port, env)

def _choose_warcprox(self):
warcproxes = self._service_registry.available_services("warcprox")
if not warcproxes:
Expand Down

0 comments on commit b3e08b9

Please sign in to comment.