Class: ErrorTracking::ProjectErrorTrackingSetting
Constant Summary
collapse
- SENTRY_API_ERROR_TYPE_BAD_REQUEST =
'bad_request_for_sentry_api'
- SENTRY_API_ERROR_TYPE_MISSING_KEYS =
'missing_keys_in_sentry_response'
- SENTRY_API_ERROR_TYPE_NON_20X_RESPONSE =
'non_20x_response_from_sentry'
- SENTRY_API_ERROR_INVALID_SIZE =
'invalid_size_of_sentry_response'
- API_URL_PATH_REGEXP =
%r{
\A
(?<prefix>/api/0/projects/+)
(?:
(?<organization>[^/]+)/+
(?<project>[^/]+)/*
)?
\z
}x
ReactiveCaching::ExceededReactiveCacheLimit, ReactiveCaching::InvalidateReactiveCache, ReactiveCaching::WORK_TYPE
ApplicationRecord::MAX_PLUCK
ResetOnUnionError::MAX_RESET_PERIOD
Class Method Summary
collapse
Instance Method Summary
collapse
includes_helpers, redirect_legacy_paths, url_helpers
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#serializable_hash
Class Method Details
.build_api_url_from(api_host:, project_slug:, organization_slug:) ⇒ Object
96
97
98
99
100
101
102
103
104
105
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 96
def self.build_api_url_from(api_host:, project_slug:, organization_slug:)
return if api_host.blank?
uri = Addressable::URI.parse("#{api_host}/api/0/projects/#{organization_slug}/#{project_slug}/")
uri.path = uri.path.squeeze('/')
uri.to_s
rescue Addressable::URI::InvalidURIError
api_host
end
|
175
176
177
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 175
def self.(url)
url&.sub('api/0/projects/', '')
end
|
Instance Method Details
#api_host ⇒ Object
179
180
181
182
183
184
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 179
def api_host
return if api_url.blank?
Addressable::URI.join(api_url, '/').to_s
end
|
#api_url=(value) ⇒ Object
75
76
77
78
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 75
def api_url=(value)
super
clear_memoization(:api_url_slugs)
end
|
#calculate_reactive_cache(request, opts) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 152
def calculate_reactive_cache(request, opts)
handle_exceptions do
case request
when 'list_issues'
sentry_client.list_issues(**opts.symbolize_keys)
when 'issue_details'
issue = sentry_client.issue_details(**opts.symbolize_keys)
{ issue: add_gitlab_issue_details(issue) }
when 'issue_latest_event'
{
latest_event: sentry_client.issue_latest_event(**opts.symbolize_keys)
}
end
end
end
|
#expire_issues_cache ⇒ Object
168
169
170
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 168
def expire_issues_cache
clear_reactive_cache_set!('list_issues')
end
|
#gitlab_dsn ⇒ Object
69
70
71
72
73
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 69
def gitlab_dsn
strong_memoize(:gitlab_dsn) do
client_key&.sentry_dsn
end
end
|
#integrated_client? ⇒ Boolean
61
62
63
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 61
def integrated_client?
integrated
end
|
#integrated_enabled? ⇒ Boolean
65
66
67
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 65
def integrated_enabled?
enabled? && integrated_client?
end
|
#issue_details(opts = {}) ⇒ Object
129
130
131
132
133
134
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 129
def issue_details(opts = {})
with_reactive_cache('issue_details', opts.stringify_keys) do |result|
ensure_issue_belongs_to_project!(result[:issue].project_id) if result[:issue]
result
end
end
|
#issue_latest_event(opts = {}) ⇒ Object
136
137
138
139
140
141
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 136
def issue_latest_event(opts = {})
with_reactive_cache('issue_latest_event', opts.stringify_keys) do |result|
ensure_issue_belongs_to_project!(result[:latest_event].project_id) if result[:latest_event]
result
end
end
|
#list_sentry_issues(opts = {}) ⇒ Object
117
118
119
120
121
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 117
def list_sentry_issues(opts = {})
with_reactive_cache_set('list_issues', opts.stringify_keys) do |result|
result
end
end
|
#list_sentry_projects ⇒ Object
123
124
125
126
127
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 123
def list_sentry_projects
handle_exceptions do
{ projects: sentry_client.projects }
end
end
|
#organization_name ⇒ Object
84
85
86
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 84
def organization_name
super || organization_name_from_slug
end
|
#organization_slug ⇒ Object
92
93
94
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 92
def organization_slug
organization_slug_from_api_url
end
|
#project_name ⇒ Object
80
81
82
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 80
def project_name
super || project_name_from_slug
end
|
#project_slug ⇒ Object
88
89
90
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 88
def project_slug
project_slug_from_api_url
end
|
#sentry_client ⇒ Object
107
108
109
110
111
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 107
def sentry_client
strong_memoize(:sentry_client) do
::ErrorTracking::SentryClient.new(api_url, token)
end
end
|
#sentry_enabled ⇒ Object
57
58
59
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 57
def sentry_enabled
enabled && !integrated_client?
end
|
#sentry_external_url ⇒ Object
113
114
115
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 113
def sentry_external_url
self.class.(api_url)
end
|
#update_issue(opts = {}) ⇒ Object
143
144
145
146
147
148
149
150
|
# File 'app/models/error_tracking/project_error_tracking_setting.rb', line 143
def update_issue(opts = {})
issue_to_be_updated = sentry_client.issue_details(issue_id: opts[:issue_id])
ensure_issue_belongs_to_project!(issue_to_be_updated.project_id)
handle_exceptions do
{ updated: sentry_client.update_issue(**opts) }
end
end
|