Commit 013d097e authored by Mario de la Ossa's avatar Mario de la Ossa

Usage ping - Differentiate Jira Server and Cloud

parent f5d71ad8
...@@ -126,7 +126,6 @@ module Gitlab ...@@ -126,7 +126,6 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def services_usage def services_usage
types = { types = {
JiraService: :projects_jira_active,
SlackService: :projects_slack_notifications_active, SlackService: :projects_slack_notifications_active,
SlackSlashCommandsService: :projects_slack_slash_active, SlackSlashCommandsService: :projects_slack_slash_active,
PrometheusService: :projects_prometheus_active PrometheusService: :projects_prometheus_active
...@@ -134,6 +133,23 @@ module Gitlab ...@@ -134,6 +133,23 @@ module Gitlab
results = count(Service.unscoped.where(type: types.keys, active: true).group(:type), fallback: Hash.new(-1)) 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 } 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 end
def count(relation, fallback: -1) def count(relation, fallback: -1)
......
...@@ -46,6 +46,17 @@ FactoryBot.define do ...@@ -46,6 +46,17 @@ FactoryBot.define do
) )
end 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 factory :hipchat_service do
project project
type 'HipchatService' type 'HipchatService'
......
...@@ -8,6 +8,7 @@ describe Gitlab::UsageData do ...@@ -8,6 +8,7 @@ describe Gitlab::UsageData do
before do before do
create(:jira_service, project: projects[0]) create(:jira_service, project: projects[0])
create(:jira_service, project: projects[1]) create(:jira_service, project: projects[1])
create(:jira_cloud_service, project: projects[2])
create(:prometheus_service, project: projects[1]) create(:prometheus_service, project: projects[1])
create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true) create(:service, project: projects[0], type: 'SlackSlashCommandsService', active: true)
create(:service, project: projects[1], type: 'SlackService', active: true) create(:service, project: projects[1], type: 'SlackService', active: true)
...@@ -95,6 +96,8 @@ describe Gitlab::UsageData do ...@@ -95,6 +96,8 @@ describe Gitlab::UsageData do
projects projects
projects_imported_from_github projects_imported_from_github
projects_jira_active projects_jira_active
projects_jira_server_active
projects_jira_cloud_active
projects_slack_notifications_active projects_slack_notifications_active
projects_slack_slash_active projects_slack_slash_active
projects_prometheus_active projects_prometheus_active
...@@ -114,7 +117,9 @@ describe Gitlab::UsageData do ...@@ -114,7 +117,9 @@ describe Gitlab::UsageData do
expect(count_data[:projects]).to eq(3) expect(count_data[:projects]).to eq(3)
expect(count_data[:projects_prometheus_active]).to eq(1) 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_notifications_active]).to eq(2)
expect(count_data[:projects_slack_slash_active]).to eq(1) expect(count_data[:projects_slack_slash_active]).to eq(1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment