Add pipeline analytics for groups on GraphQL
What does this MR do and why?
Add pipelineAnalytics field for groups on GraphQL.
- Project pipeline analytics are still using the same queries
- Legacy fields will return nullfor groups
References
How to set up and validate locally
- Setup ClickHouse on your localhost
- Create a project that belongs to a group and take a note of its id
- On Rails console run the following script:
# Make sure this project belongs to a group
traversal_path = Project.last.project_namespace.traversal_path 
sample_data = [
  { id: 1, path: traversal_path, status: 'success', started_at: '2024-01-10 10:00:00' },
  { id: 2, path: traversal_path, status: 'failed', started_at: '2024-01-10 11:00:00' },
  { id: 3, path: traversal_path, status: 'failed', started_at: '2024-02-11 09:00:00' },
  { id: 4, path: traversal_path, status: 'success', started_at: '2024-03-12 10:00:00' },
  { id: 4, path: traversal_path, status: 'canceled', started_at: '2024-04-13 10:00:00' }
]
# Insert data into the ci_finished_pipelines table
sample_data.each do |record|
  query = <<-SQL
    INSERT INTO ci_finished_pipelines 
    (id, path, status, started_at)
    VALUES (#{record[:id]}, '#{record[:path]}', '#{record[:status]}', '#{record[:started_at]}')
  SQL
  ClickHouse::Client.execute(query, :main)
end- Go to GraphQL explorer and run a query to ensure protect pipelineAnalyticsfield still works
{
  project(fullPath: PROJECT_PATH) {
    pipelineAnalytics(fromTime: "2024-01-9", toTime: "2024-04-14") {
      aggregate {
        count
      }
      
      monthPipelinesLabels
    }
  }
} 5 Now check if the field is working for groups running the query
{
  group(fullPath: GROUP_PATH) {
    pipelineAnalytics(fromTime: "2024-01-9", toTime: "2024-04-14") {
      aggregate {
        count(status: FAILED)
      }
      
      timeSeries(period: DAY) {
        label
        count
      }
      
      monthPipelinesLabels
    }
  }
}Edited  by Felipe Cardozo