Validate error tracking params before queueing cache work
What does this MR do and why?
The Sentry-backed error tracking services (ErrorTracking::ListIssuesService, IssueDetailsService and IssueLatestEventService) read through ProjectErrorTrackingSetting#with_reactive_cache. Every distinct set of request parameters is its own cache entry, and each entry is refreshed every minute by ExternalServiceReactiveCachingWorker for as long as it is read. That worker class is shared with environments, clusters, Prometheus and integrations.
Nothing validated the parameters before that happened. A request with sort=newest, a non-numeric issue id or an arbitrary cursor still wrote an :alive key, enqueued a job, and kept a refresh loop running for a Sentry call that could only fail. Only issue_status was checked.
This MR rejects malformed input in the services, before with_reactive_cache runs, and returns 400 Bad Request: Invalid <param> with no cache write and no job:
| Parameter | Check |
|---|---|
sort |
One of frequency, first_seen, last_seen (the keys of SentryClient::Issue::SENTRY_API_SORT_VALUE_MAP). It was previously only mapped inside the job. |
search_term |
At most 255 characters. |
cursor |
Sentry backend only. Must match <timestamp>:<offset>:<is_prev>, the shape Sentry's pagination cursors have. |
issue_id |
Sentry backend only. Must be numeric. |
issue_status |
Existing check kept; the error message now uses the same invalid_param_error helper. |
The checks live in the services so the web JSON controllers and the three GraphQL resolvers (sentryErrors, sentryDetailedError, errorStackTrace) are covered by one change. The integrated error tracking backend uses opaque cursors and ids, so the cursor and issue id checks are skipped for it and its behaviour is unchanged.
Valid requests behave exactly as before. The GraphQL resolvers keep returning null for rejected input, as they already did for data that was not ready yet. Surfacing a GraphQL error there is a possible follow-up.
No new tables, settings or feature flags. The 255-character limit on search_term and the cursor pattern are proposed thresholds, open to review.
References
- Related to https://gitlab.com/gitlab-org/gitlab/-/work_items/638412 (confidential)
- Parent: https://gitlab.com/gitlab-org/gitlab/-/work_items/636812 (confidential)
Screenshots or screen recordings
Not applicable, backend-only change. The existing error tracking pages show their generic "Failed to load" alert for a rejected request, as they already did for other 400 responses.
How to set up and validate locally
The Sentry settings page needs a reachable Sentry to save, so create the setting from the Rails console instead. The API URL only has to pass format validation.
-
Create a project, for example
root/et-test, then inbin/rails console:project = Project.find_by_full_path('root/et-test') project.create_error_tracking_setting!( enabled: true, integrated: false, api_url: 'https://sentry.io/api/0/projects/my-org/my-project/', token: 'dummy-token' ) -
Signed in, open these URLs. Each returns
400with{"message":"Bad Request: Invalid <param>"}:http://127.0.0.1:3000/root/et-test/-/error_tracking.json?sort=newesthttp://127.0.0.1:3000/root/et-test/-/error_tracking.json?cursor=some-cursorhttp://127.0.0.1:3000/root/et-test/-/error_tracking.json?search_term=<256 characters>http://127.0.0.1:3000/root/et-test/-/error_tracking/abc/details.jsonhttp://127.0.0.1:3000/root/et-test/-/error_tracking/abc/stack_trace.json
-
Open the valid forms. Each returns
204on the first call and enqueues a job; later calls return the cached Sentry401error, which is the pre-existing behaviour with a dummy token:http://127.0.0.1:3000/root/et-test/-/error_tracking.json?sort=frequencyhttp://127.0.0.1:3000/root/et-test/-/error_tracking.json?cursor=1572959139000:0:0http://127.0.0.1:3000/root/et-test/-/error_tracking/123/details.json
-
Confirm the rejected requests left nothing behind. In the console, only the valid requests appear:
Gitlab::Redis::Cache.with do |r| r.scan_each(match: 'cache:gitlab:error_tracking_project_error_tracking_setting:*').to_a endgdk tail rails-background-jobs | grep ExternalServiceReactiveCachingWorkershows jobs for the valid requests only.
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.