Commit c6ef87c5 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '36235-services-usage-ping' into 'master'

Add remaining project services to usage ping

See merge request gitlab-org/gitlab!21843
parents dddefcf5 10a174b5
---
title: Add remaining project services to usage ping
merge_request: 21843
author:
type: added
...@@ -26,6 +26,7 @@ describe Gitlab::UsageData do ...@@ -26,6 +26,7 @@ describe Gitlab::UsageData do
create(:alerts_service, project: projects[0]) create(:alerts_service, project: projects[0])
create(:alerts_service, :inactive, project: projects[1]) create(:alerts_service, :inactive, project: projects[1])
create(:service, project: projects[1], type: 'JenkinsService', active: true)
create(:package, project: projects[0]) create(:package, project: projects[0])
create(:package, project: projects[0]) create(:package, project: projects[0])
...@@ -79,6 +80,7 @@ describe Gitlab::UsageData do ...@@ -79,6 +80,7 @@ describe Gitlab::UsageData do
operations_dashboard_default_dashboard operations_dashboard_default_dashboard
operations_dashboard_users_with_projects_added operations_dashboard_users_with_projects_added
pod_logs_usages_total pod_logs_usages_total
projects_jenkins_active
projects_jira_dvcs_cloud_active projects_jira_dvcs_cloud_active
projects_jira_dvcs_server_active projects_jira_dvcs_server_active
projects_mirrored_with_pipelines_enabled projects_mirrored_with_pipelines_enabled
...@@ -96,6 +98,7 @@ describe Gitlab::UsageData do ...@@ -96,6 +98,7 @@ describe Gitlab::UsageData do
template_repositories template_repositories
)) ))
expect(count_data[:projects_jenkins_active]).to eq(1)
expect(count_data[:projects_with_prometheus_alerts]).to eq(2) expect(count_data[:projects_with_prometheus_alerts]).to eq(2)
expect(count_data[:projects_with_packages]).to eq(2) expect(count_data[:projects_with_packages]).to eq(2)
expect(count_data[:feature_flags]).to eq(1) expect(count_data[:feature_flags]).to eq(1)
......
...@@ -178,18 +178,17 @@ module Gitlab ...@@ -178,18 +178,17 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def services_usage def services_usage
types = { service_counts = count(Service.active.where(template: false).where.not(type: 'JiraService').group(:type), fallback: Hash.new(-1))
SlackService: :projects_slack_notifications_active,
SlackSlashCommandsService: :projects_slack_slash_active, results = Service.available_services_names.each_with_object({}) do |service_name, response|
PrometheusService: :projects_prometheus_active, response["projects_#{service_name}_active".to_sym] = service_counts["#{service_name}_service".camelize] || 0
CustomIssueTrackerService: :projects_custom_issue_tracker_active, end
JenkinsService: :projects_jenkins_active,
MattermostService: :projects_mattermost_active
}
results = count(Service.active.by_type(types.keys).group(:type), fallback: Hash.new(-1)) # Keep old Slack keys for backward compatibility, https://gitlab.com/gitlab-data/analytics/issues/3241
types.each_with_object({}) { |(klass, key), response| response[key] = results[klass.to_s] || 0 } results[:projects_slack_notifications_active] = results[:projects_slack_active]
.merge(jira_usage) results[:projects_slack_slash_active] = results[:projects_slack_slash_commands_active]
results.merge(jira_usage)
end end
def jira_usage def jira_usage
...@@ -223,6 +222,7 @@ module Gitlab ...@@ -223,6 +222,7 @@ module Gitlab
results results
end end
# rubocop: enable CodeReuse/ActiveRecord
def user_preferences_usage def user_preferences_usage
{} # augmented in EE {} # augmented in EE
...@@ -233,7 +233,6 @@ module Gitlab ...@@ -233,7 +233,6 @@ module Gitlab
rescue ActiveRecord::StatementInvalid rescue ActiveRecord::StatementInvalid
fallback fallback
end end
# rubocop: enable CodeReuse/ActiveRecord
def approximate_counts def approximate_counts
approx_counts = Gitlab::Database::Count.approximate_counts(APPROXIMATE_COUNT_MODELS) approx_counts = Gitlab::Database::Count.approximate_counts(APPROXIMATE_COUNT_MODELS)
......
...@@ -17,8 +17,8 @@ describe Gitlab::UsageData do ...@@ -17,8 +17,8 @@ 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: 'MattermostService', active: false)
create(:service, project: projects[2], type: 'JenkinsService', active: true) create(:service, project: projects[2], type: 'MattermostService', active: true, template: true)
create(:service, project: projects[2], type: 'CustomIssueTrackerService', 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)
...@@ -168,13 +168,15 @@ describe Gitlab::UsageData do ...@@ -168,13 +168,15 @@ describe Gitlab::UsageData do
pool_repositories pool_repositories
projects projects
projects_imported_from_github projects_imported_from_github
projects_asana_active
projects_jira_active projects_jira_active
projects_jira_server_active projects_jira_server_active
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_slack_active
projects_slack_slash_commands_active
projects_custom_issue_tracker_active projects_custom_issue_tracker_active
projects_jenkins_active
projects_mattermost_active projects_mattermost_active
projects_prometheus_active projects_prometheus_active
projects_with_repositories_enabled projects_with_repositories_enabled
...@@ -203,15 +205,17 @@ describe Gitlab::UsageData do ...@@ -203,15 +205,17 @@ describe Gitlab::UsageData do
count_data = subject[:counts] count_data = subject[:counts]
expect(count_data[:projects]).to eq(4) expect(count_data[:projects]).to eq(4)
expect(count_data[:projects_asana_active]).to eq(0)
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(4) expect(count_data[:projects_jira_active]).to eq(4)
expect(count_data[:projects_jira_server_active]).to eq(2) expect(count_data[:projects_jira_server_active]).to eq(2)
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_slack_active]).to eq(2)
expect(count_data[:projects_slack_slash_commands_active]).to eq(1)
expect(count_data[:projects_custom_issue_tracker_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(0)
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_created_from_gitlab_error_tracking_ui]).to eq(1) expect(count_data[:issues_created_from_gitlab_error_tracking_ui]).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