Ignore child pipeline absences in analyzer statuses

What does this MR do and why?

Security inventory marks scanners Stale when child pipelines without security jobs finish on the default branch. Each finished child pipeline was evaluated as its own default-branch pipeline. Every analyzer it did not run got one more consecutive absence, so a parent pipeline that triggers three deployment child pipelines turned its scanners Stale minutes after running them.

This MR stops counting absences for child pipelines in Security::AnalyzersStatus::UpdateService#absent_statuses, the same way business logic scan pipelines are already skipped. A child pipeline that runs a scanner still records that scanner's status. The change is behind the analyzer_status_ignore_child_pipeline_absences feature flag (gitlab_com_derisk, project actor, default off).

Why in the service and not in the pipeline completion hook

Child pipelines without reports reach the service through the after_transition hook in ee/app/models/ee/ci/pipeline.rb. Child pipelines with reports reach it through Security::ReportsIngestedEvent, which is published per pipeline in the hierarchy. Skipping absences in the service covers both paths. The parent pipeline still reaches the service on either path, so an analyzer that is really removed from the CI configuration still goes Stale through the parent's runs.

Known gap, not changed here: the parent pipeline still counts analyzers that only run in child pipelines as absent. A complete fix would evaluate the whole pipeline hierarchy once. That is a follow-up.

References

Screenshots or screen recordings

Not applicable, backend only. Security::AnalyzerProjectStatus for a reproduction project (SAST and secret detection in the parent, three child pipelines without security jobs):

Before (flag off) After (flag on)
sast, secret_detection: stale, count 3 after the third child pipeline sast, secret_detection: success, count 0 after all three child pipelines

How to set up and validate locally

  1. Create a project in a group on an Ultimate instance, using the .gitlab-ci.yml, deploy.yml and deploy-env.yml from the issue's steps to reproduce.

  2. Run a pipeline on the default branch and let its three child pipelines finish. In the Rails console, the statuses are now stale:

    Security::AnalyzerProjectStatus.where(project: Project.find_by_full_path('<group>/<project>')).pluck(:analyzer_type, :status, :consecutive_absence_count)
  3. Enable the flag for the project:

    Feature.enable(:analyzer_status_ignore_child_pipeline_absences, Project.find_by_full_path('<group>/<project>'))
  4. Run another default branch pipeline and let its child pipelines finish. The statuses are success with a count of 0, and Secure > Security inventory shows the scanners as enabled.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Danny Bailey

Merge request reports

Loading
Loading