-
Notifications
You must be signed in to change notification settings - Fork 0
feat(settings): route structural data reads through SettingsService #525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7e2393d
730efa5
97ec9bf
534667b
52d626a
9e6f646
4dbfdda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| """Analytics controller — derived read-only metrics.""" | ||
|
|
||
| import asyncio | ||
| from collections import Counter | ||
|
|
||
| from litestar import Controller, get | ||
|
|
@@ -11,6 +12,7 @@ | |
| from synthorg.api.state import AppState # noqa: TC001 | ||
| from synthorg.core.enums import TaskStatus | ||
| from synthorg.observability import get_logger | ||
| from synthorg.observability.events.api import API_REQUEST_ERROR | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
@@ -56,17 +58,29 @@ async def get_overview( | |
| """ | ||
| app_state: AppState = state.app_state | ||
|
|
||
| all_tasks = await app_state.persistence.tasks.list_tasks() | ||
| try: | ||
| async with asyncio.TaskGroup() as tg: | ||
| t_tasks = tg.create_task(app_state.persistence.tasks.list_tasks()) | ||
| t_cost = tg.create_task(app_state.cost_tracker.get_total_cost()) | ||
| t_agents = tg.create_task(app_state.config_resolver.get_agents()) | ||
| except ExceptionGroup as eg: | ||
| logger.warning( | ||
| API_REQUEST_ERROR, | ||
| endpoint="analytics.overview", | ||
| error_count=len(eg.exceptions), | ||
| exc_info=True, | ||
| ) | ||
| raise eg.exceptions[0] from eg | ||
|
Comment on lines
+61
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't emit This group wraps Based on learnings, "Settings namespaces: api, company, providers, memory, budget, security, coordination, observability, backup". 🤖 Prompt for AI Agents |
||
|
|
||
| all_tasks = t_tasks.result() | ||
| counts = Counter(t.status.value for t in all_tasks) | ||
| by_status = {s.value: counts.get(s.value, 0) for s in TaskStatus} | ||
|
|
||
| total_cost = await app_state.cost_tracker.get_total_cost() | ||
|
|
||
| return ApiResponse( | ||
| data=OverviewMetrics( | ||
| total_tasks=len(all_tasks), | ||
| tasks_by_status=by_status, | ||
| total_agents=len(app_state.config.agents), | ||
| total_cost_usd=total_cost, | ||
| total_agents=len(t_agents.result()), | ||
| total_cost_usd=t_cost.result(), | ||
| ), | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.