Commit fb8d93bd authored by Alper Akgun's avatar Alper Akgun

Move monitor stage usage activity to CE

Also updates the documentation
parent 6047bf27
---
title: Move monitor stage usage activity to CE
merge_request: 36067
author:
type: changed
......@@ -648,6 +648,13 @@ appear to be associated to any of the services running, since they all appear to
| `projects_slack_slash_active` | `usage_activity_by_stage` | `configure` | | EE | Unique projects with Slack '/' commands enabled |
| `projects_with_prometheus_alerts` | `usage_activity_by_stage` | `configure` | | EE | Projects with Prometheus enabled and no alerts |
| `deploy_keys` | `usage_activity_by_stage` | `create` | | | |
| `clusters` | `usage_activity_by_stage` | `monitor` | | CE+EE | |
| `clusters_applications_prometheus` | `usage_activity_by_stage` | `monitor` | | CE+EE | |
| `operations_dashboard_default_dashboard` | `usage_activity_by_stage` | `monitor` | | CE+EE | |
| `operations_dashboard_users_with_projects_added` | `usage_activity_by_stage` | `monitor` | | EE | |
| `projects_prometheus_active` | `usage_activity_by_stage` | `monitor` | | EE | |
| `projects_with_error_tracking_enabled` | `usage_activity_by_stage` | `monitor` | | EE | |
| `projects_with_tracing_enabled` | `usage_activity_by_stage` | `monitor` | | EE | |
| `keys` | `usage_activity_by_stage` | `create` | | | |
| `projects_jira_dvcs_server_active` | `usage_activity_by_stage` | `plan` | | | |
| `service_desk_enabled_projects` | `usage_activity_by_stage` | `plan` | | | |
......
......@@ -255,11 +255,6 @@ module EE
override :usage_activity_by_stage_monitor
def usage_activity_by_stage_monitor(time_period)
super.merge({
clusters: distinct_count(::Clusters::Cluster.where(time_period), :user_id),
clusters_applications_prometheus: cluster_applications_user_distinct_count(::Clusters::Applications::Prometheus, time_period),
operations_dashboard_default_dashboard: count(::User.active.with_dashboard('operations').where(time_period),
start: user_minimum_id,
finish: user_maximum_id),
operations_dashboard_users_with_projects_added: distinct_count(UsersOpsDashboardProject.joins(:user).merge(::User.active).where(time_period), :user_id),
projects_prometheus_active: distinct_count(::Project.with_active_prometheus_service.where(time_period), :creator_id),
projects_with_error_tracking_enabled: distinct_count(::Project.with_enabled_error_tracking.where(time_period), :creator_id),
......
......@@ -439,29 +439,20 @@ RSpec.describe Gitlab::UsageData do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back 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)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:monitor]).to eq(
clusters: 2,
clusters_applications_prometheus: 2,
operations_dashboard_default_dashboard: 2,
expect(described_class.uncached_data[:usage_activity_by_stage][:monitor]).to include(
operations_dashboard_users_with_projects_added: 2,
projects_prometheus_active: 2,
projects_with_error_tracking_enabled: 2,
projects_with_tracing_enabled: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:monitor]).to eq(
clusters: 1,
clusters_applications_prometheus: 1,
operations_dashboard_default_dashboard: 1,
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:monitor]).to include(
operations_dashboard_users_with_projects_added: 1,
projects_prometheus_active: 1,
projects_with_error_tracking_enabled: 1,
......
......@@ -490,9 +490,17 @@ module Gitlab
{}
end
# rubocop: disable CodeReuse/ActiveRecord
def usage_activity_by_stage_monitor(time_period)
{}
{
clusters: distinct_count(::Clusters::Cluster.where(time_period), :user_id),
clusters_applications_prometheus: cluster_applications_user_distinct_count(::Clusters::Applications::Prometheus, time_period),
operations_dashboard_default_dashboard: count(::User.active.with_dashboard('operations').where(time_period),
start: user_minimum_id,
finish: user_maximum_id)
}
end
# rubocop: enable CodeReuse/ActiveRecord
def usage_activity_by_stage_package(time_period)
{}
......
......@@ -93,6 +93,28 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
end
context 'for monitor' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user, dashboard: 'operations')
cluster = create(:cluster, user: user)
create(:project, creator: user)
create(:clusters_applications_prometheus, :installed, cluster: cluster)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:monitor]).to include(
clusters: 2,
clusters_applications_prometheus: 2,
operations_dashboard_default_dashboard: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:monitor]).to include(
clusters: 1,
clusters_applications_prometheus: 1,
operations_dashboard_default_dashboard: 1
)
end
end
it 'ensures recorded_at is set before any other usage data calculation' do
%i(alt_usage_data redis_usage_data distinct_count count).each do |method|
expect(described_class).not_to receive(method)
......
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