Usage ping - Differentiate Jira Server and Cloud
This commit is contained in:
parent
f5d71ad8f3
commit
013d097e8b
3 changed files with 34 additions and 2 deletions
|
@ -126,7 +126,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
|
||||
|
@ -134,6 +133,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)
|
||||
|
@ -95,6 +96,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
|
||||
|
@ -114,7 +117,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