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
14 changes: 7 additions & 7 deletions docs/en/api/07-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Get system status including initialization state and user info.
**Python SDK (Embedded / HTTP)**

```python
print(client.observer.system)
print(client.observer.system())
```

**HTTP API**
Expand Down Expand Up @@ -204,16 +204,16 @@ Get VikingDB status (collections, indexes, vector counts).
**Python SDK (Embedded / HTTP)**

```python
print(client.observer.vikingdb)
print(client.observer.vikingdb())
# Output:
# [vikingdb] (healthy)
# Collection Index Count Vector Count Status
# context 1 55 OK
# TOTAL 1 55

# Access specific properties
print(client.observer.vikingdb.is_healthy) # True
print(client.observer.vikingdb.status) # Status table string
# Access specific attributes
print(client.observer.vikingdb().is_healthy) # True
print(client.observer.vikingdb().status) # Status table string
```

**HTTP API**
Expand Down Expand Up @@ -306,7 +306,7 @@ Get overall system status including all components.
**Python SDK (Embedded / HTTP)**

```python
print(client.observer.system)
print(client.observer.system())
# Output:
# [queue] (healthy)
# ...
Expand Down Expand Up @@ -382,7 +382,7 @@ Quick health check for the entire system.
if client.observer.is_healthy():
print("System OK")
else:
print(client.observer.system)
print(client.observer.system())
```

**HTTP API**
Expand Down
12 changes: 6 additions & 6 deletions docs/zh/api/07-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ openviking health
**Python SDK (Embedded / HTTP)**

```python
print(client.observer.system)
print(client.observer.system())
```

**HTTP API**
Expand Down Expand Up @@ -204,16 +204,16 @@ openviking observer queue
**Python SDK (Embedded / HTTP)**

```python
print(client.observer.vikingdb)
print(client.observer.vikingdb())
# Output:
# [vikingdb] (healthy)
# Collection Index Count Vector Count Status
# context 1 55 OK
# TOTAL 1 55

# 访问特定属性
print(client.observer.vikingdb.is_healthy) # True
print(client.observer.vikingdb.status) # Status table string
print(client.observer.vikingdb().is_healthy) # True
print(client.observer.vikingdb().status) # Status table string
```

**HTTP API**
Expand Down Expand Up @@ -306,7 +306,7 @@ openviking observer vlm
**Python SDK (Embedded / HTTP)**

```python
print(client.observer.system)
print(client.observer.system())
# Output:
# [queue] (healthy)
# ...
Expand Down Expand Up @@ -382,7 +382,7 @@ openviking observer system
if client.observer.is_healthy():
print("System OK")
else:
print(client.observer.system)
print(client.observer.system())
```

