diff --git a/ee/app/graphql/mutations/remote_development/workspaces/create.rb b/ee/app/graphql/mutations/remote_development/workspaces/create.rb index 20babd00f6fa1d383283d8305ec5c96237172fbf..55c145a71d7373540c4be5cbcd3910bbed7ca3f8 100644 --- a/ee/app/graphql/mutations/remote_development/workspaces/create.rb +++ b/ee/app/graphql/mutations/remote_development/workspaces/create.rb @@ -7,6 +7,8 @@ module Workspaces class Create < BaseMutation graphql_name 'WorkspaceCreate' + include Gitlab::Utils::UsageData + authorize :create_workspace field :workspace, @@ -66,6 +68,8 @@ def resolve(args) agent = authorized_find!(id: cluster_agent_id) + track_usage_event(:users_creating_workspaces, current_user.id) + service = ::RemoteDevelopment::Workspaces::CreateService.new(current_user: current_user) params = args.merge(agent: agent, user: current_user, project: project) response = service.execute(params: params) diff --git a/ee/app/graphql/mutations/remote_development/workspaces/update.rb b/ee/app/graphql/mutations/remote_development/workspaces/update.rb index 5e865aa9e6bc5f2311ecfccc86ca0563ab743327..6e3b1bfddecc568f395eb993614be16f44b481fa 100644 --- a/ee/app/graphql/mutations/remote_development/workspaces/update.rb +++ b/ee/app/graphql/mutations/remote_development/workspaces/update.rb @@ -6,6 +6,8 @@ module Workspaces class Update < BaseMutation graphql_name 'WorkspaceUpdate' + include Gitlab::Utils::UsageData + authorize :update_workspace field :workspace, @@ -34,6 +36,8 @@ def resolve(id:, **args) workspace = authorized_find!(id: id) + track_usage_event(:users_updating_workspaces, current_user.id) + service = ::RemoteDevelopment::Workspaces::UpdateService.new(current_user: current_user) response = service.execute(workspace: workspace, params: args) diff --git a/ee/config/metrics/counts_28d/20230510181628_users_updating_workspaces_monthly.yml b/ee/config/metrics/counts_28d/20230510181628_users_updating_workspaces_monthly.yml new file mode 100644 index 0000000000000000000000000000000000000000..33119d51ddb7caec45abbade2d297163e9250a4c --- /dev/null +++ b/ee/config/metrics/counts_28d/20230510181628_users_updating_workspaces_monthly.yml @@ -0,0 +1,22 @@ +--- +key_path: redis_hll_counters.workspaces.users_updating_workspaces_monthly +description: Count of users updating workspaces +product_section: dev +product_stage: create +product_group: ide +value_type: number +status: active +milestone: "16.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/120341 +time_frame: 28d +data_source: redis_hll +data_category: optional +instrumentation_class: RedisHLLMetric +performance_indicator_type: [] +distribution: +- ee +tier: +- ultimate +options: + events: + - users_updating_workspaces diff --git a/ee/config/metrics/counts_28d/20230510181855_users_creating_workspaces_monthly.yml b/ee/config/metrics/counts_28d/20230510181855_users_creating_workspaces_monthly.yml new file mode 100644 index 0000000000000000000000000000000000000000..e1dc1807426c1919c680eb02a07251a0a77dbaca --- /dev/null +++ b/ee/config/metrics/counts_28d/20230510181855_users_creating_workspaces_monthly.yml @@ -0,0 +1,23 @@ +--- +key_path: redis_hll_counters.workspaces.users_creating_workspaces_monthly +name: "count_users_creating_workspaces_monthly" +description: Count of users creating workspaces +product_section: dev +product_stage: create +product_group: ide +value_type: number +status: active +milestone: "16.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/120341 +time_frame: 28d +data_source: redis_hll +data_category: optional +instrumentation_class: RedisHLLMetric +performance_indicator_type: [] +distribution: +- ee +tier: +- ultimate +options: + events: + - users_creating_workspaces diff --git a/ee/config/metrics/counts_7d/20230510181628_users_updating_workspaces_weekly.yml b/ee/config/metrics/counts_7d/20230510181628_users_updating_workspaces_weekly.yml new file mode 100644 index 0000000000000000000000000000000000000000..ca143e0f41ce3ad7e4988e3e7104b88ad6f68146 --- /dev/null +++ b/ee/config/metrics/counts_7d/20230510181628_users_updating_workspaces_weekly.yml @@ -0,0 +1,23 @@ +--- +key_path: redis_hll_counters.workspaces.users_updating_workspaces_weekly +name: "count_users_updating_workspaces_weekly" +description: Count of users updating workspaces +product_section: dev +product_stage: create +product_group: ide +value_type: number +status: active +milestone: "16.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/120341 +time_frame: 7d +data_source: redis_hll +data_category: optional +instrumentation_class: RedisHLLMetric +performance_indicator_type: [] +distribution: +- ee +tier: +- ultimate +options: + events: + - users_updating_workspaces diff --git a/ee/config/metrics/counts_7d/20230510181854_users_creating_workspaces_weekly.yml b/ee/config/metrics/counts_7d/20230510181854_users_creating_workspaces_weekly.yml new file mode 100644 index 0000000000000000000000000000000000000000..1cc595cbeefa5a2e24ce88daf2a102b383d8e310 --- /dev/null +++ b/ee/config/metrics/counts_7d/20230510181854_users_creating_workspaces_weekly.yml @@ -0,0 +1,23 @@ +--- +key_path: redis_hll_counters.workspaces.users_creating_workspaces_weekly +name: "count_users_creating_workspaces_weekly" +description: Count of users creating workspaces +product_section: dev +product_stage: create +product_group: ide +value_type: number +status: active +milestone: "16.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/120341 +time_frame: 7d +data_source: redis_hll +data_category: optional +instrumentation_class: RedisHLLMetric +performance_indicator_type: [] +distribution: +- ee +tier: +- ultimate +options: + events: + - users_creating_workspaces diff --git a/ee/config/metrics/counts_all/20230510151446_remote_agent_configurations.yml b/ee/config/metrics/counts_all/20230510151446_remote_agent_configurations.yml new file mode 100644 index 0000000000000000000000000000000000000000..63daf3756942c378c60fb52ebbb01ae9a6c60680 --- /dev/null +++ b/ee/config/metrics/counts_all/20230510151446_remote_agent_configurations.yml @@ -0,0 +1,20 @@ +--- +key_path: counts.remote_agent_configurations +name: "count_remote_agent_configurations" +description: Count of remote agent configurations +product_section: dev +product_stage: create +product_group: ide +value_type: number +status: active +milestone: "16.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/120341 +time_frame: all +data_source: database +data_category: optional +instrumentation_class: CountRemoteAgentConfigurationsMetric +performance_indicator_type: [] +distribution: +- ee +tier: +- ultimate diff --git a/ee/config/metrics/counts_all/20230510152124_workspaces.yml b/ee/config/metrics/counts_all/20230510152124_workspaces.yml new file mode 100644 index 0000000000000000000000000000000000000000..ed5ee900326779121a71c7fb6eb7a678789a1a30 --- /dev/null +++ b/ee/config/metrics/counts_all/20230510152124_workspaces.yml @@ -0,0 +1,19 @@ +--- +key_path: counts.workspaces +description: Count of workspaces +product_section: dev +product_stage: create +product_group: ide +value_type: number +status: active +milestone: "16.0" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/120341 +time_frame: all +data_source: database +data_category: optional +instrumentation_class: CountWorkspacesMetric +performance_indicator_type: [] +distribution: +- ee +tier: +- ultimate diff --git a/ee/lib/gitlab/usage/metrics/instrumentations/count_remote_agent_configurations_metric.rb b/ee/lib/gitlab/usage/metrics/instrumentations/count_remote_agent_configurations_metric.rb new file mode 100644 index 0000000000000000000000000000000000000000..3dcf26267091822f601e4ab6212cb42b2e2fed0c --- /dev/null +++ b/ee/lib/gitlab/usage/metrics/instrumentations/count_remote_agent_configurations_metric.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Gitlab + module Usage + module Metrics + module Instrumentations + class CountRemoteAgentConfigurationsMetric < DatabaseMetric + operation :distinct_count, column: :cluster_agent_id + + # TODO: Do we only want to consider agents that have successfully connected? + relation { RemoteDevelopment::RemoteDevelopmentAgentConfig } + + start { RemoteDevelopment::RemoteDevelopmentAgentConfig.minimum(:cluster_agent_id) } + finish { RemoteDevelopment::RemoteDevelopmentAgentConfig.maximum(:cluster_agent_id) } + end + end + end + end +end diff --git a/ee/lib/gitlab/usage/metrics/instrumentations/count_workspaces_metric.rb b/ee/lib/gitlab/usage/metrics/instrumentations/count_workspaces_metric.rb new file mode 100644 index 0000000000000000000000000000000000000000..55f3b9ab320962c1a9a0ddcc504e2babd2ff4ccb --- /dev/null +++ b/ee/lib/gitlab/usage/metrics/instrumentations/count_workspaces_metric.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module Gitlab + module Usage + module Metrics + module Instrumentations + class CountWorkspacesMetric < DatabaseMetric + operation :count + + relation { RemoteDevelopment::Workspace } # rubocop: disable CodeReuse/ActiveRecord + end + end + end + end +end diff --git a/ee/spec/config/metrics/every_metric_definition_spec.rb b/ee/spec/config/metrics/every_metric_definition_spec.rb index 36666a8e42b3870666ea9c23495229b6f3ba85f0..b8ab32f4becb7206134c914ed4e164e877c019b4 100644 --- a/ee/spec/config/metrics/every_metric_definition_spec.rb +++ b/ee/spec/config/metrics/every_metric_definition_spec.rb @@ -5,7 +5,7 @@ RSpec.describe 'Every metric definition', feature_category: :service_ping do include UsageDataHelpers - let(:usage_ping) { Gitlab::Usage::ServicePingReport.for(output: :all_metrics_values) } + let(:usage_ping) { Gitlab::Usage::ServicePingReport.for(output: :all_metrics_values, cached: false) } let(:ignored_usage_ping_key_patterns) do %w( license_add_ons diff --git a/ee/spec/lib/gitlab/usage/metrics/instrumentations/count_remote_agent_configurations_metric_spec.rb b/ee/spec/lib/gitlab/usage/metrics/instrumentations/count_remote_agent_configurations_metric_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..4f4fb7b3579f0fc64d5adbc25ff59e6fad7d22f1 --- /dev/null +++ b/ee/spec/lib/gitlab/usage/metrics/instrumentations/count_remote_agent_configurations_metric_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountRemoteAgentConfigurationsMetric, feature_category: :remote_development do + before do + configs = create_list(:remote_development_agent_config, 2) + create(:remote_development_agent_config, cluster_agent_id: configs[0].cluster_agent_id) + end + + it_behaves_like 'a correct instrumented metric value and query', { time_frame: 'all', data_source: 'database' } do + let(:expected_value) { 2 } + let(:expected_query) do + 'SELECT COUNT(DISTINCT "remote_development_agent_configs"."cluster_agent_id") ' \ + 'FROM "remote_development_agent_configs"' + end + end +end diff --git a/ee/spec/lib/gitlab/usage/metrics/instrumentations/count_workspaces_metric_spec.rb b/ee/spec/lib/gitlab/usage/metrics/instrumentations/count_workspaces_metric_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..a46fffea0de7f11747696e6faa1b950719707771 --- /dev/null +++ b/ee/spec/lib/gitlab/usage/metrics/instrumentations/count_workspaces_metric_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountWorkspacesMetric, feature_category: :remote_development do + let_it_be(:workspace) { create(:workspace) } + + it_behaves_like 'a correct instrumented metric value and query', { time_frame: 'all', data_source: 'database' } do + let(:expected_value) { 1 } + let(:expected_query) do + %{SELECT COUNT("workspaces"."id") FROM "workspaces"} + end + end +end diff --git a/lib/gitlab/usage_data_counters/known_events/workspaces.yml b/lib/gitlab/usage_data_counters/known_events/workspaces.yml new file mode 100644 index 0000000000000000000000000000000000000000..8a96524b167287db9c94d62b57cda6edb73c2572 --- /dev/null +++ b/lib/gitlab/usage_data_counters/known_events/workspaces.yml @@ -0,0 +1,5 @@ +- name: users_updating_workspaces + aggregation: weekly + +- name: users_creating_workspaces + aggregation: weekly