diff --git a/app/services/ci/runners/create_runner_service.rb b/app/services/ci/runners/create_runner_service.rb index 013cbec7f6a4b552761416d8df7d231d20269666..83d5f4a2d4facd5701e39ea60ece12be2e4a9d62 100644 --- a/app/services/ci/runners/create_runner_service.rb +++ b/app/services/ci/runners/create_runner_service.rb @@ -31,7 +31,7 @@ def execute runner = ::Ci::Runner.new(params) if runner.save - track_runner_event(runner) + track_runner_events(runner) return ServiceResponse.success(payload: { runner: runner }) end @@ -51,10 +51,9 @@ def normalize_params attr_reader :user, :scope, :params, :strategy - def track_runner_event(runner) - return if params[:maintenance_note].blank? - + def track_runner_events(runner) kwargs = { user: user } + case runner.runner_type when 'group_type' kwargs[:namespace] = @scope @@ -62,11 +61,22 @@ def track_runner_event(runner) kwargs[:project] = @scope end + track_internal_event( + 'create_ci_runner', + **kwargs, + additional_properties: { + label: runner.runner_type, + property: 'authenticated_user' + } + ) + + return if params[:maintenance_note].blank? + track_internal_event( 'set_runner_maintenance_note', **kwargs, additional_properties: { - label: params[:runner_type] + label: runner.runner_type } ) end diff --git a/app/services/ci/runners/register_runner_service.rb b/app/services/ci/runners/register_runner_service.rb index 58e9a96395e79bb667ca7a71b93bee9d06661564..2c35dc60ded990cfd357ea2f4dbe7abc1a585bd1 100644 --- a/app/services/ci/runners/register_runner_service.rb +++ b/app/services/ci/runners/register_runner_service.rb @@ -32,7 +32,7 @@ def execute end end - track_runner_event(runner) + track_runner_events(runner) ServiceResponse.success(payload: { runner: runner }) end @@ -89,10 +89,9 @@ def token_scope end end - def track_runner_event(runner) - return if attributes[:maintenance_note].blank? - + def track_runner_events(runner) kwargs = {} + case runner.runner_type when 'group_type' kwargs[:namespace] = token_scope @@ -101,12 +100,23 @@ def track_runner_event(runner) end track_internal_event( - 'set_runner_maintenance_note', + 'create_ci_runner', **kwargs, additional_properties: { - label: runner.runner_type + label: runner.runner_type, + property: 'registration_token' } ) + + if attributes[:maintenance_note].present? + track_internal_event( + 'set_runner_maintenance_note', + **kwargs, + additional_properties: { + label: runner.runner_type + } + ) + end end end end diff --git a/config/events/create_ci_runner.yml b/config/events/create_ci_runner.yml new file mode 100644 index 0000000000000000000000000000000000000000..ebb2e2c786cf5b0aa7d413adb3b6a948ca6bf044 --- /dev/null +++ b/config/events/create_ci_runner.yml @@ -0,0 +1,23 @@ +--- +description: Tracks the number of CI runners created +internal_events: true +action: create_ci_runner +identifiers: +- project +- namespace +- user +additional_properties: + label: + description: The runner type, which can be `project_type`, `group_type`, or `instance_type` + property: + description: Registration type, which can be `registration_token` or `authenticated_user` +product_group: runner +product_categories: +- fleet_visibility +- runner +milestone: '17.9' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/179876 +tiers: +- free +- premium +- ultimate diff --git a/config/metrics/counts_all/count_distinct_namespace_id_from_create_ci_runner.yml b/config/metrics/counts_all/count_distinct_namespace_id_from_create_ci_runner.yml new file mode 100644 index 0000000000000000000000000000000000000000..11d699560a873619ed9c670e27e439c0682712af --- /dev/null +++ b/config/metrics/counts_all/count_distinct_namespace_id_from_create_ci_runner.yml @@ -0,0 +1,24 @@ +--- +key_path: redis_hll_counters.count_distinct_namespace_id_from_create_ci_runner +description: Count of unique namespaces where a group runner was created +product_group: runner +product_categories: +- fleet_visibility +- runner +performance_indicator_type: [] +value_type: number +status: active +milestone: '17.9' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/179876 +time_frame: +- 28d +- 7d +data_source: internal_events +data_category: optional +tiers: +- free +- premium +- ultimate +events: +- name: create_ci_runner + unique: namespace.id diff --git a/config/metrics/counts_all/count_distinct_namespace_id_from_create_ci_runner_with_token.yml b/config/metrics/counts_all/count_distinct_namespace_id_from_create_ci_runner_with_token.yml new file mode 100644 index 0000000000000000000000000000000000000000..87264caeee5b92447e9cd4ab6dd789da61d56b28 --- /dev/null +++ b/config/metrics/counts_all/count_distinct_namespace_id_from_create_ci_runner_with_token.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.count_distinct_namespace_id_from_create_ci_runner_with_token +description: Count of unique groups where a group runner was created using a runner registration token +product_group: runner +product_categories: +- fleet_visibility +- runner +performance_indicator_type: [] +value_type: number +status: active +milestone: '17.9' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/179876 +time_frame: +- 28d +- 7d +data_source: internal_events +data_category: optional +tiers: +- free +- premium +- ultimate +events: +- name: create_ci_runner + unique: namespace.id + filter: + label: 'group_type' + property: 'registration_token' diff --git a/config/metrics/counts_all/count_distinct_project_id_from_create_ci_runner.yml b/config/metrics/counts_all/count_distinct_project_id_from_create_ci_runner.yml new file mode 100644 index 0000000000000000000000000000000000000000..64e260210b52706ddfabb08db08ced9b0b73a879 --- /dev/null +++ b/config/metrics/counts_all/count_distinct_project_id_from_create_ci_runner.yml @@ -0,0 +1,24 @@ +--- +key_path: redis_hll_counters.count_distinct_project_id_from_create_ci_runner +description: Count of unique projects where a project runner was created +product_group: runner +product_categories: +- fleet_visibility +- runner +performance_indicator_type: [] +value_type: number +status: active +milestone: '17.9' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/179876 +time_frame: +- 28d +- 7d +data_source: internal_events +data_category: optional +tiers: +- free +- premium +- ultimate +events: +- name: create_ci_runner + unique: project.id diff --git a/config/metrics/counts_all/count_distinct_project_id_from_create_ci_runner_with_token.yml b/config/metrics/counts_all/count_distinct_project_id_from_create_ci_runner_with_token.yml new file mode 100644 index 0000000000000000000000000000000000000000..7b389d6782e62c2a77a2651a679a8ba0456dcbb8 --- /dev/null +++ b/config/metrics/counts_all/count_distinct_project_id_from_create_ci_runner_with_token.yml @@ -0,0 +1,27 @@ +--- +key_path: redis_hll_counters.count_distinct_project_id_from_create_ci_runner_with_token +description: Count of unique projects where a project runner was created using a runner registration token +product_group: runner +product_categories: +- fleet_visibility +- runner +performance_indicator_type: [] +value_type: number +status: active +milestone: '17.9' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/179876 +time_frame: +- 28d +- 7d +data_source: internal_events +data_category: optional +tiers: +- free +- premium +- ultimate +events: +- name: create_ci_runner + unique: project.id + filter: + label: 'project_type' + property: 'registration_token' diff --git a/config/metrics/counts_all/count_distinct_user_id_from_create_ci_runner.yml b/config/metrics/counts_all/count_distinct_user_id_from_create_ci_runner.yml new file mode 100644 index 0000000000000000000000000000000000000000..ef945af0ec9819a010b64a4af0096e2411d1c4b4 --- /dev/null +++ b/config/metrics/counts_all/count_distinct_user_id_from_create_ci_runner.yml @@ -0,0 +1,24 @@ +--- +key_path: redis_hll_counters.count_distinct_user_id_from_create_ci_runner +description: Count of unique users who created a runner +product_group: runner +product_categories: +- fleet_visibility +- runner +performance_indicator_type: [] +value_type: number +status: active +milestone: '17.9' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/179876 +time_frame: +- 28d +- 7d +data_source: internal_events +data_category: optional +tiers: +- free +- premium +- ultimate +events: +- name: create_ci_runner + unique: user.id diff --git a/config/metrics/counts_all/count_distinct_user_id_from_create_ci_runner_with_token.yml b/config/metrics/counts_all/count_distinct_user_id_from_create_ci_runner_with_token.yml new file mode 100644 index 0000000000000000000000000000000000000000..d76a86d0136c8eb01087a452ed5633197e53e8f2 --- /dev/null +++ b/config/metrics/counts_all/count_distinct_user_id_from_create_ci_runner_with_token.yml @@ -0,0 +1,26 @@ +--- +key_path: redis_hll_counters.count_distinct_user_id_from_create_ci_runner_with_token +description: Count of unique users who registered a runner using a runner registration token +product_group: runner +product_categories: +- fleet_visibility +- runner +performance_indicator_type: [] +value_type: number +status: active +milestone: '17.9' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/179876 +time_frame: +- 28d +- 7d +data_source: internal_events +data_category: optional +tiers: +- free +- premium +- ultimate +events: +- name: create_ci_runner + unique: user.id + filter: + property: 'registration_token' diff --git a/config/metrics/counts_all/count_total_ci_runners_created_with_token.yml b/config/metrics/counts_all/count_total_ci_runners_created_with_token.yml new file mode 100644 index 0000000000000000000000000000000000000000..91897d83fd3af927f2e30325a3c8462fdeb91b4c --- /dev/null +++ b/config/metrics/counts_all/count_total_ci_runners_created_with_token.yml @@ -0,0 +1,26 @@ +--- +key_path: counts.count_total_ci_runners_created_with_token +description: Count of runners created using a runner registration token +product_group: runner +product_categories: +- fleet_visibility +- runner +performance_indicator_type: [] +value_type: number +status: active +milestone: '17.9' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/179876 +time_frame: +- 28d +- 7d +- all +data_source: internal_events +data_category: optional +tiers: +- free +- premium +- ultimate +events: +- name: create_ci_runner + filter: + property: 'registration_token' diff --git a/spec/services/ci/runners/create_runner_service_spec.rb b/spec/services/ci/runners/create_runner_service_spec.rb index b9a95efa44653e63aac18ebd06562e030750972e..a1b07f08de369785b027eda8aea2e7cfea077948 100644 --- a/spec/services/ci/runners/create_runner_service_spec.rb +++ b/spec/services/ci/runners/create_runner_service_spec.rb @@ -132,6 +132,10 @@ end it { is_expected.to be_error } + + it 'does not track runner creation' do + expect { execute }.not_to trigger_internal_events('create_ci_runner') + end end shared_examples 'it can return an error' do @@ -175,6 +179,18 @@ it_behaves_like 'it can create a runner' it_behaves_like 'it can return an error' + it 'tracks internal events', :clean_gitlab_redis_shared_state do + expect { execute } + .to trigger_internal_events('create_ci_runner') + .with(user: current_user, additional_properties: { + label: expected_type, + property: 'authenticated_user' + }).and increment_usage_metrics( + 'redis_hll_counters.count_distinct_user_id_from_create_ci_runner_monthly', + 'redis_hll_counters.count_distinct_user_id_from_create_ci_runner_weekly' + ) + end + it 'does not track runner creation with maintenance note' do expect { execute }.not_to trigger_internal_events('set_runner_maintenance_note') end @@ -230,6 +246,18 @@ it_behaves_like 'it can create a runner' + it 'tracks internal events', :clean_gitlab_redis_shared_state do + expect { execute } + .to trigger_internal_events('create_ci_runner') + .with(namespace: group, user: current_user, additional_properties: { + label: expected_type, + property: 'authenticated_user' + }).and increment_usage_metrics( + 'redis_hll_counters.count_distinct_namespace_id_from_create_ci_runner_monthly', + 'redis_hll_counters.count_distinct_namespace_id_from_create_ci_runner_weekly' + ) + end + it 'populates sharding_key_id correctly' do expect(runner.sharding_key_id).to eq(group.id) end @@ -314,6 +342,18 @@ end it_behaves_like 'it can create a runner' + + it 'tracks internal events', :clean_gitlab_redis_shared_state do + expect { execute } + .to trigger_internal_events('create_ci_runner') + .with(project: project, user: current_user, additional_properties: { + label: expected_type, + property: 'authenticated_user' + }).and increment_usage_metrics( + 'redis_hll_counters.count_distinct_project_id_from_create_ci_runner_monthly', + 'redis_hll_counters.count_distinct_project_id_from_create_ci_runner_weekly' + ) + end end end diff --git a/spec/services/ci/runners/register_runner_service_spec.rb b/spec/services/ci/runners/register_runner_service_spec.rb index 2cc6155e971382506a0911c446c3af82312f12c9..f8e9f5283228dd672e2dc66f5bc510c225a16ced 100644 --- a/spec/services/ci/runners/register_runner_service_spec.rb +++ b/spec/services/ci/runners/register_runner_service_spec.rb @@ -23,6 +23,10 @@ expect(execute.message).to eq 'runner registration disallowed' expect(execute.reason).to eq :runner_registration_disallowed end + + it 'does not track runner creation' do + expect { execute }.not_to trigger_internal_events('create_ci_runner') + end end context 'when no token is provided' do @@ -33,6 +37,10 @@ expect(execute.message).to eq 'invalid token supplied' expect(execute.http_status).to eq :forbidden end + + it 'does not track runner creation' do + expect { execute }.not_to trigger_internal_events('create_ci_runner') + end end context 'when invalid token is provided' do @@ -43,6 +51,10 @@ expect(execute.message).to eq 'invalid token supplied' expect(execute.http_status).to eq :forbidden end + + it 'does not track runner creation' do + expect { execute }.not_to trigger_internal_events('create_ci_runner') + end end context 'when valid token is provided' do @@ -61,6 +73,17 @@ expect(runner).to be_instance_type end + it 'tracks internal events', :clean_gitlab_redis_shared_state do + expect { execute } + .to trigger_internal_events('create_ci_runner') + .with(additional_properties: { + label: 'instance_type', + property: 'registration_token' + }).and increment_usage_metrics( + 'counts.count_total_ci_runners_created_with_token' + ) + end + context 'when registering instance runners is disallowed' do before do stub_application_setting( @@ -160,6 +183,18 @@ expect { execute }.not_to trigger_internal_events('set_runner_maintenance_note') end + it 'tracks internal events', :clean_gitlab_redis_shared_state do + expect { execute } + .to trigger_internal_events('create_ci_runner') + .with(project: project, additional_properties: { + label: 'project_type', + property: 'registration_token' + }).and increment_usage_metrics( + 'redis_hll_counters.count_distinct_project_id_from_create_ci_runner_monthly', + 'redis_hll_counters.count_distinct_project_id_from_create_ci_runner_weekly' + ) + end + context 'when maintenance note is specified' do let(:args) { { maintenance_note: 'a note' } } @@ -259,6 +294,18 @@ expect { execute }.not_to trigger_internal_events('set_runner_maintenance_note') end + it 'tracks internal events', :clean_gitlab_redis_shared_state do + expect { execute } + .to trigger_internal_events('create_ci_runner') + .with(namespace: group, additional_properties: { + label: 'group_type', + property: 'registration_token' + }).and increment_usage_metrics( + 'redis_hll_counters.count_distinct_namespace_id_from_create_ci_runner_monthly', + 'redis_hll_counters.count_distinct_namespace_id_from_create_ci_runner_weekly' + ) + end + context 'when maintenance note is specified' do let(:args) { { maintenance_note: 'a note' } }