Commit e011088c authored by Justin Ho Tuan Duong's avatar Justin Ho Tuan Duong Committed by Dmitriy Zaporozhets

Add usage ping data for project services

- Add new scope to Services to make it easy to reuse
- Add new structure of usage counts
parent 88c0cce6
...@@ -40,6 +40,7 @@ class Service < ApplicationRecord ...@@ -40,6 +40,7 @@ class Service < ApplicationRecord
scope :external_wikis, -> { where(type: 'ExternalWikiService').active } scope :external_wikis, -> { where(type: 'ExternalWikiService').active }
scope :active, -> { where(active: true) } scope :active, -> { where(active: true) }
scope :without_defaults, -> { where(default: false) } scope :without_defaults, -> { where(default: false) }
scope :by_type, -> (type) { where(type: type) }
scope :push_hooks, -> { where(push_events: true, active: true) } scope :push_hooks, -> { where(push_events: true, active: true) }
scope :tag_push_hooks, -> { where(tag_push_events: true, active: true) } scope :tag_push_hooks, -> { where(tag_push_events: true, active: true) }
......
---
title: Add usage ping data for project services
merge_request: 19687
author:
type: added
...@@ -13,7 +13,8 @@ module Gitlab ...@@ -13,7 +13,8 @@ module Gitlab
end end
def uncached_data def uncached_data
license_usage_data.merge(system_usage_data) license_usage_data
.merge(system_usage_data)
.merge(features_usage_data) .merge(features_usage_data)
.merge(components_usage_data) .merge(components_usage_data)
.merge(cycle_analytics_usage_data) .merge(cycle_analytics_usage_data)
...@@ -170,10 +171,13 @@ module Gitlab ...@@ -170,10 +171,13 @@ module Gitlab
types = { types = {
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,
CustomIssueTrackerService: :projects_custom_issue_tracker_active,
JenkinsService: :projects_jenkins_active,
MattermostService: :projects_mattermost_active
} }
results = count(Service.unscoped.where(type: types.keys, active: true).group(:type), fallback: Hash.new(-1)) 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 } types.each_with_object({}) { |(klass, key), response| response[key] = results[klass.to_s] || 0 }
.merge(jira_usage) .merge(jira_usage)
end end
...@@ -188,8 +192,8 @@ module Gitlab ...@@ -188,8 +192,8 @@ module Gitlab
projects_jira_active: -1 projects_jira_active: -1
} }
Service.unscoped Service.active
.where(type: :JiraService, active: true) .by_type(:JiraService)
.includes(:jira_tracker_data) .includes(:jira_tracker_data)
.find_in_batches(batch_size: BATCH_SIZE) do |services| .find_in_batches(batch_size: BATCH_SIZE) do |services|
......
...@@ -17,6 +17,9 @@ describe Gitlab::UsageData do ...@@ -17,6 +17,9 @@ describe Gitlab::UsageData do
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)
create(:service, project: projects[2], type: 'SlackService', active: true) create(:service, project: projects[2], type: 'SlackService', active: true)
create(:service, project: projects[2], type: 'MattermostService', active: true)
create(:service, project: projects[2], type: 'JenkinsService', active: true)
create(:service, project: projects[2], type: 'CustomIssueTrackerService', active: true)
create(:project_error_tracking_setting, project: projects[0]) create(:project_error_tracking_setting, project: projects[0])
create(:project_error_tracking_setting, project: projects[1], enabled: false) create(:project_error_tracking_setting, project: projects[1], enabled: false)
create_list(:issue, 4, project: projects[0]) create_list(:issue, 4, project: projects[0])
...@@ -157,6 +160,9 @@ describe Gitlab::UsageData do ...@@ -157,6 +160,9 @@ describe Gitlab::UsageData do
projects_jira_cloud_active projects_jira_cloud_active
projects_slack_notifications_active projects_slack_notifications_active
projects_slack_slash_active projects_slack_slash_active
projects_custom_issue_tracker_active
projects_jenkins_active
projects_mattermost_active
projects_prometheus_active projects_prometheus_active
projects_with_repositories_enabled projects_with_repositories_enabled
projects_with_error_tracking_enabled projects_with_error_tracking_enabled
...@@ -190,6 +196,9 @@ describe Gitlab::UsageData do ...@@ -190,6 +196,9 @@ describe Gitlab::UsageData do
expect(count_data[:projects_jira_cloud_active]).to eq(2) expect(count_data[:projects_jira_cloud_active]).to eq(2)
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)
expect(count_data[:projects_custom_issue_tracker_active]).to eq(1)
expect(count_data[:projects_jenkins_active]).to eq(1)
expect(count_data[:projects_mattermost_active]).to eq(1)
expect(count_data[:projects_with_repositories_enabled]).to eq(3) expect(count_data[:projects_with_repositories_enabled]).to eq(3)
expect(count_data[:projects_with_error_tracking_enabled]).to eq(1) expect(count_data[:projects_with_error_tracking_enabled]).to eq(1)
expect(count_data[:issues_with_associated_zoom_link]).to eq(2) expect(count_data[:issues_with_associated_zoom_link]).to eq(2)
......
...@@ -15,6 +15,26 @@ describe Service do ...@@ -15,6 +15,26 @@ describe Service do
end end
describe 'Scopes' do describe 'Scopes' do
describe '.by_type' do
let!(:service1) { create(:jira_service) }
let!(:service2) { create(:jira_service) }
let!(:service3) { create(:redmine_service) }
subject { described_class.by_type(type) }
context 'when type is "JiraService"' do
let(:type) { 'JiraService' }
it { is_expected.to match_array([service1, service2]) }
end
context 'when type is "RedmineService"' do
let(:type) { 'RedmineService' }
it { is_expected.to match_array([service3]) }
end
end
describe '.confidential_note_hooks' do describe '.confidential_note_hooks' do
it 'includes services where confidential_note_events is true' do it 'includes services where confidential_note_events is true' do
create(:service, active: true, confidential_note_events: true) create(:service, active: true, confidential_note_events: true)
......
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