Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions openviking/service/debug_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def set_dependencies(
self._vikingdb = vikingdb
self._config = config

@property
def _dependencies_ready(self) -> bool:
"""Check if both vikingdb and config dependencies are set."""
return self._vikingdb is not None and self._config is not None

@property
def queue(self) -> ComponentStatus:
"""Get queue status."""
Expand All @@ -87,6 +92,13 @@ def queue(self) -> ComponentStatus:
@property
def vikingdb(self) -> ComponentStatus:
"""Get VikingDB status."""
if self._vikingdb is None:
return ComponentStatus(
name="vikingdb",
is_healthy=False,
has_errors=True,
status="Not initialized",
)
observer = VikingDBObserver(self._vikingdb)
return ComponentStatus(
name="vikingdb",
Expand All @@ -98,6 +110,13 @@ def vikingdb(self) -> ComponentStatus:
@property
def vlm(self) -> ComponentStatus:
"""Get VLM status."""
if self._config is None:
return ComponentStatus(
name="vlm",
is_healthy=False,
has_errors=True,
status="Not initialized",
)
observer = VLMObserver(self._config.vlm.get_vlm_instance())
return ComponentStatus(
name="vlm",
Expand Down Expand Up @@ -143,6 +162,8 @@ def system(self) -> SystemStatus:

def is_healthy(self) -> bool:
"""Quick health check."""
if not self._dependencies_ready:
return False
return self.system.is_healthy


Expand Down
32 changes: 32 additions & 0 deletions tests/misc/test_debug_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,38 @@ def test_is_healthy_returns_true(
status = service.system
assert all(c.is_healthy for name, c in status.components.items() if name != "transaction")

def test_is_healthy_without_dependencies(self):
"""Test is_healthy returns False (not raises) when dependencies not set."""
service = ObserverService()
assert service.is_healthy() is False

def test_vikingdb_property_without_dependency(self):
"""Test vikingdb property returns unhealthy ComponentStatus when vikingdb is None."""
service = ObserverService()
status = service.vikingdb
assert isinstance(status, ComponentStatus)
assert status.name == "vikingdb"
assert status.is_healthy is False
assert status.has_errors is True
assert status.status == "Not initialized"

def test_vlm_property_without_dependency(self):
"""Test vlm property returns unhealthy ComponentStatus when config is None."""
service = ObserverService()
status = service.vlm
assert isinstance(status, ComponentStatus)
assert status.name == "vlm"
assert status.is_healthy is False
assert status.has_errors is True
assert status.status == "Not initialized"

def test_system_property_without_dependencies(self):
"""Test system property returns unhealthy SystemStatus when dependencies not set."""
service = ObserverService()
status = service.system
assert isinstance(status, SystemStatus)
assert status.is_healthy is False

@patch("openviking.service.debug_service.get_queue_manager")
@patch("openviking.service.debug_service.QueueObserver")
@patch("openviking.service.debug_service.VikingDBObserver")
Expand Down
Loading