Skip to content

Allow group projects to be queried by code coverage with GraphQL

Max Orefice requested to merge mo-fix-coverage-summary-data-all-projects into master

Ref: #296665 (closed)

What does this MR do?

This MR allows to query group projects by code coverage with our GraphQL API.

It includes the following items:

  • New scope to query group projects with code coverage
  • Add new argument (hasCodeCoverage: Boolean) to our group projects graphql endpoint

Why are we doing this?

We are working to improve our analytic page aggregating our code coverage data at the group level.

We are currently displaying all projects in our dropdown projects as you can see below 👇

Repositories_Analytics___GitLab.org___GitLab_2021-02-22_17-03-13

After this MR, we will be able to display only projects having a code coverage data in our project's dropdown for a given group.

Screenshots

GraphQL request Response
{
  group(fullPath: "gitlab-org") {
      projects(hasCodeCoverage: true) {
      nodes {
        id
        name
          codeCoverageSummary {
          averageCoverage
          coverageCount
          lastUpdatedOn
        }
      }
    }
  }
}
{
  "data": {
    "group": {
      "projects": {
        "nodes": [
          {
            "id": "gid://gitlab/Project/2",
            "name": "Gitlab Shell",
            "codeCoverageSummary": {
              "averageCoverage": 49.9,
              "coverageCount": 1,
              "lastUpdatedOn": "2021-02-12"
            }
          },
          {
            "id": "gid://gitlab/Project/1",
            "name": "Gitlab Test",
            "codeCoverageSummary": {
              "averageCoverage": 99.9,
              "coverageCount": 1,
              "lastUpdatedOn": "2020-10-21"
            }
          }
        ]
      }
    }
  }
}

This implementation is similar to our existing one filtering group projects with vulnerabilities:

Database review

Query

SELECT
    projects.*
FROM
    projects
    INNER JOIN ci_daily_build_group_report_results ON ci_daily_build_group_report_results.project_id = projects.id
WHERE
    projects.namespace_id = 22
    AND ((data -> 'coverage') IS NOT NULL)
    AND ci_daily_build_group_report_results.default_branch = TRUE
GROUP BY
    projects.id

Execution plan

 Group  (cost=0.86..1609.87 rows=8 width=18) (actual time=12.469..760.310 rows=16 loops=1)
   Group Key: projects.id
   Buffers: shared hit=624 read=539 dirtied=49
   I/O Timings: read=716.746
   ->  Nested Loop  (cost=0.86..1609.85 rows=8 width=18) (actual time=12.466..759.816 rows=2493 loops=1)
         Buffers: shared hit=624 read=539 dirtied=49
         I/O Timings: read=716.746
         ->  Index Scan using index_projects_on_namespace_id_and_id on public.projects  (cost=0.44..525.47 rows=356 width=18) (actual time=7.812..471.048 rows=260 loops=1)
               Index Cond: (projects.namespace_id = 9970)
               Buffers: shared hit=4 read=262 dirtied=6
               I/O Timings: read=467.533
         ->  Index Only Scan using index_ci_daily_build_group_report_results_on_project_and_date on public.ci_daily_build_group_report_results  (cost=0.42..2.89 rows=16 width=8) (actual time=0.761..1.104 rows=10 loops=260)
               Index Cond: (ci_daily_build_group_report_results.project_id = projects.id)
               Heap Fetches: 170
               Buffers: shared hit=620 read=277 dirtied=43
               I/O Timings: read=249.213

Cold cache

Time: 766.079 ms  
  - planning: 5.660 ms  
  - execution: 760.419 ms (estimated* for prod: 0.038...0.760 s)  
    - I/O read: 716.746 ms  
    - I/O write: N/A  
  
Shared buffers:  
  - hits: 624 (~4.90 MiB) from the buffer pool  
  - reads: 539 (~4.20 MiB) from the OS file cache, including disk I/O  
  - dirtied: 49 (~392.00 KiB)  
  - writes: 0  

Warm cache

Time: 4.761 ms  
  - planning: 1.067 ms  
  - execution: 3.694 ms  
    - I/O read: N/A  
    - I/O write: N/A  
  
Shared buffers:  
  - hits: 1134 (~8.90 MiB) from the buffer pool  
  - reads: 0 from the OS file cache, including disk I/O  
  - dirtied: 0  
  - writes: 0 

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Max Orefice

Merge request reports

Loading