Skip to content

Add source as filter on Jobs GraphQL

What does this MR do and why?

Adds GraphQL filtering on jobs by their source, leveraging the Ci::BuildSource model. The source property is an enum consisting of scan_execution_policy and pipeline_execution_policy, merged with the source options from ::Enums::Ci::Pipeline.sources.

How to set up and validate locally

  1. Enable the FF populate_and_use_build_source_table.
  2. Run pipelines to generate jobs or examine existing jobs.
  3. Build sources are not yet generated automatically. In a Rails console, create BuildSource records for some jobs, setting source. Check Ci::BuildSource.sources for possible values. You can generate a source for each build in the local database with the following:
DO $$DECLARE b record;
BEGIN
  FOR b IN SELECT id, project_id, partition_id FROM p_ci_builds WHERE type = 'Ci::Build'
  LOOP
    INSERT INTO p_ci_build_sources (build_id, project_id, partition_id, source)
      VALUES (b.id, b.project_id, b.partition_id, ceil(random() * 17));
  END LOOP;
END
$$;
  1. Run GraphQL queries on jobs with the source filter:
query {
  project(fullPath: "flightjs/Flight") {
    id
    jobs(first: 10, sources: [PUSH, TRIGGER]) {
      nodes {
        id
        source
        refName
        refPath
        pipeline {
          id
        }
        name
      }
      pageInfo {
        endCursor
        hasNextPage
      }
    }
  }
}
  1. Test with after param using the value endCursor. Note that the results are offset paginated for source-filtered queries only.

Queries

From GraphQL query, with index created and 1M source records seeded: https://console.postgres.ai/gitlab/gitlab-production-ci/sessions/34191/commands/105201

Related to #481907 (closed)

Edited by Aaron Huntsman

Merge request reports

Loading