diff --git a/config/metrics/counts_all/20231204142552_service_desk_custom_email_enabled.yml b/config/metrics/counts_all/20231204142552_service_desk_custom_email_enabled.yml new file mode 100644 index 0000000000000000000000000000000000000000..d577c3b5b9f2fafb86cca47625380cb29acc1c8a --- /dev/null +++ b/config/metrics/counts_all/20231204142552_service_desk_custom_email_enabled.yml @@ -0,0 +1,21 @@ +--- +key_path: counts.service_desk_custom_email_enabled +description: "Number of projects that have Service Desk custom email enabled" +product_section: seg +product_stage: service management +product_group: respond +value_type: number +status: active +milestone: "16.7" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/138662 +time_frame: all +data_source: database +data_category: optional +instrumentation_class: CountServiceDeskCustomEmailEnabledMetric +distribution: +- ce +- ee +tier: +- free +- premium +- ultimate diff --git a/db/migrate/20231204144300_add_index_service_desk_settings_on_custom_email_enabled.rb b/db/migrate/20231204144300_add_index_service_desk_settings_on_custom_email_enabled.rb new file mode 100644 index 0000000000000000000000000000000000000000..22c8c1962341c6be287dc601cb4460309f812ec0 --- /dev/null +++ b/db/migrate/20231204144300_add_index_service_desk_settings_on_custom_email_enabled.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddIndexServiceDeskSettingsOnCustomEmailEnabled < Gitlab::Database::Migration[2.2] + milestone '16.7' + + disable_ddl_transaction! + + INDEX_NAME = 'index_service_desk_settings_on_custom_email_enabled' + + def up + add_concurrent_index :service_desk_settings, :custom_email_enabled, name: INDEX_NAME + end + + def down + remove_concurrent_index_by_name :service_desk_settings, INDEX_NAME + end +end diff --git a/db/schema_migrations/20231204144300 b/db/schema_migrations/20231204144300 new file mode 100644 index 0000000000000000000000000000000000000000..a69b0278d5af2234879b9113d50b015fdb2142c6 --- /dev/null +++ b/db/schema_migrations/20231204144300 @@ -0,0 +1 @@ +385471e69c2099130d0758d2fe6ac27b9211204759de04f3fc0a79b84b5a1633 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 242c3eb65b8e3217c28bb79dbb172eab5e88f3e1..0573af7b8f3d97dd07bdec2aac60051171e9b748 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -34514,6 +34514,8 @@ CREATE INDEX index_service_desk_custom_email_verifications_on_triggerer_id ON se CREATE INDEX index_service_desk_enabled_projects_on_id_creator_id_created_at ON projects USING btree (id, creator_id, created_at) WHERE (service_desk_enabled = true); +CREATE INDEX index_service_desk_settings_on_custom_email_enabled ON service_desk_settings USING btree (custom_email_enabled); + CREATE INDEX index_service_desk_settings_on_file_template_project_id ON service_desk_settings USING btree (file_template_project_id); CREATE UNIQUE INDEX index_shards_on_name ON shards USING btree (name); diff --git a/lib/gitlab/usage/metrics/instrumentations/count_service_desk_custom_email_enabled_metric.rb b/lib/gitlab/usage/metrics/instrumentations/count_service_desk_custom_email_enabled_metric.rb new file mode 100644 index 0000000000000000000000000000000000000000..85f59f3694174846beb931831810f700f43cf7f2 --- /dev/null +++ b/lib/gitlab/usage/metrics/instrumentations/count_service_desk_custom_email_enabled_metric.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Gitlab + module Usage + module Metrics + module Instrumentations + class CountServiceDeskCustomEmailEnabledMetric < DatabaseMetric + operation :count + + relation do + ServiceDeskSetting.where(custom_email_enabled: true) + end + end + end + end + end +end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/count_service_desk_custom_email_enabled_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/count_service_desk_custom_email_enabled_metric_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..6d10052ff668b24576fc276fe569f254323bdd6f --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/count_service_desk_custom_email_enabled_metric_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountServiceDeskCustomEmailEnabledMetric, feature_category: :service_ping do + let_it_be(:project) { create(:project) } + let_it_be(:credential) { create(:service_desk_custom_email_credential, project: project) } + let_it_be(:verification) { create(:service_desk_custom_email_verification, :finished, project: project) } + let_it_be(:setting) do + create(:service_desk_setting, project: project, custom_email: 'support@example.com', custom_email_enabled: true) + end + + let(:expected_value) { 1 } + + it_behaves_like 'a correct instrumented metric value', { time_frame: 'all', data_source: 'database' } +end