Add an error SLI for the v3 package metadata sync
What does this MR do and why?
Summary
The package metadata sync can fail on every run on GitLab.com without anyone noticing: it logs the failure and returns, so the Sidekiq job still succeeds. This MR adds an error-rate application SLI for the sync so we can alert on it, delivering #643222 (closed).
Details
- New metric: two Prometheus counters, labelled by dataset (
data_type:malware_advisories,licenses,advisories).gitlab_sli_package_metadata_v3_sync_total: one per counted registry sync (npm, PyPI, ...).gitlab_sli_package_metadata_v3_sync_error_total: the syncs that failed.
- Where it is counted:
V3SyncService.track_sync_outcome, which already reports the result of every registry sync as an internal event. Each result counts as a success, an error, or is ignored: see How results are counted. - One behaviour change: a registry download that raises (for example a 500 from the package metadata distribution service, PDS) used to raise without reporting a result. It now reports a failure first, then raises as before.
- Low risk, no feature flag: the sync does the same work; the MR only adds two counters. It follows the
duo_workflow_session_credits_syncSLI (duo_workflow_session_credits_sync_slis.rb). - Alerts: gitlab-com/runbooks!12242 (merged). Either MR can merge first.
How results are counted
| Sync result | Counted as |
|---|---|
| New data synced, or already up to date | success |
| Stopped by the run's time limit after saving progress (it continues on the next run) | success |
| PDS rejected or failed the request, no instance token, or the data could not be read or saved | error |
| Stopped by the time limit before saving any progress, or after a save failed | not counted |
| Skipped: registry not served by PDS, or the run is shutting down | not counted |
A run stopped before it saved anything is not counted, so a download that never fits the time limit cannot look healthy.
The same mapping by outcome name (SYNC_OUTCOMES)
| Outcome | Counted as |
|---|---|
full_completed, delta_completed, delta_up_to_date |
success |
full_interrupted, delta_interrupted |
success when the checkpoint moved and nothing failed to persist; otherwise not counted |
full_failed, delta_failed, full_not_persisted, delta_not_persisted, bulk_delta_failed, aborted_no_token |
error |
skipped_stop_signal, bulk_delta_skipped_stop_signal, skipped_unsupported, delta_backlog |
not counted |
A spec fails if an outcome is added to SYNC_OUTCOMES without a row here.
Screenshots or screen recordings
Not applicable: no UI changes.
How to set up and validate locally
No user-facing change. To see the counters move on a real run in the GDK (this syncs malware advisories into your development database):
-
In
gdk rails console:Gitlab::Metrics::PackageMetadataV3SyncSlis.initialize_slis! counts = -> { %i[gitlab_sli_package_metadata_v3_sync_total gitlab_sli_package_metadata_v3_sync_error_total].to_h do |name| [name, Prometheus::Client.registry.get(name).values.to_h { |labels, value| [labels[:data_type], value.get] }] end } counts.call # every series starts at 0 PackageMetadata::MalwareAdvisorySyncService.execute(lease: Gitlab::ExclusiveLease.new('pm-sli-check', timeout: 60)) counts.call -
gitlab_sli_package_metadata_v3_sync_total{data_type="malware_advisories"}goes up by one per registry that synced or found nothing new...._error_totalstays at 0 unless a registry failed. Without an instance token, the run stops ataborted_no_tokenand both go up by one.
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.
References
- Issue: #643222 (closed)
- Alerts MR: gitlab-com/runbooks!12242 (merged)
- Epic: &20876
- Related: #602417 (closed) (sync metrics), #612556 (closed) (Kibana dashboard)