**HTTP API**
Expand Down
2 changes: 1 addition & 1 deletion openviking/client/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def get_status(self) -> Any:
Returns:
SystemStatus containing health status of all components.
"""
return self._service.debug.observer.system
return self._service.debug.observer.system()

def is_healthy(self) -> bool:
"""Quick health check (synchronous).
Expand Down
8 changes: 4 additions & 4 deletions openviking/server/routers/observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ async def observer_queue(

@router.get("/vikingdb")
async def observer_vikingdb(
_ctx: RequestContext = Depends(get_request_context),
ctx: RequestContext = Depends(get_request_context),
):
"""Get VikingDB status."""
service = get_service()
component = service.debug.observer.vikingdb
component = service.debug.observer.vikingdb(ctx=ctx)
return Response(status="ok", result=_component_to_dict(component))


Expand Down Expand Up @@ -94,9 +94,9 @@ async def observer_retrieval(

@router.get("/system")
async def observer_system(
_ctx: RequestContext = Depends(get_request_context),
ctx: RequestContext = Depends(get_request_context),
):
"""Get system overall status (includes all components)."""
service = get_service()
status = service.debug.observer.system
status = service.debug.observer.system(ctx=ctx)
return Response(status="ok", result=_system_to_dict(status))
13 changes: 6 additions & 7 deletions openviking/service/debug_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dataclasses import dataclass
from typing import Dict, List, Optional

from openviking.server.identity import RequestContext
from openviking.storage import VikingDBManager
from openviking.storage.observers import (
LockObserver,
Expand Down Expand Up @@ -99,8 +100,7 @@ def queue(self) -> ComponentStatus:
status=observer.get_status_table(),
)

@property
def vikingdb(self) -> ComponentStatus:
def vikingdb(self, ctx: Optional[RequestContext] = None) -> ComponentStatus:
"""Get VikingDB status."""
if self._vikingdb is None:
return ComponentStatus(
Expand All @@ -114,7 +114,7 @@ def vikingdb(self) -> ComponentStatus:
name="vikingdb",
is_healthy=observer.is_healthy(),
has_errors=observer.has_errors(),
status=observer.get_status_table(),
status=observer.get_status_table(ctx=ctx),
)

@property
Expand Down Expand Up @@ -166,12 +166,11 @@ def retrieval(self) -> ComponentStatus:
status=observer.get_status_table(),
)

@property
def system(self) -> SystemStatus:
def system(self, ctx: Optional[RequestContext] = None) -> SystemStatus:
"""Get system overall status."""
components = {
"queue": self.queue,
"vikingdb": self.vikingdb,
"vikingdb": self.vikingdb(ctx=ctx),
"vlm": self.vlm,
"lock": self.lock,
"retrieval": self.retrieval,
Expand All @@ -187,7 +186,7 @@ def is_healthy(self) -> bool:
"""Quick health check."""
if not self._dependencies_ready:
return False
return self.system.is_healthy
return self.system().is_healthy


class DebugService:
Expand Down
2 changes: 1 addition & 1 deletion openviking/storage/observers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Monitors VikingDB collection status (index count and vector count per collection
import openviking as ov

client = ov.OpenViking(path="./data")
print(client.observer.vikingdb)
print(client.observer.vikingdb())
# Output:
# Collection Index Count Vector Count Status
# context 1 69 OK
Expand Down
19 changes: 12 additions & 7 deletions openviking/storage/observers/vikingdb_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
Provides methods to observe and report VikingDB collection status.
"""

from typing import Dict
from typing import Dict, Optional

from openviking.server.identity import RequestContext
from openviking.storage.observers.base_observer import BaseObserver
from openviking.storage.vikingdb_manager import VikingDBManager
from openviking_cli.utils import run_async
Expand All @@ -26,23 +27,27 @@ class VikingDBObserver(BaseObserver):
def __init__(self, vikingdb_manager: VikingDBManager):
self._vikingdb_manager = vikingdb_manager

async def get_status_table_async(self) -> str:
async def get_status_table_async(self, ctx: Optional[RequestContext] = None) -> str:
if not self._vikingdb_manager:
return "VikingDB manager not initialized."

if not await self._vikingdb_manager.collection_exists():
return "No collections found."

statuses = await self._get_collection_statuses([self._vikingdb_manager.collection_name])
statuses = await self._get_collection_statuses(
[self._vikingdb_manager.collection_name], ctx=ctx
)
return self._format_status_as_table(statuses)

def get_status_table(self) -> str:
return run_async(self.get_status_table_async())
def get_status_table(self, ctx: Optional[RequestContext] = None) -> str:
return run_async(self.get_status_table_async(ctx=ctx))

def __str__(self) -> str:
return self.get_status_table()

async def _get_collection_statuses(self, collection_names: list) -> Dict[str, Dict]:
async def _get_collection_statuses(
self, collection_names: list, *, ctx: Optional[RequestContext] = None
) -> Dict[str, Dict]:
statuses = {}

for name in collection_names:
Expand All @@ -52,7 +57,7 @@ async def _get_collection_statuses(self, collection_names: list) -> Dict[str, Di

# Current OpenViking flow uses one managed default index per collection.
index_count = 1
vector_count = await self._vikingdb_manager.count()
vector_count = await self._vikingdb_manager.count(ctx=ctx)

statuses[name] = {
"index_count": index_count,
Expand Down
12 changes: 6 additions & 6 deletions tests/misc/test_debug_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_vikingdb_property(self, mock_observer_cls):
mock_observer_cls.return_value = mock_observer

service = ObserverService(vikingdb=mock_vikingdb)
status = service.vikingdb
status = service.vikingdb()

assert isinstance(status, ComponentStatus)
assert status.name == "vikingdb"
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_system_property_all_healthy(

mock_config = MagicMock()
service = ObserverService(vikingdb=MagicMock(), config=mock_config)
status = service.system
status = service.system()

assert isinstance(status, SystemStatus)
for name in ("queue", "vikingdb", "vlm"):
Expand Down Expand Up @@ -255,7 +255,7 @@ def test_system_property_with_errors(

mock_config = MagicMock()
service = ObserverService(vikingdb=MagicMock(), config=mock_config)
status = service.system
status = service.system()

assert isinstance(status, SystemStatus)
assert status.is_healthy is False
Expand All @@ -281,7 +281,7 @@ def test_is_healthy_returns_true(

mock_config = MagicMock()
service = ObserverService(vikingdb=MagicMock(), config=mock_config)
status = service.system
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):
Expand All @@ -292,7 +292,7 @@ def test_is_healthy_without_dependencies(self):
def test_vikingdb_property_without_dependency(self):
"""Test vikingdb property returns unhealthy ComponentStatus when vikingdb is None."""
service = ObserverService()
status = service.vikingdb
status = service.vikingdb()
assert isinstance(status, ComponentStatus)
assert status.name == "vikingdb"
assert status.is_healthy is False
Expand All @@ -312,7 +312,7 @@ def test_vlm_property_without_dependency(self):
def test_system_property_without_dependencies(self):
"""Test system property returns unhealthy SystemStatus when dependencies not set."""
service = ObserverService()
status = service.system
status = service.system()
assert isinstance(status, SystemStatus)
assert status.is_healthy is False

Expand Down
6 changes: 3 additions & 3 deletions tests/misc/test_vikingdb_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def test_vikingdb_observer():

# Test VikingDBObserver
print("\n4. Test VikingDBObserver:")
vikingdb_status = client.observer.vikingdb
vikingdb_status = client.observer.vikingdb()
print(f"Type: {type(vikingdb_status)}")
print(f"Is healthy: {vikingdb_status.is_healthy}")
print(f"Has errors: {vikingdb_status.has_errors}")
Expand All @@ -58,7 +58,7 @@ async def test_vikingdb_observer():

# Test system status
print("\n7. Test system status:")
system_status = client.observer.system
system_status = client.observer.system()
print(f"System is_healthy: {system_status.is_healthy}")
for name, component in system_status.components.items():
print(f"\n{name}:")
Expand Down Expand Up @@ -102,7 +102,7 @@ async def test_sync_client():

# Test VikingDBObserver
print("\nVikingDBObserver status:")
print(client.observer.vikingdb)
print(client.observer.vikingdb())

print("\n=== Sync client test completed ===")

Expand Down
Loading