feat: add observability api foundation
This commit is contained in:
@@ -385,5 +385,64 @@ pub async fn apply_postgres(pool: &PgPool) -> Result<(), sqlx::Error> {
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
query(
|
||||
"create table if not exists invocation_logs (
|
||||
id text primary key,
|
||||
workspace_id text not null references workspaces(id) on delete cascade,
|
||||
agent_id text null references agents(id) on delete set null,
|
||||
operation_id text not null references operations(id) on delete cascade,
|
||||
source text not null,
|
||||
level text not null,
|
||||
status text not null,
|
||||
tool_name text not null,
|
||||
message text not null,
|
||||
request_id text null,
|
||||
status_code integer null,
|
||||
duration_ms bigint not null,
|
||||
error_kind text null,
|
||||
request_preview_json jsonb not null,
|
||||
response_preview_json jsonb not null,
|
||||
created_at timestamptz not null
|
||||
)",
|
||||
)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
query(
|
||||
"create index if not exists invocation_logs_workspace_created_idx on invocation_logs(workspace_id, created_at desc)",
|
||||
)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
query(
|
||||
"create index if not exists invocation_logs_workspace_operation_created_idx on invocation_logs(workspace_id, operation_id, created_at desc)",
|
||||
)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
query(
|
||||
"create index if not exists invocation_logs_workspace_agent_created_idx on invocation_logs(workspace_id, agent_id, created_at desc)",
|
||||
)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
query(
|
||||
"create table if not exists usage_rollups (
|
||||
workspace_id text not null references workspaces(id) on delete cascade,
|
||||
agent_id text null references agents(id) on delete cascade,
|
||||
operation_id text null references operations(id) on delete cascade,
|
||||
period text not null,
|
||||
calls_total bigint not null,
|
||||
calls_ok bigint not null,
|
||||
calls_error bigint not null,
|
||||
p50_ms bigint not null,
|
||||
p95_ms bigint not null,
|
||||
p99_ms bigint not null,
|
||||
updated_at timestamptz not null
|
||||
)",
|
||||
)
|
||||
.execute(pool)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user