Skip to content

Commit e15b90d

Browse files
committed
wip:core:services: Send standard events
1 parent e864db0 commit e15b90d

File tree

17 files changed

+105
-6
lines changed

17 files changed

+105
-6
lines changed

core/services/ardupilot_manager/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from args import CommandLineArgs
66
from autopilot_manager import AutoPilotManager
7+
from commonwealth.utils.events import events
78
from commonwealth.utils.general import is_running_as_root
89
from commonwealth.utils.logs import InterceptHandler, init_logger
910
from commonwealth.utils.sentry_config import init_sentry_async
@@ -14,6 +15,7 @@
1415

1516
logging.basicConfig(handlers=[InterceptHandler()], level=0)
1617
init_logger(SERVICE_NAME)
18+
events.publish_start()
1719

1820
logger.info("Starting AutoPilot Manager.")
1921
autopilot = AutoPilotManager()
@@ -46,6 +48,16 @@ async def main() -> None:
4648
asyncio.create_task(autopilot.auto_restart_ardupilot())
4749
asyncio.create_task(autopilot.start_mavlink_manager_watchdog())
4850

51+
# Publish running event when service is ready
52+
events.publish_running()
53+
events.publish_health(
54+
"ready",
55+
{
56+
"endpoint": f"{args.host}:{args.port}",
57+
"sitl": args.sitl,
58+
},
59+
)
60+
4961
await server.serve()
5062
await autopilot.kill_ardupilot()
5163

core/services/ardupilot_manager/mavlink_proxy/MAVLinkServer.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,19 @@ def convert_endpoint(endpoint: Endpoint) -> str:
4444
filtered_endpoints = Endpoint.filter_enabled(self.endpoints())
4545
endpoints = " ".join([convert_endpoint(endpoint) for endpoint in [master_endpoint, *filtered_endpoints]])
4646

47-
if not self.log_path:
48-
self.log_path = "/var/logs/blueos/services/mavlink-server/"
4947
if not self.mavlink_system_id:
5048
self.mavlink_system_id = int(os.environ.get("MAV_SYSTEM_ID", 1))
5149
if not self.mavlink_component_id:
5250
self.mavlink_component_id = int(os.environ.get("MAV_COMPONENT_ID_ONBOARD_COMPUTER", 191))
5351

54-
return f"{self.binary()} {endpoints} --mavlink-system-id={self.mavlink_system_id} --mavlink-component-id={self.mavlink_component_id} --log-path={self.log_path}"
52+
command = (
53+
f"{self.binary()} {endpoints}"
54+
f" --mavlink-system-id={self.mavlink_system_id}"
55+
f" --mavlink-component-id={self.mavlink_component_id}"
56+
)
57+
if self.log_path:
58+
command += f" --log-path={self.log_path}"
59+
return command
5560

5661
@staticmethod
5762
def name() -> str:

core/services/bag_of_holding/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import appdirs
99
import dpath
1010
from commonwealth.utils.apis import GenericErrorHandlingRoute
11+
from commonwealth.utils.events import events
1112
from commonwealth.utils.logs import InterceptHandler, init_logger
1213
from commonwealth.utils.sentry_config import init_sentry_async
1314
from fastapi import Body, FastAPI, HTTPException
@@ -23,6 +24,7 @@
2324

2425
logging.basicConfig(handlers=[InterceptHandler()], level=0)
2526
init_logger(SERVICE_NAME)
27+
events.publish_start()
2628

