Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-09 12:07:51 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-09 12:07:51 +0300
commit5afd8575506372dd64c238203bd05b4826f3ae2e (patch)
treee167192fdc7d73fcc1aa5bd33b535b813120ec37 /lib
parent8bda404e2919234c299f088b7d8d04f8449125de (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/usage_data.rb23
-rw-r--r--lib/sentry/client.rb108
-rw-r--r--lib/sentry/client/issue.rb107
3 files changed, 118 insertions, 120 deletions
diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb
index b200596a500..e00b49b9042 100644
--- a/lib/gitlab/usage_data.rb
+++ b/lib/gitlab/usage_data.rb
@@ -178,18 +178,17 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
def services_usage
- types = {
- SlackService: :projects_slack_notifications_active,
- SlackSlashCommandsService: :projects_slack_slash_active,
- PrometheusService: :projects_prometheus_active,
- CustomIssueTrackerService: :projects_custom_issue_tracker_active,
- JenkinsService: :projects_jenkins_active,
- MattermostService: :projects_mattermost_active
- }
+ service_counts = count(Service.active.where(template: false).where.not(type: 'JiraService').group(:type), fallback: Hash.new(-1))
+
+ results = Service.available_services_names.each_with_object({}) do |service_name, response|
+ response["projects_#{service_name}_active".to_sym] = service_counts["#{service_name}_service".camelize] || 0
+ end
- results = count(Service.active.by_type(types.keys).group(:type), fallback: Hash.new(-1))
- types.each_with_object({}) { |(klass, key), response| response[key] = results[klass.to_s] || 0 }
- .merge(jira_usage)
+ # Keep old Slack keys for backward compatibility, https://gitlab.com/gitlab-data/analytics/issues/3241
+ results[:projects_slack_notifications_active] = results[:projects_slack_active]
+ results[:projects_slack_slash_active] = results[:projects_slack_slash_commands_active]
+
+ results.merge(jira_usage)
end
def jira_usage
@@ -223,6 +222,7 @@ module Gitlab
results
end
+ # rubocop: enable CodeReuse/ActiveRecord
def user_preferences_usage
{} # augmented in EE
@@ -233,7 +233,6 @@ module Gitlab
rescue ActiveRecord::StatementInvalid
fallback
end
- # rubocop: enable CodeReuse/ActiveRecord
def approximate_counts
approx_counts = Gitlab::Database::Count.approximate_counts(APPROXIMATE_COUNT_MODELS)
diff --git a/lib/sentry/client.rb b/lib/sentry/client.rb
index e3b8305b664..40821e2b233 100644
--- a/lib/sentry/client.rb
+++ b/lib/sentry/client.rb
@@ -9,14 +9,6 @@ module Sentry
Error = Class.new(StandardError)
MissingKeysError = Class.new(StandardError)
ResponseInvalidSizeError = Class.new(StandardError)
- BadRequestError = Class.new(StandardError)
-
- SENTRY_API_SORT_VALUE_MAP = {
- # <accepted_by_client> => <accepted_by_sentry_api>
- 'frequency' => 'freq',
- 'first_seen' => 'new',
- 'last_seen' => nil
- }.freeze
attr_accessor :url, :token
@@ -25,30 +17,8 @@ module Sentry
@token = token
end
- def list_issues(**keyword_args)
- response = get_issues(keyword_args)
-
- issues = response[:issues]
- pagination = response[:pagination]
-
- validate_size(issues)
-
- handle_mapping_exceptions do
- {
- issues: map_to_errors(issues),
- pagination: pagination
- }
- end
- end
-
private
- def validate_size(issues)
- return if Gitlab::Utils::DeepSize.new(issues).valid?
-
- raise ResponseInvalidSizeError, "Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}."
- end
-
def handle_mapping_exceptions(&block)
yield
rescue KeyError => e
@@ -85,31 +55,6 @@ module Sentry
handle_response(response)
end
- def get_issues(**keyword_args)
- response = http_get(
- issues_api_url,
- query: list_issue_sentry_query(keyword_args)
- )
-
- {
- issues: response[:body],
- pagination: Sentry::PaginationParser.parse(response[:headers])
- }
- end
-
- def list_issue_sentry_query(issue_status:, limit:, sort: nil, search_term: '', cursor: nil)
- unless SENTRY_API_SORT_VALUE_MAP.key?(sort)
- raise BadRequestError, 'Invalid value for sort param'
- end
-
- {
- query: "is:#{issue_status} #{search_term}".strip,
- limit: limit,
- sort: SENTRY_API_SORT_VALUE_MAP[sort],
- cursor: cursor
- }.compact
- end
-
def handle_request_exceptions
yield
rescue Gitlab::HTTP::Error => e
@@ -139,58 +84,5 @@ module Sentry
def raise_error(message)
raise Client::Error, message
end
-
- def issues_api_url
- issues_url = URI(@url + '/issues/')
- issues_url.path.squeeze!('/')
-
- issues_url
- end
-
- def map_to_errors(issues)
- issues.map(&method(:map_to_error))
- end
-
- def issue_url(id)
- issues_url = @url + "/issues/#{id}"
-
- parse_sentry_url(issues_url)
- end
-
- def project_url
- parse_sentry_url(@url)
- end
-
- def parse_sentry_url(api_url)
- url = ErrorTracking::ProjectErrorTrackingSetting.extract_sentry_external_url(api_url)
-
- uri = URI(url)
- uri.path.squeeze!('/')
- # Remove trailing slash
- uri = uri.to_s.gsub(/\/\z/, '')
-
- uri
- end
-
- def map_to_error(issue)
- Gitlab::ErrorTracking::Error.new(
- id: issue.fetch('id'),
- first_seen: issue.fetch('firstSeen', nil),
- last_seen: issue.fetch('lastSeen', nil),
- title: issue.fetch('title', nil),
- type: issue.fetch('type', nil),
- user_count: issue.fetch('userCount', nil),
- count: issue.fetch('count', nil),
- message: issue.dig('metadata', 'value'),
- culprit: issue.fetch('culprit', nil),
- external_url: issue_url(issue.fetch('id')),
- short_id: issue.fetch('shortId', nil),
- status: issue.fetch('status', nil),
- frequency: issue.dig('stats', '24h'),
- project_id: issue.dig('project', 'id'),
- project_name: issue.dig('project', 'name'),
- project_slug: issue.dig('project', 'slug')
- )
- end
end
end
diff --git a/lib/sentry/client/issue.rb b/lib/sentry/client/issue.rb
index 4a11c87faa4..b6f2e07d233 100644
--- a/lib/sentry/client/issue.rb
+++ b/lib/sentry/client/issue.rb
@@ -3,6 +3,31 @@
module Sentry
class Client
module Issue
+ BadRequestError = Class.new(StandardError)
+
+ SENTRY_API_SORT_VALUE_MAP = {
+ # <accepted_by_client> => <accepted_by_sentry_api>
+ 'frequency' => 'freq',
+ 'first_seen' => 'new',
+ 'last_seen' => nil
+ }.freeze
+
+ def list_issues(**keyword_args)
+ response = get_issues(keyword_args)
+
+ issues = response[:issues]
+ pagination = response[:pagination]
+
+ validate_size(issues)
+
+ handle_mapping_exceptions do
+ {
+ issues: map_to_errors(issues),
+ pagination: pagination
+ }
+ end
+ end
+
def issue_details(issue_id:)
issue = get_issue(issue_id: issue_id)
@@ -11,6 +36,37 @@ module Sentry
private
+ def get_issues(**keyword_args)
+ response = http_get(
+ issues_api_url,
+ query: list_issue_sentry_query(keyword_args)
+ )
+
+ {
+ issues: response[:body],
+ pagination: Sentry::PaginationParser.parse(response[:headers])
+ }
+ end
+
+ def list_issue_sentry_query(issue_status:, limit:, sort: nil, search_term: '', cursor: nil)
+ unless SENTRY_API_SORT_VALUE_MAP.key?(sort)
+ raise BadRequestError, 'Invalid value for sort param'
+ end
+
+ {
+ query: "is:#{issue_status} #{search_term}".strip,
+ limit: limit,
+ sort: SENTRY_API_SORT_VALUE_MAP[sort],
+ cursor: cursor
+ }.compact
+ end
+
+ def validate_size(issues)
+ return if Gitlab::Utils::DeepSize.new(issues).valid?
+
+ raise ResponseInvalidSizeError, "Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}."
+ end
+
def get_issue(issue_id:)
http_get(issue_api_url(issue_id))[:body]
end
@@ -19,6 +75,13 @@ module Sentry
http_put(issue_api_url(issue_id), params)[:body]
end
+ def issues_api_url
+ issues_url = URI("#{url}/issues/")
+ issues_url.path.squeeze!('/')
+
+ issues_url
+ end
+
def issue_api_url(issue_id)
issue_url = URI(url)
issue_url.path = "/api/0/issues/#{CGI.escape(issue_id.to_s)}/"
@@ -35,6 +98,50 @@ module Sentry
gitlab_plugin.dig('issue', 'url')
end
+ def issue_url(id)
+ parse_sentry_url("#{url}/issues/#{id}")
+ end
+
+ def project_url
+ parse_sentry_url(url)
+ end
+
+ def parse_sentry_url(api_url)
+ url = ErrorTracking::ProjectErrorTrackingSetting.extract_sentry_external_url(api_url)
+
+ uri = URI(url)
+ uri.path.squeeze!('/')
+ # Remove trailing slash
+ uri = uri.to_s.gsub(/\/\z/, '')
+
+ uri
+ end
+
+ def map_to_errors(issues)
+ issues.map(&method(:map_to_error))
+ end
+
+ def map_to_error(issue)
+ Gitlab::ErrorTracking::Error.new(
+ id: issue.fetch('id'),
+ first_seen: issue.fetch('firstSeen', nil),
+ last_seen: issue.fetch('lastSeen', nil),
+ title: issue.fetch('title', nil),
+ type: issue.fetch('type', nil),
+ user_count: issue.fetch('userCount', nil),
+ count: issue.fetch('count', nil),
+ message: issue.dig('metadata', 'value'),
+ culprit: issue.fetch('culprit', nil),
+ external_url: issue_url(issue.fetch('id')),
+ short_id: issue.fetch('shortId', nil),
+ status: issue.fetch('status', nil),
+ frequency: issue.dig('stats', '24h'),
+ project_id: issue.dig('project', 'id'),
+ project_name: issue.dig('project', 'name'),
+ project_slug: issue.dig('project', 'slug')
+ )
+ end
+
def map_to_detailed_error(issue)
Gitlab::ErrorTracking::DetailedError.new(
id: issue.fetch('id'),