Add DuoToolCalls aggregation engine for Duo Chat tool call events
Related to #633445 (closed)
Split out of !263296 (merged) at review request. This MR adds the engine, its specs and the development fixture. The GraphQL exposure (type mount, authz entries, request spec, regenerated docs) stays in !263296 (merged), which is stacked on this branch.
What does this MR do?
Adds a ClickHouse aggregation engine, Analytics::AggregationEngines::DuoToolCalls, over the ai_usage_events table. It covers only the two Duo Chat tool call events: tool_succeeded_duo_chat and tool_failed_duo_chat. Nothing mounts it yet, so this MR changes no API.
- Dimensions:
toolName,event(tool_succeeded_duo_chatortool_failed_duo_chat),toolAccess(read, write or NULL),flowType, user, group, timestamp. - Metrics:
totalCount,usersCount,sessionsCount,writeSessionsCount,readOnlySessionsCount,successRate(NULL when there are no calls). - Filters:
toolName(in and not in),event,toolAccess,flowType(in and not in),userId(in and not in),groupId, timestamp range.
toolAccess is derived in the query from Ai::ToolRules::Registry.action_type_for, so the registry stays the only map from tool to access type. There is no database lookup. Destroy tools such as run_command count as write. Tool names outside the registry's built-in catalog, for example MCP server tools, are NULL. A session that called such a tool does not count as read-only.
readOnlySessionsCount uses a window function over the per-row groups the framework already builds. This is the first engine to do that, so reviewers may want to look at that expression. The window sorts every tool call in scope by session before the outer aggregate; a per-session CTE was not an option because supporting_cte joins on a table column and the session ID lives in the extras JSON. The metric is evaluated within the applied filters.
The development fixture gives the two tool-call events a tool name (one read, one write, one unknown MCP-style tool) and a session ID, so every toolAccess value appears in seeded data.
Tests
ee/spec/models/analytics/aggregation_engines/duo_tool_calls_spec.rbandexclusion_filter_coverage_spec.rb: 53 examples, pass locally against ClickHouse. Every filter has an example.
How to test
The engine has no API surface in this MR. Use the GraphiQL query in !263296 (merged) once both branches are checked out together, or run the engine spec.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.