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
62 changes: 14 additions & 48 deletions openviking/storage/observers/queue_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ def __str__(self) -> str:

def _format_status_as_table(self, statuses: Dict[str, QueueStatus]) -> str:
"""
Format queue statuses as a string table.
Format queue statuses as a table using tabulate.

Args:
statuses: Dict mapping queue names to QueueStatus

Returns:
Formatted table string
"""
from tabulate import tabulate

if not statuses:
return "No queue status data available."

Expand All @@ -61,11 +63,11 @@ def _format_status_as_table(self, statuses: Dict[str, QueueStatus]) -> str:
data.append(
{
"Queue": queue_name,
"Pending": str(status.pending),
"In Progress": str(status.in_progress),
"Processed": str(status.processed),
"Errors": str(status.error_count),
"Total": str(total),
"Pending": status.pending,
"In Progress": status.in_progress,
"Processed": status.processed,
"Errors": status.error_count,
"Total": total,
}
)
total_pending += status.pending
Expand All @@ -78,51 +80,15 @@ def _format_status_as_table(self, statuses: Dict[str, QueueStatus]) -> str:
data.append(
{
"Queue": "TOTAL",
"Pending": str(total_pending),
"In Progress": str(total_in_progress),
"Processed": str(total_processed),
"Errors": str(total_errors),
"Total": str(total_total),
"Pending": total_pending,
"In Progress": total_in_progress,
"Processed": total_processed,
"Errors": total_errors,
"Total": total_total,
}
)

# Simple table formatter
headers = ["Queue", "Pending", "In Progress", "Processed", "Errors", "Total"]
# Default minimum widths similar to previous col_space
min_widths = {
"Queue": 20,
"Pending": 10,
"In Progress": 12,
"Processed": 10,
"Errors": 8,
"Total": 10,
}

col_widths = {h: len(h) for h in headers}

# Calculate max width based on content and min_widths
for row in data:
for h in headers:
content_len = len(str(row.get(h, "")))
col_widths[h] = max(col_widths[h], content_len, min_widths.get(h, 0))

# Add padding
for h in headers:
col_widths[h] += 2

# Build string
lines = []

# Header
header_line = "".join(h.ljust(col_widths[h]) for h in headers)
lines.append(header_line)

# Rows
for row in data:
line = "".join(str(row.get(h, "")).ljust(col_widths[h]) for h in headers)
lines.append(line)

return "\n".join(lines)
return tabulate(data, headers="keys", tablefmt="pretty")

def is_healthy(self) -> bool:
return not self.has_errors()
Expand Down
36 changes: 7 additions & 29 deletions openviking/storage/observers/vikingdb_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ async def _get_collection_statuses(self, collection_names: list) -> Dict[str, Di
return statuses

def _format_status_as_table(self, statuses: Dict[str, Dict]) -> str:
from tabulate import tabulate

data = []
total_indexes = 0
total_vectors = 0
Expand All @@ -90,8 +92,8 @@ def _format_status_as_table(self, statuses: Dict[str, Dict]) -> str:
data.append(
{
"Collection": name,
"Index Count": str(index_count),
"Vector Count": str(vector_count),
"Index Count": index_count,
"Vector Count": vector_count,
"Status": "ERROR" if error else "OK",
}
)
Expand All @@ -105,37 +107,13 @@ def _format_status_as_table(self, statuses: Dict[str, Dict]) -> str:
data.append(
{
"Collection": "TOTAL",
"Index Count": str(total_indexes),
"Vector Count": str(total_vectors),
"Index Count": total_indexes,
"Vector Count": total_vectors,
"Status": "",
}
)

# Simple table formatter
headers = ["Collection", "Index Count", "Vector Count", "Status"]
col_widths = {h: len(h) for h in headers}

for row in data:
for h in headers:
col_widths[h] = max(col_widths[h], len(str(row.get(h, ""))))

# Add padding
for h in headers:
col_widths[h] += 2

# Build string
lines = []

# Header
header_line = "".join(h.ljust(col_widths[h]) for h in headers)
lines.append(header_line)

# Rows
for row in data:
line = "".join(str(row.get(h, "")).ljust(col_widths[h]) for h in headers)
lines.append(line)

return "\n".join(lines)
return tabulate(data, headers="keys", tablefmt="pretty")

def is_healthy(self) -> bool:
"""
Expand Down
57 changes: 11 additions & 46 deletions openviking/storage/observers/vlm_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ def get_status_table(self) -> str:

def _format_status_as_table(self) -> str:
"""
Format token usage status as a string table.
Format token usage status as a table using tabulate.

Returns:
Formatted table string representation of token usage
"""
from tabulate import tabulate

usage_data = self._vlm_instance.get_token_usage()

if not usage_data.get("usage_by_model"):
Expand All @@ -61,10 +63,10 @@ def _format_status_as_table(self) -> str:
{
"Model": model_name,
"Provider": provider_name,
"Prompt": str(provider_data["prompt_tokens"]),
"Completion": str(provider_data["completion_tokens"]),
"Total": str(provider_data["total_tokens"]),
"Last Updated": str(provider_data["last_updated"]),
"Prompt": provider_data["prompt_tokens"],
"Completion": provider_data["completion_tokens"],
"Total": provider_data["total_tokens"],
"Last Updated": provider_data["last_updated"],
}
)
total_prompt += provider_data["prompt_tokens"]
Expand All @@ -79,51 +81,14 @@ def _format_status_as_table(self) -> str:
{
"Model": "TOTAL",
"Provider": "",
"Prompt": str(total_prompt),
"Completion": str(total_completion),
"Total": str(total_all),
"Prompt": total_prompt,
"Completion": total_completion,
"Total": total_all,
"Last Updated": "",
}
)

# Simple table formatter
headers = ["Model", "Provider", "Prompt", "Completion", "Total", "Last Updated"]

# Default minimum widths similar to previous col_space
min_widths = {
"Model": 30,
"Provider": 12,
"Prompt": 12,
"Completion": 12,
"Total": 12,
"Last Updated": 20,
}

col_widths = {h: len(h) for h in headers}

# Calculate max width based on content and min_widths
for row in data:
for h in headers:
content_len = len(str(row.get(h, "")))
col_widths[h] = max(col_widths[h], content_len, min_widths.get(h, 0))

# Add padding
for h in headers:
col_widths[h] += 2

# Build string
lines = []

# Header
header_line = "".join(h.ljust(col_widths[h]) for h in headers)
lines.append(header_line)

# Rows
for row in data:
line = "".join(str(row.get(h, "")).ljust(col_widths[h]) for h in headers)
lines.append(line)

return "\n".join(lines)
return tabulate(data, headers="keys", tablefmt="pretty")

def __str__(self) -> str:
return self.get_status_table()
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies = [
"xxhash>=3.0.0",
"jinja2>=3.1.6",
"nest-asyncio>=1.5.0",
"tabulate>=0.9.0",
]

[project.optional-dependencies]
Expand Down
11 changes: 11 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading