Add agent platform event counts to GraphQL
What does this MR do and why?
This merge request enhances the AI metrics system by adding detailed session tracking for agent platform events. The changes introduce new fields to track different session states (created, started, finished, dropped, stopped, resumed) and add filtering capabilities to query these metrics by flow type.
The implementation includes a new service to count these session events from a ClickHouse database, updates the GraphQL API to expose these new metrics with filtering options, and refactors some shared code to be more reusable across different AI analytics features. The changes also include comprehensive tests to ensure the new functionality works correctly with various filtering scenarios.
References
How to set up and validate locally
-
Run
FILTER=ai_usage_stats bundle exec rake db:seed_fu, try loweringTIME_PERIOD_DAYSto 5 to have more consistent data. -
Test the query with the flow type inclusion filter
query {
group(fullPath: "toolbox") {
name
aiMetrics {
agentPlatform(flowTypes: ["duo_chat"]) {
createdSessionEventCount
startedSessionEventCount
finishedSessionEventCount
stoppedSessionEventCount
resumedSessionEventCount
droppedSessionEventCount
}
}
}
3 Test the query with the flow type exclusion filter
query {
group(fullPath: "toolbox") {
name
aiMetrics {
agentPlatform(not: { flowTypes: ["duo_chat"] }) {
createdSessionEventCount
startedSessionEventCount
finishedSessionEventCount
stoppedSessionEventCount
resumedSessionEventCount
droppedSessionEventCount
}
}
}
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.