2729
app = FastAPI(
2830
title="Bag of Holding API",
@@ -117,6 +119,10 @@ async def main() -> None:
117119
config = Config(app=app, host="0.0.0.0", port=9101, log_config=None)
118120
server = Server(config)
119121

122+
# Publish running event when service is ready
123+
events.publish_running()
124+
events.publish_health("ready", {"port": 9101})
125+
120126
await server.serve()
121127

122128

core/services/beacon/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import psutil
1111
from commonwealth.settings.manager import Manager
1212
from commonwealth.utils.apis import PrettyJSONResponse
13+
from commonwealth.utils.events import events
1314
from commonwealth.utils.logs import init_logger
1415
from commonwealth.utils.sentry_config import init_sentry_async
1516
from fastapi import FastAPI, Request
@@ -24,7 +25,6 @@
2425

2526
SERVICE_NAME = "beacon"
2627

27-
2828
class AsyncRunner:
2929
def __init__(self, ip_version: IPVersion, interface: str, interface_name: str) -> None:
3030
self.ip_version = ip_version
@@ -266,6 +266,7 @@ async def stop(self) -> None:
266266

267267
logging.basicConfig(level=logging.DEBUG)
268268
init_logger(SERVICE_NAME)
269+
events.publish_start()
269270

270271
app = FastAPI(
271272
title="Beacon API",
@@ -348,6 +349,10 @@ async def main() -> None:
348349
config = Config(app=app, host="0.0.0.0", port=9111, log_config=None)
349350
server = Server(config)
350351

352+
# Publish running event when service is ready
353+
events.publish_running()
354+
events.publish_health("ready", {"port": 9111})
355+
351356
asyncio.create_task(beacon.run())
352357
await server.serve()
353358
await beacon.stop()

core/services/bridget/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from bridget import BridgeFrontendSpec, Bridget
77
from commonwealth.utils.apis import GenericErrorHandlingRoute, PrettyJSONResponse
8+
from commonwealth.utils.events import events
89
from commonwealth.utils.logs import InterceptHandler, init_logger
910
from commonwealth.utils.sentry_config import init_sentry_async
1011
from fastapi import FastAPI, status
@@ -17,6 +18,7 @@
1718

1819
logging.basicConfig(handlers=[InterceptHandler()], level=0)
1920
init_logger(SERVICE_NAME)
21+
events.publish_start()
2022

2123
app = FastAPI(
2224
title="Bridget API",
@@ -83,6 +85,10 @@ async def main() -> None:
8385
config = Config(app=app, host="0.0.0.0", port=27353, log_config=None)
8486
server = Server(config)
8587

88+
# Publish running event when service is ready
89+
events.publish_running()
90+
events.publish_health("ready", {"port": 27353})
91+
8692
await server.serve()
8793

8894

core/services/cable_guy/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from commonwealth.utils.apis import GenericErrorHandlingRoute, PrettyJSONResponse
1111
from commonwealth.utils.decorators import temporary_cache
1212
from commonwealth.utils.DHCPServerManager import DHCPServerDetails, DHCPServerLease
13+
from commonwealth.utils.events import events
1314
from commonwealth.utils.logs import InterceptHandler, init_logger
1415
from commonwealth.utils.sentry_config import init_sentry_async
1516
from config import SERVICE_NAME
@@ -22,6 +23,7 @@
2223

2324
logging.basicConfig(handlers=[InterceptHandler()], level=0)
2425
init_logger(SERVICE_NAME)
26+
events.publish_start()
2527

2628
manager = EthernetManager()
2729

@@ -186,6 +188,10 @@ async def main() -> None:
186188
await manager.initialize()
187189
asyncio.create_task(manager.watchdog())
188190

191+
# Publish running event when service is ready
192+
events.publish_running()
193+
events.publish_health("ready", {"port": 9090})
194+
189195
await server.serve()
190196

191197

core/services/commander/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import appdirs
1313
from commonwealth.utils.apis import GenericErrorHandlingRoute
1414
from commonwealth.utils.commands import run_command
15+
from commonwealth.utils.events import events
1516
from commonwealth.utils.general import delete_everything, delete_everything_stream
1617
from commonwealth.utils.logs import InterceptHandler, init_logger
1718
from commonwealth.utils.sentry_config import init_sentry_async
@@ -23,11 +24,12 @@
2324
from uvicorn import Config, Server
2425

2526
SERVICE_NAME = "commander"
26-
LOG_FOLDER_PATH = os.environ.get("BLUEOS_LOG_FOLDER_PATH", "/var/logs/blueos")
27+
LOG_FOLDER_PATH = os.environ.get("BLUEOS_LOG_FOLDER_PATH", "/usr/blueos/system_logs")
2728
MAVLINK_LOG_FOLDER_PATH = os.environ.get("BLUEOS_MAVLINK_LOG_FOLDER_PATH", "/shortcuts/ardupilot_logs/logs/")
2829

2930
logging.basicConfig(handlers=[InterceptHandler()], level=0)
3031
init_logger(SERVICE_NAME)
32+
events.publish_start()
3133

3234
app = FastAPI(
3335
title="Commander API",
@@ -298,6 +300,11 @@ async def main() -> None:
298300
# Running uvicorn with log disabled so loguru can handle it
299301
config = Config(app=app, host="0.0.0.0", port=9100, log_config=None)
300302
server = Server(config)
303+
304+
# Publish running event when service is ready
305+
events.publish_running()
306+
events.publish_health("ready", {"port": 9100})
307+
301308
await server.serve()
302309

303310

core/services/disk_usage/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from typing import Any, Dict, List, Optional
1313

1414
from commonwealth.utils.apis import GenericErrorHandlingRoute, PrettyJSONResponse
15+
from commonwealth.utils.events import events
1516
from commonwealth.utils.logs import InterceptHandler, init_logger
1617
from commonwealth.utils.sentry_config import init_sentry_async
1718
from fastapi import APIRouter, FastAPI, HTTPException, Query, status
@@ -28,6 +29,7 @@
2829

2930
logging.basicConfig(handlers=[InterceptHandler()], level=logging.DEBUG)
3031
init_logger(SERVICE_NAME)
32+
events.publish_start()
3133
logger.info("Starting Disk Usage service")
3234

3335

@@ -436,6 +438,8 @@ async def main() -> None:
436438
config = Config(app=app, host="0.0.0.0", port=PORT, log_config=None)
437439
server = Server(config)
438440

441+
events.publish_running()
442+
events.publish_health("ready", {"port": PORT})
439443
await server.serve()
440444
finally:
441445
logger.info("Disk Usage service stopped")

core/services/helper/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
local_hardware_identifier,
3131
local_unique_identifier,
3232
)
33+
from commonwealth.utils.events import events
3334
from commonwealth.utils.logs import InterceptHandler, init_logger
3435
from commonwealth.utils.sentry_config import init_sentry_async
3536
from fastapi import FastAPI, HTTPException
@@ -45,6 +46,7 @@
4546
logging.basicConfig(handlers=[InterceptHandler()], level=logging.DEBUG)
4647
try:
4748
init_logger(SERVICE_NAME)
49+
events.publish_start()
4850
except Exception as logger_e:
4951
print(f"Error: unable to set logger path: {logger_e}")
5052

@@ -626,6 +628,10 @@ async def main() -> None:
626628
config = Config(app=app, host="0.0.0.0", port=Helper.PORT, log_config=None)
627629
server = Server(config)
628630

631+
# Publish running event when service is ready
632+
events.publish_running()
633+
events.publish_health("ready", {"port": Helper.PORT})
634+
629635
asyncio.create_task(periodic())
630636

631637
await server.serve()

core/services/kraken/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
import logging
44

55
from args import CommandLineArgs
6+
from commonwealth.utils.events import events
67
from commonwealth.utils.logs import InterceptHandler, init_logger
78
from commonwealth.utils.sentry_config import init_sentry_async
89
from config import SERVICE_NAME
910
from loguru import logger
1011
from uvicorn import Config, Server
1112

13+
from args import CommandLineArgs
14+
from config import SERVICE_NAME
15+
1216
logging.basicConfig(handlers=[InterceptHandler()], level=0)
1317
init_logger(SERVICE_NAME)
18+
events.publish_start()
1419

1520
from api import application
1621
from jobs import JobsManager
@@ -35,6 +40,10 @@ async def main() -> None:
3540

3641
jobs.set_base_host(f"http://{args.host}:{args.port}")
3742

43+
# Publish running event when service is ready
44+
events.publish_running()
45+
events.publish_health("ready", {"endpoint": f"{args.host}:{args.port}"})
46+
3847
# Launch background tasks
3948
asyncio.create_task(kraken.start_cleaner_task())
4049
asyncio.create_task(kraken.start_starter_task())

0 commit comments

Comments
 (0)