diff --git a/ee/config/metrics/counts_all/count_total_projects_with_secret_push_protection_enabled.yml b/ee/config/metrics/counts_all/count_total_projects_with_secret_push_protection_enabled.yml new file mode 100644 index 0000000000000000000000000000000000000000..f9d46716a76e39b21ded940ed0418834b5fa841a --- /dev/null +++ b/ee/config/metrics/counts_all/count_total_projects_with_secret_push_protection_enabled.yml @@ -0,0 +1,15 @@ +data_category: optional +key_path: counts.projects_with_secret_push_protection_enabled +description: Count of projects with Secret Push Protection enabled +product_group: secret_detection +value_type: number +status: active +milestone: "17.1" +instrumentation_class: CountProjectsWithSecretPushProtectionEnabledMetric +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/156076 +time_frame: all +data_source: database +distribution: +- ee +tier: +- ultimate diff --git a/ee/lib/gitlab/usage/metrics/instrumentations/count_projects_with_secret_push_protection_enabled_metric.rb b/ee/lib/gitlab/usage/metrics/instrumentations/count_projects_with_secret_push_protection_enabled_metric.rb new file mode 100644 index 0000000000000000000000000000000000000000..b73308bd6f3aefb32c2689720aa5020ba2d0a07a --- /dev/null +++ b/ee/lib/gitlab/usage/metrics/instrumentations/count_projects_with_secret_push_protection_enabled_metric.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Gitlab + module Usage + module Metrics + module Instrumentations + class CountProjectsWithSecretPushProtectionEnabledMetric < DatabaseMetric + operation :count + + relation do + ProjectSecuritySetting.where(pre_receive_secret_detection_enabled: true) + end + end + end + end + end +end diff --git a/ee/spec/lib/gitlab/usage/metrics/instrumentations/count_projects_with_secret_push_protection_enabled_metric_spec.rb b/ee/spec/lib/gitlab/usage/metrics/instrumentations/count_projects_with_secret_push_protection_enabled_metric_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..1808574e1f4a7eceee592011a8ae69810032331c --- /dev/null +++ b/ee/spec/lib/gitlab/usage/metrics/instrumentations/count_projects_with_secret_push_protection_enabled_metric_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountProjectsWithSecretPushProtectionEnabledMetric, feature_category: :service_ping do + let(:expected_value) { 3 } + + before do + 3.times do + create(:project).security_setting.update!(pre_receive_secret_detection_enabled: true) + end + create(:project) + end + + it_behaves_like 'a correct instrumented metric value', { time_frame: 'all', data_source: 'database' } +end