From 3eb4c4032b91384eefd7b52f5daf92b6be72408c Mon Sep 17 00:00:00 2001 From: David Fernandez Date: Tue, 27 May 2025 19:03:26 +0200 Subject: [PATCH 1/3] Add internal tracking events for the Maven virtual registry Add the event and the different metrics We use a property to categorize if the file request has been served from the upstream or the cache. --- .../maven/handle_file_request_service.rb | 17 +++++++++++++ ..._package_file_through_virtual_registry.yml | 18 ++++++++++++++ ...le_through_virtual_registry_from_cache.yml | 24 +++++++++++++++++++ ...through_virtual_registry_from_upstream.yml | 24 +++++++++++++++++++ .../maven/handle_file_request_service_spec.rb | 17 +++++++++++-- 5 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 ee/config/events/pull_maven_package_file_through_virtual_registry.yml create mode 100644 ee/config/metrics/counts_all/count_total_pull_maven_package_file_through_virtual_registry_from_cache.yml create mode 100644 ee/config/metrics/counts_all/count_total_pull_maven_package_file_through_virtual_registry_from_upstream.yml diff --git a/ee/app/services/virtual_registries/packages/maven/handle_file_request_service.rb b/ee/app/services/virtual_registries/packages/maven/handle_file_request_service.rb index 26069b5fa02a7f..46d52a79b27cb8 100644 --- a/ee/app/services/virtual_registries/packages/maven/handle_file_request_service.rb +++ b/ee/app/services/virtual_registries/packages/maven/handle_file_request_service.rb @@ -4,6 +4,8 @@ module VirtualRegistries module Packages module Maven class HandleFileRequestService < ::VirtualRegistries::BaseService + include Gitlab::InternalEventsTracking + DIGEST_EXTENSIONS = %w[.sha1 .md5].freeze PERMISSIONS_CACHE_TTL = 5.minutes @@ -98,6 +100,8 @@ def download_cache_entry_digest digest_format = File.extname(path)[1..] # file extension without the leading dot return ERRORS[:fips_unsupported_md5] if digest_format == 'md5' && Gitlab::FIPS.enabled? + create_event(from_upstream: false) + ServiceResponse.success( payload: { action: :download_digest, @@ -143,6 +147,8 @@ def relative_path end def download_cache_entry + create_event(from_upstream: false) + ServiceResponse.success( payload: { action: :download_file, @@ -157,6 +163,8 @@ def download_cache_entry end def workhorse_upload_url_response(upstream:) + create_event(from_upstream: true) + ServiceResponse.success( payload: { action: :workhorse_upload_url, @@ -164,6 +172,15 @@ def workhorse_upload_url_response(upstream:) } ) end + + def create_event(from_upstream:) + args = { + namespace: registry.group, + additional_properties: { label: from_upstream ? 'from_upstream' : 'from_cache' } + } + args[:user] = current_user if current_user.is_a?(User) + track_internal_event('pull_maven_package_file_through_virtual_registry', **args) + end end end end diff --git a/ee/config/events/pull_maven_package_file_through_virtual_registry.yml b/ee/config/events/pull_maven_package_file_through_virtual_registry.yml new file mode 100644 index 00000000000000..78547ed9a12173 --- /dev/null +++ b/ee/config/events/pull_maven_package_file_through_virtual_registry.yml @@ -0,0 +1,18 @@ +--- +description: Maven package file pulled through a maven virtual registry +internal_events: true +action: pull_maven_package_file_through_virtual_registry +identifiers: + - namespace + - user +additional_properties: + label: + description: Wether the upstream or the cache was used to fulfill the file request (one of from_upstream, from_cache) +product_group: package_registry +product_categories: + - virtual_registry +milestone: '18.1' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/192689 +tiers: + - premium + - ultimate diff --git a/ee/config/metrics/counts_all/count_total_pull_maven_package_file_through_virtual_registry_from_cache.yml b/ee/config/metrics/counts_all/count_total_pull_maven_package_file_through_virtual_registry_from_cache.yml new file mode 100644 index 00000000000000..fbadba26e13f04 --- /dev/null +++ b/ee/config/metrics/counts_all/count_total_pull_maven_package_file_through_virtual_registry_from_cache.yml @@ -0,0 +1,24 @@ +--- +key_path: counts.count_total_pull_maven_package_file_through_virtual_registry_from_cache +description: Count of amount of maven package files pulled through virtual registries from cache +product_group: package_registry +product_categories: + - virtual_registry +performance_indicator_type: [] +value_type: number +status: active +milestone: '18.1' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/192689 +time_frame: + - 28d + - 7d + - all +data_source: internal_events +data_category: optional +tiers: + - premium + - ultimate +events: + - name: pull_maven_package_file_through_virtual_registry + filter: + label: from_cache diff --git a/ee/config/metrics/counts_all/count_total_pull_maven_package_file_through_virtual_registry_from_upstream.yml b/ee/config/metrics/counts_all/count_total_pull_maven_package_file_through_virtual_registry_from_upstream.yml new file mode 100644 index 00000000000000..d1474f56d04ef2 --- /dev/null +++ b/ee/config/metrics/counts_all/count_total_pull_maven_package_file_through_virtual_registry_from_upstream.yml @@ -0,0 +1,24 @@ +--- +key_path: counts.count_total_pull_maven_package_file_through_virtual_registry_from_upstream +description: Count of amount of maven package files pulled through virtual registries using upstreams (no cache) +product_group: package_registry +product_categories: + - virtual_registry +performance_indicator_type: [] +value_type: number +status: active +milestone: '18.1' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/192689 +time_frame: + - 28d + - 7d + - all +data_source: internal_events +data_category: optional +tiers: + - premium + - ultimate +events: + - name: pull_maven_package_file_through_virtual_registry + filter: + label: from_upstream diff --git a/ee/spec/services/virtual_registries/packages/maven/handle_file_request_service_spec.rb b/ee/spec/services/virtual_registries/packages/maven/handle_file_request_service_spec.rb index d7e63539aeab95..8cfd4ca49f0af5 100644 --- a/ee/spec/services/virtual_registries/packages/maven/handle_file_request_service_spec.rb +++ b/ee/spec/services/virtual_registries/packages/maven/handle_file_request_service_spec.rb @@ -22,7 +22,22 @@ end it 'returns a success service response' do + if action == :workhorse_upload_url + event_label = 'from_upstream' + metric_key = 'counts.count_total_pull_maven_package_file_through_virtual_registry_from_upstream' + else + event_label = 'from_cache' + metric_key = 'counts.count_total_pull_maven_package_file_through_virtual_registry_from_cache' + end + + args = { namespace: registry.group, additional_properties: { label: event_label } } + args[:user] = user if user.is_a?(User) + expect(service).to receive(:can?).and_call_original + expect { execute } + .to trigger_internal_events('pull_maven_package_file_through_virtual_registry') + .with(**args) + .and increment_usage_metrics(metric_key) expect(execute).to be_success expect(execute.payload[:action]).to eq(action) @@ -37,8 +52,6 @@ expect(action_params[:file_md5]).to be_instance_of(String) when :download_digest expect(execute.payload[:action_params]).to eq(digest: expected_digest) - else - {} end end end -- GitLab From 5c16e6aa0208068e4f258d835a71154687d68107 Mon Sep 17 00:00:00 2001 From: David Fernandez Date: Tue, 3 Jun 2025 15:21:57 +0200 Subject: [PATCH 2/3] Fix typo --- .../events/pull_maven_package_file_through_virtual_registry.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/config/events/pull_maven_package_file_through_virtual_registry.yml b/ee/config/events/pull_maven_package_file_through_virtual_registry.yml index 78547ed9a12173..e74a0f07d7d33c 100644 --- a/ee/config/events/pull_maven_package_file_through_virtual_registry.yml +++ b/ee/config/events/pull_maven_package_file_through_virtual_registry.yml @@ -7,7 +7,7 @@ identifiers: - user additional_properties: label: - description: Wether the upstream or the cache was used to fulfill the file request (one of from_upstream, from_cache) + description: Whether the upstream or the cache was used to fulfill the file request (one of from_upstream, from_cache) product_group: package_registry product_categories: - virtual_registry -- GitLab From 938538d6f6c19f614053487f9e643083ef24419a Mon Sep 17 00:00:00 2001 From: David Fernandez Date: Thu, 5 Jun 2025 20:47:44 +0200 Subject: [PATCH 3/3] Improve spec readability --- .../maven/handle_file_request_service_spec.rb | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/ee/spec/services/virtual_registries/packages/maven/handle_file_request_service_spec.rb b/ee/spec/services/virtual_registries/packages/maven/handle_file_request_service_spec.rb index 8cfd4ca49f0af5..5675b1d409b07c 100644 --- a/ee/spec/services/virtual_registries/packages/maven/handle_file_request_service_spec.rb +++ b/ee/spec/services/virtual_registries/packages/maven/handle_file_request_service_spec.rb @@ -22,25 +22,17 @@ end it 'returns a success service response' do - if action == :workhorse_upload_url - event_label = 'from_upstream' - metric_key = 'counts.count_total_pull_maven_package_file_through_virtual_registry_from_upstream' - else - event_label = 'from_cache' - metric_key = 'counts.count_total_pull_maven_package_file_through_virtual_registry_from_cache' - end - - args = { namespace: registry.group, additional_properties: { label: event_label } } - args[:user] = user if user.is_a?(User) - + event_data = event_data_from(action) expect(service).to receive(:can?).and_call_original + expect { execute } .to trigger_internal_events('pull_maven_package_file_through_virtual_registry') - .with(**args) - .and increment_usage_metrics(metric_key) - expect(execute).to be_success + .with(**event_data[:args]) + .and increment_usage_metrics(event_data[:metric_key]) + expect(execute).to be_success expect(execute.payload[:action]).to eq(action) + case action when :workhorse_upload_url expect(execute.payload[:action_params]).to eq(url: upstream_resource_url, upstream: upstream) @@ -54,6 +46,21 @@ expect(execute.payload[:action_params]).to eq(digest: expected_digest) end end + + def event_data_from(action) + if action == :workhorse_upload_url + event_label = 'from_upstream' + metric_key = 'counts.count_total_pull_maven_package_file_through_virtual_registry_from_upstream' + else + event_label = 'from_cache' + metric_key = 'counts.count_total_pull_maven_package_file_through_virtual_registry_from_cache' + end + + args = { namespace: registry.group, additional_properties: { label: event_label } } + args[:user] = user if user.is_a?(User) + + { args:, metric_key: } + end end context 'with a User' do -- GitLab