Merge branch 'jira-ping-differentiate-cloud' into 'master'
Usage ping - Differentiate Jira Server and Cloud Closes #51043 See merge request gitlab-org/gitlab-ce!22791
This commit is contained in:
commit
cc9e3d0900
3 changed files with 34 additions and 2 deletions
|
@ -127,7 +127,6 @@ module Gitlab
|
|||
# rubocop: disable CodeReuse/ActiveRecord
|
||||
def services_usage
|
||||
types = {
|
||||
JiraService: :projects_jira_active,
|
||||
SlackService: :projects_slack_notifications_active,
|
||||
SlackSlashCommandsService: :projects_slack_slash_active,
|
||||
PrometheusService: :projects_prometheus_active
|
||||
|
@ -135,6 +134,23 @@ module Gitlab
|
|||
|
||||
results = count(Service.unscoped.where(type: types.keys, active: true).group(:type), fallback: Hash.new(-1))
|
||||
types.each_with_object({}) { |(klass, key), response| response[key] = results[klass.to_s] || 0 }
|
||||
.merge(jira_usage)
|
||||
end
|
||||
|
||||
def jira_usage
|
||||
# Jira Cloud does not support custom domains as per https://jira.atlassian.com/browse/CLOUD-6999
|
||||
# so we can just check for subdomains of atlassian.net
|
||||
services = count(
|
||||
Service.unscoped.where(type: :JiraService, active: true)
|
||||
.group("CASE WHEN properties LIKE '%.atlassian.net%' THEN 'cloud' ELSE 'server' END"),
|
||||
fallback: Hash.new(-1)
|
||||
)
|
||||
|
||||
{
|
||||
projects_jira_server_active: services['server'] || 0,
|
||||
projects_jira_cloud_active: services['cloud'] || 0,
|
||||
projects_jira_active: services['server'] == -1 ? -1 : services.values.sum
|
||||
}
|
||||
end
|
||||
|
||||
def count(relation, fallback: -1)
|
||||
|
|
|
@ -46,6 +46,17 @@ FactoryBot.define do
|
|||
)
|
||||
end
|
||||
|
||||
factory :jira_cloud_service, class: JiraService do
|
||||
project
|
||||
active true
|
||||
properties(
|
||||
url: 'https://mysite.atlassian.net',
|
||||
username: 'jira_user',
|
||||
password: 'my-secret-password',
|
||||
project_key: 'jira-key'
|
||||
)
|
||||
end
|
||||
|
||||
factory :hipchat_service do
|
||||
project
|
||||
type 'HipchatService'
|
||||
|
|
|
@ -8,6 +8,7 @@ describe Gitlab::UsageData do
|
|||
before do
|
||||
create(:jira_service, project: projects[0])
|
||||
create(:jira_service, project: projects[1])
|
||||
create(:jira_cloud_service, project: projects[2])
|
||||
create(:prometheus_service, project: projects[1])
|
||||
create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true)
|
||||
create(:service, project: projects[1], type: 'SlackService', active: true)
|
||||
|
@ -97,6 +98,8 @@ describe Gitlab::UsageData do
|
|||
projects
|
||||
projects_imported_from_github
|
||||
projects_jira_active
|
||||
projects_jira_server_active
|
||||
projects_jira_cloud_active
|
||||
projects_slack_notifications_active
|
||||
projects_slack_slash_active
|
||||
projects_prometheus_active
|
||||
|
@ -116,7 +119,9 @@ describe Gitlab::UsageData do
|
|||
|
||||
expect(count_data[:projects]).to eq(3)
|
||||
expect(count_data[:projects_prometheus_active]).to eq(1)
|
||||
expect(count_data[:projects_jira_active]).to eq(2)
|
||||
expect(count_data[:projects_jira_active]).to eq(3)
|
||||
expect(count_data[:projects_jira_server_active]).to eq(2)
|
||||
expect(count_data[:projects_jira_cloud_active]).to eq(1)
|
||||
expect(count_data[:projects_slack_notifications_active]).to eq(2)
|
||||
expect(count_data[:projects_slack_slash_active]).to eq(1)
|
||||
|
||||
|
|
Loading…
Reference in a new issue