2017-04-05 12:29:48 +00:00
|
|
|
module Gitlab
|
|
|
|
class UsageData
|
|
|
|
class << self
|
2016-10-19 21:29:01 +00:00
|
|
|
def data(force_refresh: false)
|
|
|
|
Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) { uncached_data }
|
2017-04-05 12:29:48 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def uncached_data
|
|
|
|
license_usage_data.merge(system_usage_data)
|
2017-09-15 16:23:56 +00:00
|
|
|
.merge(features_usage_data)
|
|
|
|
.merge(components_usage_data)
|
2018-01-30 11:28:15 +00:00
|
|
|
.merge(cycle_analytics_usage_data)
|
2017-04-05 12:29:48 +00:00
|
|
|
end
|
|
|
|
|
2016-10-19 21:29:01 +00:00
|
|
|
def to_json(force_refresh: false)
|
|
|
|
data(force_refresh: force_refresh).to_json
|
2017-04-05 12:29:48 +00:00
|
|
|
end
|
|
|
|
|
2017-09-15 16:23:56 +00:00
|
|
|
def license_usage_data
|
|
|
|
usage_data = {
|
2018-02-02 18:39:55 +00:00
|
|
|
uuid: Gitlab::CurrentSettings.uuid,
|
2017-09-15 16:23:56 +00:00
|
|
|
hostname: Gitlab.config.gitlab.host,
|
|
|
|
version: Gitlab::VERSION,
|
2018-06-07 15:01:20 +00:00
|
|
|
installation_type: Gitlab::INSTALLATION_TYPE,
|
2017-09-15 16:23:56 +00:00
|
|
|
active_user_count: User.active.count,
|
|
|
|
recorded_at: Time.now,
|
|
|
|
edition: 'CE'
|
|
|
|
}
|
|
|
|
|
|
|
|
usage_data
|
|
|
|
end
|
|
|
|
|
2018-03-22 11:23:59 +00:00
|
|
|
# rubocop:disable Metrics/AbcSize
|
2017-04-05 12:29:48 +00:00
|
|
|
def system_usage_data
|
|
|
|
{
|
|
|
|
counts: {
|
|
|
|
boards: Board.count,
|
|
|
|
ci_builds: ::Ci::Build.count,
|
2017-06-19 17:56:27 +00:00
|
|
|
ci_internal_pipelines: ::Ci::Pipeline.internal.count,
|
|
|
|
ci_external_pipelines: ::Ci::Pipeline.external.count,
|
2017-09-08 17:38:02 +00:00
|
|
|
ci_pipeline_config_auto_devops: ::Ci::Pipeline.auto_devops_source.count,
|
|
|
|
ci_pipeline_config_repository: ::Ci::Pipeline.repository_source.count,
|
2017-04-05 12:29:48 +00:00
|
|
|
ci_runners: ::Ci::Runner.count,
|
|
|
|
ci_triggers: ::Ci::Trigger.count,
|
2017-05-07 22:35:56 +00:00
|
|
|
ci_pipeline_schedules: ::Ci::PipelineSchedule.count,
|
2017-09-12 10:33:48 +00:00
|
|
|
auto_devops_enabled: ::ProjectAutoDevops.enabled.count,
|
|
|
|
auto_devops_disabled: ::ProjectAutoDevops.disabled.count,
|
2017-04-05 12:29:48 +00:00
|
|
|
deploy_keys: DeployKey.count,
|
|
|
|
deployments: Deployment.count,
|
2017-08-07 13:54:30 +00:00
|
|
|
environments: ::Environment.count,
|
2017-11-01 07:12:44 +00:00
|
|
|
clusters: ::Clusters::Cluster.count,
|
|
|
|
clusters_enabled: ::Clusters::Cluster.enabled.count,
|
|
|
|
clusters_disabled: ::Clusters::Cluster.disabled.count,
|
2018-03-30 15:34:10 +00:00
|
|
|
clusters_platforms_gke: ::Clusters::Cluster.gcp_installed.enabled.count,
|
2018-03-29 19:26:12 +00:00
|
|
|
clusters_platforms_user: ::Clusters::Cluster.user_provided.enabled.count,
|
|
|
|
clusters_applications_helm: ::Clusters::Applications::Helm.installed.count,
|
|
|
|
clusters_applications_ingress: ::Clusters::Applications::Ingress.installed.count,
|
|
|
|
clusters_applications_prometheus: ::Clusters::Applications::Prometheus.installed.count,
|
|
|
|
clusters_applications_runner: ::Clusters::Applications::Runner.installed.count,
|
2017-08-07 13:54:30 +00:00
|
|
|
in_review_folder: ::Environment.in_review_folder.count,
|
2017-04-05 12:29:48 +00:00
|
|
|
groups: Group.count,
|
|
|
|
issues: Issue.count,
|
|
|
|
keys: Key.count,
|
|
|
|
labels: Label.count,
|
|
|
|
lfs_objects: LfsObject.count,
|
|
|
|
merge_requests: MergeRequest.count,
|
|
|
|
milestones: Milestone.count,
|
|
|
|
notes: Note.count,
|
|
|
|
pages_domains: PagesDomain.count,
|
|
|
|
projects: Project.count,
|
2017-07-19 07:07:17 +00:00
|
|
|
projects_imported_from_github: Project.where(import_type: 'github').count,
|
2017-04-05 12:29:48 +00:00
|
|
|
protected_branches: ProtectedBranch.count,
|
|
|
|
releases: Release.count,
|
2018-05-03 12:55:14 +00:00
|
|
|
remote_mirrors: RemoteMirror.count,
|
2017-04-05 12:29:48 +00:00
|
|
|
snippets: Snippet.count,
|
|
|
|
todos: Todo.count,
|
2017-03-09 16:00:25 +00:00
|
|
|
uploads: Upload.count,
|
2017-04-05 12:29:48 +00:00
|
|
|
web_hooks: WebHook.count
|
2017-07-19 14:45:28 +00:00
|
|
|
}.merge(services_usage)
|
2017-04-05 12:29:48 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-30 11:28:15 +00:00
|
|
|
def cycle_analytics_usage_data
|
2018-02-15 13:23:39 +00:00
|
|
|
Gitlab::CycleAnalytics::UsageData.new.to_json
|
2018-01-30 11:28:15 +00:00
|
|
|
end
|
|
|
|
|
2017-09-15 16:23:56 +00:00
|
|
|
def features_usage_data
|
|
|
|
features_usage_data_ce
|
|
|
|
end
|
|
|
|
|
|
|
|
def features_usage_data_ce
|
|
|
|
{
|
2018-06-20 17:16:14 +00:00
|
|
|
container_registry_enabled: Gitlab.config.registry.enabled,
|
|
|
|
gitlab_shared_runners_enabled: Gitlab.config.gitlab_ci.shared_runners_enabled,
|
|
|
|
gravatar_enabled: Gitlab::CurrentSettings.gravatar_enabled?,
|
|
|
|
ldap_enabled: Gitlab.config.ldap.enabled,
|
|
|
|
mattermost_enabled: Gitlab.config.mattermost.enabled,
|
|
|
|
omniauth_enabled: Gitlab.config.omniauth.enabled,
|
|
|
|
reply_by_email_enabled: Gitlab::IncomingEmail.enabled?,
|
|
|
|
signup_enabled: Gitlab::CurrentSettings.allow_signup?
|
2017-04-06 19:16:57 +00:00
|
|
|
}
|
2017-09-15 16:23:56 +00:00
|
|
|
end
|
2017-04-05 12:29:48 +00:00
|
|
|
|
2017-09-15 16:23:56 +00:00
|
|
|
def components_usage_data
|
|
|
|
{
|
|
|
|
gitlab_pages: { enabled: Gitlab.config.pages.enabled, version: Gitlab::Pages::VERSION },
|
|
|
|
git: { version: Gitlab::Git.version },
|
|
|
|
database: { adapter: Gitlab::Database.adapter_name, version: Gitlab::Database.version }
|
|
|
|
}
|
2017-04-05 12:29:48 +00:00
|
|
|
end
|
2017-07-19 14:45:28 +00:00
|
|
|
|
|
|
|
def services_usage
|
|
|
|
types = {
|
|
|
|
JiraService: :projects_jira_active,
|
|
|
|
SlackService: :projects_slack_notifications_active,
|
|
|
|
SlackSlashCommandsService: :projects_slack_slash_active,
|
|
|
|
PrometheusService: :projects_prometheus_active
|
|
|
|
}
|
|
|
|
|
|
|
|
results = Service.unscoped.where(type: types.keys, active: true).group(:type).count
|
|
|
|
results.each_with_object({}) { |(key, value), response| response[types[key.to_sym]] = value }
|
|
|
|
end
|
2017-04-05 12:29:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|