Skip to content

Commit 277cca3

Browse files
committed
Replaced CustomHandler with HTTPSHandler in instrument server
1 parent b76c121 commit 277cca3

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/murfey/instrument_server/__init__.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ def start_instrument_server():
2525
from rich.logging import RichHandler
2626

2727
import murfey
28-
import murfey.client.websocket
29-
from murfey.client.customlogging import CustomHandler
28+
from murfey.client.customlogging import HTTPSHandler
3029
from murfey.util import LogFilter
30+
from murfey.util.api import url_path_for
31+
from murfey.util.client import read_config
3132

3233
parser = argparse.ArgumentParser(description="Start the Murfey server")
3334
parser.add_argument(
@@ -55,22 +56,21 @@ def start_instrument_server():
5556
logging.getLogger("fastapi").addHandler(rich_handler)
5657
logging.getLogger("uvicorn").addHandler(rich_handler)
5758

58-
# Create a websocket app to connect to the backend
59-
ws = murfey.client.websocket.WSApp(
60-
server=read_config().get("Murfey", "server", fallback=""),
61-
register_client=False,
62-
)
59+
# Construct URL for the HTTPS log handler
60+
client_config = dict(read_config()["Murfey"])
61+
murfey_server_url = client_config["server"].rstrip("/")
62+
logger_url = f"{murfey_server_url}{url_path_for('api.hub.router', 'forward_logs')}"
6363

6464
# Forward DEBUG levels logs and above from Murfey to the backend
65-
murfey_ws_handler = CustomHandler(ws.send)
66-
murfey_ws_handler.setLevel(logging.DEBUG)
67-
logging.getLogger("murfey").addHandler(murfey_ws_handler)
65+
murfey_https_handler = HTTPSHandler(endpoint_url=logger_url)
66+
murfey_https_handler.setLevel(logging.DEBUG)
67+
logging.getLogger("murfey").addHandler(murfey_https_handler)
6868

6969
# Forward only INFO level logs and above for other packages
70-
other_ws_handler = CustomHandler(ws.send)
71-
other_ws_handler.setLevel(logging.INFO)
72-
logging.getLogger("fastapi").addHandler(other_ws_handler)
73-
logging.getLogger("uvicorn").addHandler(other_ws_handler)
70+
other_https_handler = HTTPSHandler(endpoint_url=logger_url)
71+
other_https_handler.setLevel(logging.INFO)
72+
logging.getLogger("fastapi").addHandler(other_https_handler)
73+
logging.getLogger("uvicorn").addHandler(other_https_handler)
7474

7575
logger.info(
7676
f"Starting Murfey server version {murfey.__version__}, listening on {args.host}:{args.port}"

tests/instrument_server/test_init.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,6 @@ def test_start_instrument_server(
142142
# Disable 'run'; we just want to confirm it's called correctly
143143
mock_server.run.return_value = lambda: None
144144

145-
# Patch the websocket instance
146-
mock_wsapp = mocker.patch("murfey.client.websocket.WSApp")
147-
mock_wsapp.return_value = mocker.Mock() # Disable functionality
148-
149145
# Construct the expected Uvicorn Config object and save it as a dict
150146
expected_config = vars(
151147
uvicorn.Config(

0 commit comments

Comments
 (0)