diff --git a/ee/app/services/ai/duo_workflows/clean_stuck_workflows_service.rb b/ee/app/services/ai/duo_workflows/clean_stuck_workflows_service.rb index fc75571babbcdc12256a461c6391ee3c5defd809..5e47876b66ab7a0d93cb5c183a05f22f4f975afb 100644 --- a/ee/app/services/ai/duo_workflows/clean_stuck_workflows_service.rb +++ b/ee/app/services/ai/duo_workflows/clean_stuck_workflows_service.rb @@ -22,9 +22,9 @@ def execute "cleanup_stuck_agent_platform_session", user: w.user, project: w.project, - name: w.project.namespace, + namespace: w.project.namespace, additional_properties: { - label: "workflow_finish_event", + label: w.workflow_definition || "unknown", value: w.id, property: "failed", category: w.workflow_definition diff --git a/ee/app/services/ai/duo_workflows/start_workflow_service.rb b/ee/app/services/ai/duo_workflows/start_workflow_service.rb index f148a1729f97b821755820ae748083377417404f..e87ff6e5cf93a49f53cf765076e356253eacb98f 100644 --- a/ee/app/services/ai/duo_workflows/start_workflow_service.rb +++ b/ee/app/services/ai/duo_workflows/start_workflow_service.rb @@ -3,6 +3,9 @@ module Ai module DuoWorkflows class StartWorkflowService + include ::Services::ReturnServiceResponses + include ::Gitlab::InternalEventsTracking + IMAGE = 'registry.gitlab.com/gitlab-org/duo-workflow/default-docker-image/workflow-generic-image:v0.0.4' def initialize(workflow:, params:) @@ -47,6 +50,10 @@ def execute workload = response.payload if response.success? @workflow.workflows_workloads.create(project_id: project.id, workload_id: workload.id) + + # Track the start of the agent platform session + track_start_agent_platform_session + ServiceResponse.success(payload: { workload_id: workload.id }) else ServiceResponse.error(message: response.message, reason: :workload_failure) @@ -121,6 +128,20 @@ def link_composite_identity identity = ::Gitlab::Auth::Identity.fabricate(duo_workflow_service_account) identity.link!(@current_user) if identity&.composite? end + + def track_start_agent_platform_session + track_internal_event( + "start_agent_platform_session", + user: @current_user, + project: project, + namespace: project.namespace, + additional_properties: { + label: @workflow.workflow_definition || "unknown", + value: @workflow.id, + category: @workflow.workflow_definition + } + ) + end end end end diff --git a/ee/config/events/cleanup_stuck_agent_platform_session.yml b/ee/config/events/cleanup_stuck_agent_platform_session.yml index d7f9c926857b6e2d2e2bb565b486651b04521636..3b27314bb187e631815305e243593af1347f7d1b 100644 --- a/ee/config/events/cleanup_stuck_agent_platform_session.yml +++ b/ee/config/events/cleanup_stuck_agent_platform_session.yml @@ -9,7 +9,7 @@ identifiers: - namespace additional_properties: label: - description: hardcoded value "workflow_finish_event" + description: flow type (e.g. chat, software_development, etc.) property: description: workflow's new status eg. failed or paused value: diff --git a/ee/config/events/start_agent_platform_session.yml b/ee/config/events/start_agent_platform_session.yml new file mode 100644 index 0000000000000000000000000000000000000000..6b61fbea56515642384b870f9ff0ca86bbe70909 --- /dev/null +++ b/ee/config/events/start_agent_platform_session.yml @@ -0,0 +1,24 @@ +--- +description: Tracks the start of a GitLab Duo Agent platform session (formerly Duo Workflow). Important for Duo Agent Platform analytics +internal_events: true +status: active +action: start_agent_platform_session +identifiers: +- project +- user +- namespace +additional_properties: + label: + description: flow type (e.g. chat, software_development, etc.) + value: + description: id of the session (still called workflow_id in most places) + category: + description: workflow definition +product_group: duo_workflow +product_categories: +- duo_workflow +milestone: '18.3' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/560731 +tiers: +- premium +- ultimate \ No newline at end of file diff --git a/ee/spec/services/ai/duo_workflows/clean_stuck_workflows_service_spec.rb b/ee/spec/services/ai/duo_workflows/clean_stuck_workflows_service_spec.rb index 4ac103a693483079e23005f46ea79c4953f3cffc..0796b6c8a3d285dbb66bc1d7ffcfac18c7d26004 100644 --- a/ee/spec/services/ai/duo_workflows/clean_stuck_workflows_service_spec.rb +++ b/ee/spec/services/ai/duo_workflows/clean_stuck_workflows_service_spec.rb @@ -43,8 +43,9 @@ .with(category: "Ai::DuoWorkflows::CleanStuckWorkflowsService", user: workflow.user, project: workflow.project, + namespace: workflow.project.namespace, additional_properties: { - label: "workflow_finish_event", + label: workflow.workflow_definition, value: workflow.id, property: "failed", category: workflow.workflow_definition diff --git a/ee/spec/services/ai/duo_workflows/start_workflow_service_spec.rb b/ee/spec/services/ai/duo_workflows/start_workflow_service_spec.rb index 523d30768202ce7e864fb516205803e51e63e3f4..efa8414e9b8eceac1af3c2171c57581f69daeb88 100644 --- a/ee/spec/services/ai/duo_workflows/start_workflow_service_spec.rb +++ b/ee/spec/services/ai/duo_workflows/start_workflow_service_spec.rb @@ -40,6 +40,19 @@ expect(workload.branch_name).to start_with('workloads/') expect(workload.branch_name).to start_with('workloads/') end + + it 'tracks start_agent_platform_session event' do + expect { execute }.to trigger_internal_events("start_agent_platform_session") + .with(category: "Ai::DuoWorkflows::StartWorkflowService", + user: workflow.user, + project: workflow.project, + namespace: workflow.project.namespace, + additional_properties: { + label: workflow.workflow_definition, + value: workflow.id, + category: workflow.workflow_definition + }) + end end shared_examples 'failure' do