From f5f2c726e461e5bfd0df1bd4d6125d1ca2c6a8ec Mon Sep 17 00:00:00 2001 From: "j.seto" Date: Wed, 10 May 2023 12:41:45 -0400 Subject: [PATCH 1/3] Add service ping metrics for workspaces - Add metrics for tracking create and update of workspaces - Add metric for count of workspaces per project Contributes to: https://gitlab.com/gitlab-org/gitlab/-/issues/408221 --- .../remote_development/workspaces/create.rb | 4 ++++ .../remote_development/workspaces/update.rb | 4 ++++ ...1628_users_updating_workspaces_monthly.yml | 22 ++++++++++++++++++ ...1855_users_creating_workspaces_monthly.yml | 23 +++++++++++++++++++ ...81628_users_updating_workspaces_weekly.yml | 23 +++++++++++++++++++ ...81854_users_creating_workspaces_weekly.yml | 23 +++++++++++++++++++ ...0510151446_remote_agent_configurations.yml | 21 +++++++++++++++++ .../counts_all/20230510152124_workspaces.yml | 20 ++++++++++++++++ ...ount_remote_agent_configurations_metric.rb | 19 +++++++++++++++ .../count_workspaces_metric.rb | 15 ++++++++++++ .../metrics/every_metric_definition_spec.rb | 2 +- ...remote_agent_configurations_metric_spec.rb | 18 +++++++++++++++ .../count_workspaces_metric_spec.rb | 14 +++++++++++ .../known_events/workspaces.yml | 5 ++++ 14 files changed, 212 insertions(+), 1 deletion(-) create mode 100644 ee/config/metrics/counts_28d/20230510181628_users_updating_workspaces_monthly.yml create mode 100644 ee/config/metrics/counts_28d/20230510181855_users_creating_workspaces_monthly.yml create mode 100644 ee/config/metrics/counts_7d/20230510181628_users_updating_workspaces_weekly.yml create mode 100644 ee/config/metrics/counts_7d/20230510181854_users_creating_workspaces_weekly.yml create mode 100644 ee/config/metrics/counts_all/20230510151446_remote_agent_configurations.yml create mode 100644 ee/config/metrics/counts_all/20230510152124_workspaces.yml create mode 100644 ee/lib/gitlab/usage/metrics/instrumentations/count_remote_agent_configurations_metric.rb create mode 100644 ee/lib/gitlab/usage/metrics/instrumentations/count_workspaces_metric.rb create mode 100644 ee/spec/lib/gitlab/usage/metrics/instrumentations/count_remote_agent_configurations_metric_spec.rb create mode 100644 ee/spec/lib/gitlab/usage/metrics/instrumentations/count_workspaces_metric_spec.rb create mode 100644 lib/gitlab/usage_data_counters/known_events/workspaces.yml diff --git a/ee/app/graphql/mutations/remote_development/workspaces/create.rb b/ee/app/graphql/mutations/remote_development/workspaces/create.rb index 20babd00f6fa1d..55c145a71d7373 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 5e865aa9e6bc5f..6e3b1bfddecc56 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 00000000000000..419385d426d70c --- /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 creating or 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 00000000000000..e1dc1807426c19 --- /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 00000000000000..ca143e0f41ce3a --- /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 00000000000000..1cc595cbeefa5a --- /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 00000000000000..631d46095806d6 --- /dev/null +++ b/ee/config/metrics/counts_all/20230510151446_remote_agent_configurations.yml @@ -0,0 +1,21 @@ +--- +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: +#- premium +- 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 00000000000000..c0d0444b2b302e --- /dev/null +++ b/ee/config/metrics/counts_all/20230510152124_workspaces.yml @@ -0,0 +1,20 @@ +--- +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: +#- premium +- 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 00000000000000..3dcf2626709182 --- /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 00000000000000..55f3b9ab320962 --- /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 36666a8e42b387..b8ab32f4becb72 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 00000000000000..4f4fb7b3579f0f --- /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 00000000000000..a46fffea0de7f1 --- /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 00000000000000..8a96524b167287 --- /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 -- GitLab From e3ceef90438a4c00babc3539b4ddecbed0f6ea7e Mon Sep 17 00:00:00 2001 From: "j.seto" Date: Fri, 12 May 2023 10:53:20 -0400 Subject: [PATCH 2/3] Fix metric description --- .../20230510181628_users_updating_workspaces_monthly.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 419385d426d70c..33119d51ddb7ca 100644 --- a/ee/config/metrics/counts_28d/20230510181628_users_updating_workspaces_monthly.yml +++ b/ee/config/metrics/counts_28d/20230510181628_users_updating_workspaces_monthly.yml @@ -1,6 +1,6 @@ --- key_path: redis_hll_counters.workspaces.users_updating_workspaces_monthly -description: Count of users creating or updating workspaces +description: Count of users updating workspaces product_section: dev product_stage: create product_group: ide -- GitLab From e3bcde23f16c4cd6b20d6ac56d3a8784ea9f47fc Mon Sep 17 00:00:00 2001 From: "j.seto" Date: Fri, 12 May 2023 11:16:52 -0400 Subject: [PATCH 3/3] Remove some comments --- .../counts_all/20230510151446_remote_agent_configurations.yml | 1 - ee/config/metrics/counts_all/20230510152124_workspaces.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/ee/config/metrics/counts_all/20230510151446_remote_agent_configurations.yml b/ee/config/metrics/counts_all/20230510151446_remote_agent_configurations.yml index 631d46095806d6..63daf3756942c3 100644 --- a/ee/config/metrics/counts_all/20230510151446_remote_agent_configurations.yml +++ b/ee/config/metrics/counts_all/20230510151446_remote_agent_configurations.yml @@ -17,5 +17,4 @@ performance_indicator_type: [] distribution: - ee tier: -#- premium - ultimate diff --git a/ee/config/metrics/counts_all/20230510152124_workspaces.yml b/ee/config/metrics/counts_all/20230510152124_workspaces.yml index c0d0444b2b302e..ed5ee900326779 100644 --- a/ee/config/metrics/counts_all/20230510152124_workspaces.yml +++ b/ee/config/metrics/counts_all/20230510152124_workspaces.yml @@ -16,5 +16,4 @@ performance_indicator_type: [] distribution: - ee tier: -#- premium - ultimate -- GitLab