Pull request #19: Prometheus tunneling
Merge in RR/pyinfra from prometheus-tunneling to pika_encapsulation
Squashed commit of the following:
commit 350448ec0f14849844deaa1a86ba4397ab3ebf3c
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Mar 9 16:52:02 2022 +0100
quickfix
commit ee88be4c80abdf597013c743ce2d490ad2b3e029
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Mar 9 15:26:19 2022 +0100
added prometheus endpoint to tunnel metrics from analysis endpoint
This commit is contained in:
parent
21592342d5
commit
08f2746afc
@ -1,11 +1,23 @@
|
||||
"""Implements a config object with dot-indexing syntax."""
|
||||
|
||||
|
||||
from envyaml import EnvYAML
|
||||
|
||||
from pyinfra.locations import CONFIG_FILE
|
||||
|
||||
|
||||
def make_art():
|
||||
return """
|
||||
______ _____ __
|
||||
| ___ \ |_ _| / _|
|
||||
| |_/ / _ | | _ __ | |_ _ __ __ _
|
||||
| __/ | | || || '_ \| _| '__/ _` |
|
||||
| | | |_| || || | | | | | | | (_| |
|
||||
\_| \__, \___/_| |_|_| |_| \__,_|
|
||||
__/ |
|
||||
|___/
|
||||
"""
|
||||
|
||||
|
||||
def _get_item_and_maybe_make_dotindexable(container, item):
|
||||
ret = container[item]
|
||||
return DotIndexable(ret) if isinstance(ret, dict) else ret
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import requests
|
||||
from flask import Flask, jsonify
|
||||
from waitress import serve
|
||||
|
||||
@ -5,7 +6,6 @@ from pyinfra.config import CONFIG
|
||||
|
||||
|
||||
def run_probing_webserver(app, host=None, port=None, mode=None):
|
||||
|
||||
if not host:
|
||||
host = CONFIG.probing_webserver.host
|
||||
|
||||
@ -23,7 +23,6 @@ def run_probing_webserver(app, host=None, port=None, mode=None):
|
||||
|
||||
|
||||
def set_up_probing_webserver():
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/ready", methods=["GET"])
|
||||
@ -38,4 +37,10 @@ def set_up_probing_webserver():
|
||||
resp.status_code = 200
|
||||
return resp
|
||||
|
||||
@app.route("/prometheus", methods=["GET"])
|
||||
def get_analysis_prometheus():
|
||||
prom_endpoint = f"{CONFIG.rabbitmq.callback.analysis_endpoint}/prometheus"
|
||||
metric = requests.get(prom_endpoint)
|
||||
return metric.text
|
||||
|
||||
return app
|
||||
|
||||
@ -2,7 +2,6 @@ import abc
|
||||
|
||||
|
||||
class Connection(abc.ABC):
|
||||
|
||||
@abc.abstractmethod
|
||||
def establish(self):
|
||||
pass
|
||||
pass
|
||||
|
||||
@ -2,6 +2,5 @@ from pyampq.connection.connection import Connection
|
||||
|
||||
|
||||
class MockConnection(Connection):
|
||||
|
||||
def establish(self):
|
||||
pass
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
class PikaConnection:
|
||||
|
||||
def establish(self):
|
||||
pass
|
||||
pass
|
||||
|
||||
@ -43,16 +43,9 @@ def monkey_patch_queue_handle(channel, queue) -> QueueHandle:
|
||||
|
||||
def get_connection():
|
||||
|
||||
credentials = pika.PlainCredentials(
|
||||
username=CONFIG.rabbitmq.user,
|
||||
password=CONFIG.rabbitmq.password
|
||||
)
|
||||
credentials = pika.PlainCredentials(username=CONFIG.rabbitmq.user, password=CONFIG.rabbitmq.password)
|
||||
|
||||
kwargs = {
|
||||
"host": CONFIG.rabbitmq.host,
|
||||
"port": CONFIG.rabbitmq.port,
|
||||
"credentials": credentials
|
||||
}
|
||||
kwargs = {"host": CONFIG.rabbitmq.host, "port": CONFIG.rabbitmq.port, "credentials": credentials}
|
||||
|
||||
parameters = pika.ConnectionParameters(**kwargs)
|
||||
|
||||
@ -62,7 +55,6 @@ def get_connection():
|
||||
|
||||
|
||||
class PikaQueueManager(QueueManager):
|
||||
|
||||
def __init__(self, input_queue, output_queue):
|
||||
super().__init__(input_queue, output_queue)
|
||||
connection = get_connection()
|
||||
|
||||
@ -2,7 +2,6 @@ import abc
|
||||
|
||||
|
||||
class QueueHandle:
|
||||
|
||||
def empty(self) -> bool:
|
||||
raise NotImplemented()
|
||||
|
||||
@ -11,7 +10,6 @@ class QueueHandle:
|
||||
|
||||
|
||||
class QueueManager(abc.ABC):
|
||||
|
||||
def __init__(self, input_queue, output_queue):
|
||||
self._input_queue = input_queue
|
||||
self._output_queue = output_queue
|
||||
|
||||
@ -10,7 +10,6 @@ def monkey_patch_queue_handle(queue) -> QueueHandle:
|
||||
|
||||
|
||||
class QueueManagerMock(QueueManager):
|
||||
|
||||
def __init__(self, input_queue, output_queue):
|
||||
super().__init__(QueueMock(), QueueMock())
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ def consumer(queue_manager, callback):
|
||||
# consumer.consume()
|
||||
# assert queue_manager.output_queue.empty()
|
||||
|
||||
|
||||
def test_consuming_nonempty_input_queue_puts_messages_on_output_queue_in_fifo_order(consumer, queue_manager, callback):
|
||||
queue_manager.clear()
|
||||
queue_manager.publish_request(1)
|
||||
|
||||
@ -8,7 +8,7 @@ from pyinfra.callback import (
|
||||
make_retry_callback,
|
||||
make_callback_for_output_queue,
|
||||
)
|
||||
from pyinfra.config import CONFIG
|
||||
from pyinfra.config import CONFIG, make_art
|
||||
from pyinfra.consume import consume, ConsumerError
|
||||
from pyinfra.core import make_payload_processor, make_storage_data_loader, make_analyzer
|
||||
from pyinfra.flask import run_probing_webserver, set_up_probing_webserver
|
||||
@ -49,6 +49,7 @@ def make_callback():
|
||||
|
||||
def main():
|
||||
# TODO: implement meaningful checks
|
||||
logging.info(make_art())
|
||||
webserver = Process(target=run_probing_webserver, args=(set_up_probing_webserver(),))
|
||||
logging.info("Starting webserver...")
|
||||
webserver.start()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user