Skip to content

Add feature to map source code - coverage - owner

Resolves: https://gitlab.com/gitlab-org/quality/feature-readiness/team/-/issues/7

What does this MR do and why?

Adds an executable, to be run in scheduled CI pipelines of GitLab's monolith, that:

  1. Maps categories to teams (i.e., groups, stages, and/or sections) by
    1. Fetching GitLab's stages.yml file
    2. Parsing it and creating the mapping
  2. Maps teams to the source code (i.e., Ruby classes) they own by
    1. Fetching all rspec-*.json artifacts created by collector jobs for unit tests, i.e.:
      1. rspec:artifact-collector unit
      2. rspec:artifact-collector unit single-redis
      3. rspec:artifact-collector ee unit single-redis
      4. rspec:artifact-collector ee unit
    2. Parsing the fetched artifacts
    3. Getting the feature_category for each class (each class could have multiple) from the parsed fetched artifacts
    4. Using the feature_category to class mapping from point 2.3 to map teams to classes with the category to teams mapping from point 1
  3. Maps classes to their unit test coverage by
    1. Fetching the .lcov file produced by the rspec:coverage job that runs in the same pipeline out executable runs in
    2. Parsing the .lcov file and getting the needed info from there
  4. Maps classes to all test files testing it (this include also non-unit tests) by
    1. Fetching the test map created by jobs running before in the same pipeline
    2. Parsing it and creating the mapping

With the above steps it's possible to create and keep up-to-date these 2 tables in ClickHouse:

category group stage section
job_artifacts pipeline_execution verify ci
timestamp file coverage category ci_project_id ci_project_path ci_job_name ci_job_id ci_pipeline_id ci_merge_request_iid ci_branch ci_target_branch
2025-10-15 15:50:49.000000 spec/feature/foo.rb 53% job_artifacts
2025-10-15 15:50:49.000000 spec/feature/bar.rb 87% source_code_management

Screenshots or screen recordings

Contact me via Slack to get access to the ClickHouse instance with the data I pushed with this MR.

How to set up and validate locally

  1. Run these commands to fetch a bunch of files locally, and store them in <project-root>/working_dir/:

    curl -o gitlab.lcov https://gitlab.com/gitlab-org/gitlab/-/jobs/11380416469/artifacts/raw/coverage/lcov/gitlab.lcov
    
    curl -o rspec-11380416038.json https://gitlab.com/gitlab-org/gitlab/-/jobs/11380416038/artifacts/raw/rspec/rspec-11380416038.json
    
    curl -o rspec-11380416056.json https://gitlab.com/gitlab-org/gitlab/-/jobs/11380416056/artifacts/raw/rspec/rspec-11380416056.json
    
    curl https://gitlab-org.gitlab.io/gitlab/crystalball/packed-mapping.json.gz | gzip -d > mapping.json
  2. Set the CLICKHOUSE_URL, CLICKHOUSE_DATABASE, CLICKHOUSE_USERNAME, CLICKHOUSE_PASSWORD with the values you got from asking me in Slack :)

  3. Run

    ruby exe/test-coverage \
      --working_dir '/local/path/to/gitlab_quality-test_tooling/working_dir/' \
      --rspec-reports-jobs 'rspec_artifact_collector_unit,rspec_artifact-collector_unit_single-redis,rspec:artifact-collector_ee_unit_single-redis,rspec_artifact-collector_ee_unit' \
      --rspec-reports-glob 'rspec/rspec-*.json' \
      --coverage-report-path '/local/path/to/gitlab_quality-test_tooling/working_dir/rspec_coverage/coverage/lcov/gitlab.lcov' \
      --test-map-url 'https://gitlab-org.gitlab.io/gitlab/crystalball/packed-mapping.json.gz'
  4. Check that the functionality works as expected

  5. Check in ClickHouse that the pushed data is what is expected

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Alberto Bignotti

Merge request reports

Loading