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 26069b5fa02a7fbd973d8370d674cb6cee149d8d..46d52a79b27cb888e5dc0c2b99e953397ee108f3 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 0000000000000000000000000000000000000000..e74a0f07d7d33c74408a3b965e43ec966f49288d --- /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: 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 +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 0000000000000000000000000000000000000000..fbadba26e13f0420e11271223daca0df749782af --- /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 0000000000000000000000000000000000000000..d1474f56d04ef25e82b7f9c0f3c0e622a87b286a --- /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 d7e63539aeab95af1245e57cb202bfdd5013f209..5675b1d409b07c4870121e0ecefc3802f1924035 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,10 +22,17 @@ end it 'returns a success service response' do + event_data = event_data_from(action) expect(service).to receive(:can?).and_call_original - expect(execute).to be_success + expect { execute } + .to trigger_internal_events('pull_maven_package_file_through_virtual_registry') + .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) @@ -37,9 +44,22 @@ expect(action_params[:file_md5]).to be_instance_of(String) when :download_digest 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