Fix Cache Refresh Issue in ProjectErrorTrackingSettings
What does this MR do?
Overview
This MR should keep unexpected errors in the cache calculation from causing the Error Tracking cache to indefinitely return nil
without attempting to refresh the cache. This code also ensures that we are still reporting the unexpected errors to sentry where we can triage them.
Technical Details
The cache always starts out as nil
[2] pry(main)> Rails.cache.read("error_tracking_project_error_tracking_setting:1889:list_issues:{"issue_status"=>"unresolved", "limit"=>20, "search_term"=>nil, "sort"=>"last_seen", "cursor"=>nil}") => nil
If I raise an uncaught error in the calculation code console without the new code I get nil
[2] pry(main)> Rails.cache.read("error_tracking_project_error_tracking_setting:1889:list_issues:{"issue_status"=>"unresolved", "limit"=>20, "search_term"=>nil, "sort"=>"last_seen", "cursor"=>nil}") => nil
but then when I remove the line of code raising the error the cache fails to ever refresh (this causes an infinite spinner).
With the new code from this branch
If an 'unexpected' error is raised it returns:
[3] pry(main)> Rails.cache.read("error_tracking_project_error_tracking_setting:1889:list_issues:{"issue_status"=>"unresolved", "limit"=>20, "search_term"=>nil, "sort"=>"last_seen", "cursor"=>nil}") => {:error=>"Unexpected Error"}
If you remove the error raise from the code the page will eventually reload
=> {:issues=> [#<Gitlab::ErrorTracking::Error:0x00007fe53d6e7e20 @count="3", @Culprit="bin/raven in ", @external_url="https://sentry.io/allison-browne/allison-browne/issues/1318486415", @first_seen="2019-11-06T20:16:57.333000Z", @frequency= [[1576454400, 0], [1576458000, 0], [1576461600, 0], [1576465200, 0], [1576468800, 0], [1576472400, 0], [1576476000, 0], [1576479600, 0], [1576483200, 0], [1576486800, 0], [1576490400, 0], [1576494000, 0], [1576497600, 0], [1576501200, 0], [1576504800, 0], [1576508400, 0], [1576512000, 0], [1576515600, 1], [1576519200, 0], [1576522800, 0], [1576526400, 0], [1576530000, 0], [1576533600, 0], [1576537200, 0]], @id="1318486415", @last_seen="2019-12-16T17:09:18.694663Z", @message="divided by 0", @project_id="1809044", @project_name="allison-browne", @project_slug="allison-browne", @short_id="ALLISON-BROWNE-1", @status="unresolved", @title="ZeroDivisionError: divided by 0", @type="error", @user_count=1>], :pagination=>{}}
Without this code the cache is set to nil and an infinite spinner occurs.
Conformity
-
Changelog entry - [-] Documentation (if required)
-
Code review guidelines - [-] Merge request performance guidelines
-
Style guides - [-] Database guides
- [-] Separation of EE specific content