diff --git a/src/QAT_RPC/qat_rpc/utils/metrics.py b/src/QAT_RPC/qat_rpc/utils/metrics.py index 594e547..863290c 100644 --- a/src/QAT_RPC/qat_rpc/utils/metrics.py +++ b/src/QAT_RPC/qat_rpc/utils/metrics.py @@ -84,10 +84,7 @@ def hardware_reloaded(self, outcome: BinaryMutableOutcome): ... class PrometheusReceiver(ReceiverBackend): - def __init__( - self, - port: int = PROMETHEUS_PORT - ): + def __init__(self, port: int = PROMETHEUS_PORT): super(PrometheusReceiver, self).__init__() start_http_server(port) log.info(f"Starting Prometheus metrics exporter on port {port}.") diff --git a/src/QAT_RPC/qat_rpc/zmq/receiver.py b/src/QAT_RPC/qat_rpc/zmq/receiver.py index ab876ba..eb550f1 100644 --- a/src/QAT_RPC/qat_rpc/zmq/receiver.py +++ b/src/QAT_RPC/qat_rpc/zmq/receiver.py @@ -40,7 +40,9 @@ def main(): else: try: if not (1024 < int(receiver_port) < 49152): - raise ValueError("Receiver must be configured to run on a valid port number between 1024 and 49152.") + raise ValueError( + "Receiver must be configured to run on a valid port number between 1024 and 49152." + ) log.info(f"Receiver server is configured to start on port {receiver_port}.") except ValueError as e: log.warning(f"{e}") @@ -48,7 +50,7 @@ def main(): log.info(f"Defaulting receiver to run on port {receiver_port}.") else: receiver_port = 5556 - + if metrics_port is not None: try: int(metrics_port) @@ -57,11 +59,15 @@ def main(): metrics_port = PROMETHEUS_PORT log.info(f"Defaulting metrics exporter to run on port {metrics_port}") else: - try: - if (int(metrics_port) == int(receiver_port)): - raise ValueError(f"Metrics exporter cannot run on port {metrics_port}, it must be set to a different value to the receiver port.") + try: + if int(metrics_port) == int(receiver_port): + raise ValueError( + f"Metrics exporter cannot run on port {metrics_port}, it must be set to a different value to the receiver port." + ) elif not (1024 < int(metrics_port) < 49152): - raise ValueError("Metrics exporter must be configured to run on a valid port number between 1024 and 49152.") + raise ValueError( + "Metrics exporter must be configured to run on a valid port number between 1024 and 49152." + ) log.info(f"Metrics exporter is configured to start on port {metrics_port}.") except ValueError as e: log.warning(f"{e}") @@ -69,16 +75,20 @@ def main(): log.info(f"Defaulting metrics exporter to run on port {metrics_port}.") else: metrics_port = PROMETHEUS_PORT - + try: if int(metrics_port) == int(receiver_port): raise ValueError except ValueError: - log.warning("The receiver and metrics exporter have been configured to run on the same port.") + log.warning( + "The receiver and metrics exporter have been configured to run on the same port." + ) receiver_port = 5556 metrics_port = PROMETHEUS_PORT - log.info(f"Defaulting receiver to run on port {receiver_port} and metrics exporter to run on port {metrics_port}.") - + log.info( + f"Defaulting receiver to run on port {receiver_port} and metrics exporter to run on port {metrics_port}." + ) + metric_exporter = MetricExporter(backend=PrometheusReceiver(port=int(metrics_port))) if (calibration_file := os.getenv("TOSHIKO_CAL")) is not None: @@ -91,10 +101,14 @@ def main(): hw = Calibratable.load_calibration_from_file(str(calibration_file)) log.debug("Loaded") - receiver = ZMQServer(hardware=hw, server_port=receiver_port, metric_exporter=metric_exporter) + receiver = ZMQServer( + hardware=hw, server_port=receiver_port, metric_exporter=metric_exporter + ) gk = GracefulKill(receiver) - log.info(f"Starting QAT receiver on port {str(receiver._port)} with {type(receiver._hardware)} hardware.") + log.info( + f"Starting QAT receiver on port {str(receiver._port)} with {type(receiver._hardware)} hardware." + ) receiver.run() diff --git a/src/QAT_RPC/qat_rpc/zmq/wrappers.py b/src/QAT_RPC/qat_rpc/zmq/wrappers.py index 168a081..5918c4b 100644 --- a/src/QAT_RPC/qat_rpc/zmq/wrappers.py +++ b/src/QAT_RPC/qat_rpc/zmq/wrappers.py @@ -24,10 +24,7 @@ class Messages(Enum): class ZMQBase: def __init__( - self, - socket_type: zmq.SocketType, - ip_address: str = "127.0.0.1", - port: str = "5556" + self, socket_type: zmq.SocketType, ip_address: str = "127.0.0.1", port: str = "5556" ): self._context = zmq.Context() self._socket = self._context.socket(socket_type) @@ -77,7 +74,7 @@ def __init__( self, hardware: Optional[QuantumHardwareModel] = None, server_port: Optional[str] = None, - metric_exporter: Optional[MetricExporter] = None + metric_exporter: Optional[MetricExporter] = None, ): super().__init__(socket_type=zmq.REP, port=server_port) self._metric = metric_exporter @@ -161,11 +158,7 @@ def stop(self): class ZMQClient(ZMQBase): - def __init__( - self, - client_ip: Optional[str] = None, - client_port: Optional[str] = None - ): + def __init__(self, client_ip: Optional[str] = None, client_port: Optional[str] = None): super().__init__(socket_type=zmq.REQ, ip_address=client_ip, port=client_port) self._socket.setsockopt(zmq.LINGER, 0) self._socket.connect(self.address)