Commit ada51097 authored by Alex Buijs's avatar Alex Buijs

Add usage statistics data for monitor stage

Added usage activity data for monitor stage
parent 62052f6a
......@@ -7,6 +7,7 @@ module EE
prepended do
prepend HasEnvironmentScope
include UsageStatistics
validate :unique_environment_scope
end
......
......@@ -119,6 +119,9 @@ module EE
scope :with_security_reports_stored, -> { where('EXISTS (?)', ::Vulnerabilities::Occurrence.scoped_project.select(1)) }
scope :with_security_reports, -> { where('EXISTS (?)', ::Ci::JobArtifact.security_reports.scoped_project.select(1)) }
scope :with_github_service_pipeline_events, -> { joins(:github_service).merge(GithubService.pipeline_hooks) }
scope :with_active_prometheus_service, -> { joins(:prometheus_service).merge(PrometheusService.active) }
scope :with_enabled_error_tracking, -> { joins(:error_tracking_setting).where(project_error_tracking_settings: { enabled: true }) }
scope :with_tracing_enabled, -> { joins(:tracing_setting) }
delegate :shared_runners_minutes, :shared_runners_seconds, :shared_runners_seconds_last_reset,
to: :statistics, allow_nil: true
......
......@@ -185,6 +185,7 @@ module EE
usage_activity_by_stage: {
create: usage_activity_by_stage_create,
manage: usage_activity_by_stage_manage,
monitor: usage_activity_by_stage_monitor,
plan: usage_activity_by_stage_plan,
verify: usage_activity_by_stage_verify
}
......@@ -216,6 +217,18 @@ module EE
}
end
def usage_activity_by_stage_monitor
{
clusters: ::Clusters::Cluster.distinct_count_by(:user_id),
clusters_applications_prometheus: ::Clusters::Applications::Prometheus.distinct_by_user,
operations_dashboard_default_dashboard: count(::User.active.with_dashboard('operations')),
operations_dashboard_users_with_projects_added: count(UsersOpsDashboardProject.distinct_users(::User.active)),
projects_prometheus_active: ::Project.with_active_prometheus_service.distinct_count_by(:creator_id),
projects_with_error_tracking_enabled: ::Project.with_enabled_error_tracking.distinct_count_by(:creator_id),
projects_with_tracing_enabled: ::Project.with_tracing_enabled.distinct_count_by(:creator_id)
}
end
# Omitted because no user, creator or author associated: `boards`, `labels`, `milestones`, `uploads`
# Omitted because too expensive: `epics_deepest_relationship_level`
# Omitted because of encrypted properties: `projects_jira_cloud_active`, `projects_jira_server_active`
......
......@@ -39,21 +39,6 @@ describe Gitlab::UsageData do
expect(described_class.uncached_data).to include(:usage_activity_by_stage)
end
context 'for Manage' do
it 'includes accurate usage_activity_by_stage data' do
user = create(:user)
create(:group_member, user: user)
create(:key, type: 'LDAPKey', user: user)
create(:group_member, ldap: true, user: user)
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to eq(
groups: 1,
ldap_keys: 1,
ldap_users: 1
)
end
end
context 'for create' do
it 'includes accurate usage_activity_by_stage data' do
user = create(:user)
......@@ -83,6 +68,45 @@ describe Gitlab::UsageData do
end
end
context 'for manage' do
it 'includes accurate usage_activity_by_stage data' do
user = create(:user)
create(:group_member, user: user)
create(:key, type: 'LDAPKey', user: user)
create(:group_member, ldap: true, user: user)
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to eq(
groups: 1,
ldap_keys: 1,
ldap_users: 1
)
end
end
context 'for monitor' do
it 'includes accurate usage_activity_by_stage data' do
user = create(:user, dashboard: 'operations')
cluster = create(:cluster, user: user)
project = create(:project, creator: user)
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:users_ops_dashboard_project, user: user)
create(:prometheus_service, project: project)
create(:project_error_tracking_setting, project: project)
create(:project_tracing_setting, project: project)
expect(described_class.uncached_data[:usage_activity_by_stage][:monitor]).to eq(
clusters: 1,
clusters_applications_prometheus: 1,
operations_dashboard_default_dashboard: 1,
operations_dashboard_users_with_projects_added: 1,
projects_prometheus_active: 1,
projects_with_error_tracking_enabled: 1,
projects_with_tracing_enabled: 1
)
end
end
context 'for plan' do
it 'includes accurate usage_activity_by_stage data' do
stub_licensed_features(board_assignee_lists: true, board_milestone_lists: true)
......
......@@ -152,6 +152,16 @@ describe Project do
expect(described_class.with_github_service_pipeline_events).not_to include(project_without_github_service_pipeline_events)
end
end
describe '.with_active_prometheus_service' do
it 'returns the correct project' do
project_with_active_prometheus_service = create(:prometheus_project)
project_without_active_prometheus_service = create(:project)
expect(described_class.with_active_prometheus_service).to include(project_with_active_prometheus_service)
expect(described_class.with_active_prometheus_service).not_to include(project_without_active_prometheus_service)
end
end
end
describe 'validations' do
......
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