diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 13:49:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 13:49:51 +0000 |
commit | 71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch) | |
tree | 6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /spec/lib/gitlab/usage/metrics | |
parent | a7253423e3403b8c08f8a161e5937e1488f5f407 (diff) | |
download | gitlab-ce-15.9.0-rc42.tar.gz |
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'spec/lib/gitlab/usage/metrics')
12 files changed, 212 insertions, 4 deletions
diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/count_ci_internal_pipelines_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/count_ci_internal_pipelines_metric_spec.rb new file mode 100644 index 00000000000..afd8fccd56c --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/count_ci_internal_pipelines_metric_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountCiInternalPipelinesMetric, +feature_category: :service_ping do + let_it_be(:ci_pipeline_1) { create(:ci_pipeline, source: :external) } + let_it_be(:ci_pipeline_2) { create(:ci_pipeline, source: :push) } + + let(:expected_value) { 1 } + let(:expected_query) do + 'SELECT COUNT("ci_pipelines"."id") FROM "ci_pipelines" ' \ + 'WHERE ("ci_pipelines"."source" IN (1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15) ' \ + 'OR "ci_pipelines"."source" IS NULL)' + end + + it_behaves_like 'a correct instrumented metric value', { time_frame: 'all', data_source: 'database' } + + context 'on Gitlab.com' do + before do + allow(Gitlab).to receive(:com?).and_return(true) + end + + let(:expected_value) { -1 } + + it_behaves_like 'a correct instrumented metric value', { time_frame: 'all', data_source: 'database' } + end +end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/count_issues_created_manually_from_alerts_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/count_issues_created_manually_from_alerts_metric_spec.rb new file mode 100644 index 00000000000..86f54c48666 --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/count_issues_created_manually_from_alerts_metric_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountIssuesCreatedManuallyFromAlertsMetric, +feature_category: :service_ping do + let_it_be(:issue) { create(:issue) } + let_it_be(:issue_with_alert) { create(:issue, :with_alert) } + + let(:expected_value) { 1 } + let(:expected_query) do + 'SELECT COUNT("issues"."id") FROM "issues" ' \ + 'INNER JOIN "alert_management_alerts" ON "alert_management_alerts"."issue_id" = "issues"."id" ' \ + 'WHERE "issues"."author_id" != 99' + end + + it_behaves_like 'a correct instrumented metric value', { time_frame: 'all', data_source: 'database' } + + context 'on Gitlab.com' do + before do + allow(Gitlab).to receive(:com?).and_return(true) + end + + let(:expected_value) { -1 } + + it_behaves_like 'a correct instrumented metric value', { time_frame: 'all', data_source: 'database' } + end +end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/count_ml_candidates_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/count_ml_candidates_metric_spec.rb new file mode 100644 index 00000000000..7d7788737df --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/count_ml_candidates_metric_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountMlCandidatesMetric, feature_category: :mlops do + let_it_be(:candidate) { create(:ml_candidates) } + + let(:expected_value) { 1 } + let(:expected_query) { 'SELECT COUNT("ml_candidates"."id") FROM "ml_candidates"' } + + it_behaves_like 'a correct instrumented metric value and query', { time_frame: 'all' } +end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/count_ml_experiments_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/count_ml_experiments_metric_spec.rb new file mode 100644 index 00000000000..887496ce39f --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/count_ml_experiments_metric_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountMlExperimentsMetric, feature_category: :mlops do + let_it_be(:candidate) { create(:ml_experiments) } + + let(:expected_value) { 1 } + let(:expected_query) { 'SELECT COUNT("ml_experiments"."id") FROM "ml_experiments"' } + + it_behaves_like 'a correct instrumented metric value and query', { time_frame: 'all' } +end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/count_projects_with_ml_candidates_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/count_projects_with_ml_candidates_metric_spec.rb new file mode 100644 index 00000000000..e5026ab6358 --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/count_projects_with_ml_candidates_metric_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountProjectsWithMlCandidatesMetric, + feature_category: :mlops do + let_it_be(:project_without_candidates) { create(:project, :repository) } + let_it_be(:candidate) { create(:ml_candidates) } + let_it_be(:another_candidate) { create(:ml_candidates, experiment: candidate.experiment) } + + let(:expected_value) { 1 } + let(:expected_query) do + 'SELECT COUNT(DISTINCT "ml_experiments"."ml_experiments.project_id") FROM "ml_experiments" WHERE ' \ + '(EXISTS (SELECT 1 FROM "ml_candidates" WHERE ("ml_experiments"."id" = "ml_candidates"."experiment_id")))' + end + + it_behaves_like 'a correct instrumented metric value and query', { time_frame: 'all' } +end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/count_projects_with_ml_experiments_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/count_projects_with_ml_experiments_metric_spec.rb new file mode 100644 index 00000000000..829245f785b --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/count_projects_with_ml_experiments_metric_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountProjectsWithMlExperimentsMetric, + feature_category: :mlops do + let_it_be(:project_without_experiment) { create(:project, :repository) } + let_it_be(:experiment) { create(:ml_experiments) } + let_it_be(:another_experiment) { create(:ml_experiments, project: experiment.project) } + + let(:expected_value) { 1 } + let(:expected_query) { 'SELECT COUNT(DISTINCT "ml_experiments"."project_id") FROM "ml_experiments"' } + + it_behaves_like 'a correct instrumented metric value and query', { time_frame: 'all' } +end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/count_projects_with_monitor_enabled_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/count_projects_with_monitor_enabled_metric_spec.rb new file mode 100644 index 00000000000..d917dccd2b0 --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/count_projects_with_monitor_enabled_metric_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountProjectsWithMonitorEnabledMetric, + feature_category: :metrics do + let_it_be(:projects) { create_list(:project, 3) } + + let(:expected_value) { 2 } + let(:expected_query) do + 'SELECT COUNT("project_features"."id") FROM "project_features" WHERE "project_features"."monitor_access_level" != 0' + end + + before_all do + # Monitor feature cannot have public visibility level. Therefore `ProjectFeature::PUBLIC` is missing here + projects[0].project_feature.update!(monitor_access_level: ProjectFeature::DISABLED) + projects[1].project_feature.update!(monitor_access_level: ProjectFeature::PRIVATE) + projects[2].project_feature.update!(monitor_access_level: ProjectFeature::ENABLED) + end + + it_behaves_like 'a correct instrumented metric value and query', { time_frame: 'all' } +end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/count_users_with_ml_candidates_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/count_users_with_ml_candidates_metric_spec.rb new file mode 100644 index 00000000000..b25d61d0bd2 --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/count_users_with_ml_candidates_metric_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountUsersWithMlCandidatesMetric, feature_category: :mlops do + let_it_be(:user_without_candidates) { create(:user) } + let_it_be(:candidate) { create(:ml_candidates) } + let_it_be(:another_candidate) { create(:ml_candidates, user: candidate.user) } + + let(:expected_value) { 1 } + let(:expected_query) { 'SELECT COUNT(DISTINCT "ml_candidates"."user_id") FROM "ml_candidates"' } + + it_behaves_like 'a correct instrumented metric value and query', { time_frame: 'all' } +end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/incoming_email_encrypted_secrets_enabled_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/incoming_email_encrypted_secrets_enabled_metric_spec.rb new file mode 100644 index 00000000000..ed35b2c8cde --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/incoming_email_encrypted_secrets_enabled_metric_spec.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::IncomingEmailEncryptedSecretsEnabledMetric, +feature_category: :service_ping do + it_behaves_like 'a correct instrumented metric value', { time_frame: 'none', data_source: 'ruby' } do + let(:expected_value) { ::Gitlab::IncomingEmail.encrypted_secrets.active? } + end +end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/jira_active_integrations_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/jira_active_integrations_metric_spec.rb new file mode 100644 index 00000000000..104fd18ba2d --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/jira_active_integrations_metric_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::JiraActiveIntegrationsMetric, + feature_category: :integrations do + let(:options) { { deployment_type: 'cloud', series: 0 } } + let(:integration_attributes) { { active: true, deployment_type: 'cloud' } } + let(:expected_value) { 3 } + let(:expected_query) do + 'SELECT COUNT("integrations"."id") FROM "integrations" ' \ + 'INNER JOIN "jira_tracker_data" ON "jira_tracker_data"."integration_id" = "integrations"."id" ' \ + 'WHERE "integrations"."type_new" = \'Integrations::Jira\' AND "integrations"."active" = TRUE ' \ + 'AND "jira_tracker_data"."deployment_type" = 2' + end + + before do + create_list :jira_integration, 3, integration_attributes + + create :jira_integration, integration_attributes.merge(active: false) + create :jira_integration, integration_attributes.merge(deployment_type: 'server') + end + + it_behaves_like 'a correct instrumented metric value and query', + { options: { deployment_type: 'cloud' }, time_frame: 'all' } + + it "raises an exception if option is not present" do + expect do + described_class.new(options: options.except(:deployment_type), time_frame: 'all') + end.to raise_error(ArgumentError, %r{deployment_type .* must be one of}) + end + + it "raises an exception if option has invalid value" do + expect do + options[:deployment_type] = 'cloood' + described_class.new(options: options, time_frame: 'all') + end.to raise_error(ArgumentError, %r{deployment_type .* must be one of}) + end +end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/service_desk_email_encrypted_secrets_enabled_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/service_desk_email_encrypted_secrets_enabled_metric_spec.rb new file mode 100644 index 00000000000..d602eae3159 --- /dev/null +++ b/spec/lib/gitlab/usage/metrics/instrumentations/service_desk_email_encrypted_secrets_enabled_metric_spec.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Usage::Metrics::Instrumentations::ServiceDeskEmailEncryptedSecretsEnabledMetric, +feature_category: :service_ping do + it_behaves_like 'a correct instrumented metric value', { time_frame: 'none', data_source: 'ruby' } do + let(:expected_value) { ::Gitlab::ServiceDeskEmail.encrypted_secrets.active? } + end +end diff --git a/spec/lib/gitlab/usage/metrics/names_suggestions/generator_spec.rb b/spec/lib/gitlab/usage/metrics/names_suggestions/generator_spec.rb index 83a4ea8e948..4f647c2700a 100644 --- a/spec/lib/gitlab/usage/metrics/names_suggestions/generator_spec.rb +++ b/spec/lib/gitlab/usage/metrics/names_suggestions/generator_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Usage::Metrics::NamesSuggestions::Generator do +RSpec.describe Gitlab::Usage::Metrics::NamesSuggestions::Generator, feature_category: :service_ping do include UsageDataHelpers before do @@ -43,9 +43,9 @@ RSpec.describe Gitlab::Usage::Metrics::NamesSuggestions::Generator do context 'joined relations' do context 'counted attribute comes from source relation' do it_behaves_like 'name suggestion' do - # corresponding metric is collected with count(Issue.with_alert_management_alerts.not_authored_by(::User.alert_bot), start: issue_minimum_id, finish: issue_maximum_id) - let(:key_path) { 'counts.issues_created_manually_from_alerts' } - let(:name_suggestion) { /count_<adjective describing: '\(issues\.author_id != \d+\)'>_issues_<with>_alert_management_alerts/ } + # corresponding metric is collected with distinct_count(Release.with_milestones, :author_id) + let(:key_path) { 'usage_activity_by_stage.release.releases_with_milestones' } + let(:name_suggestion) { /count_distinct_author_id_from_releases_<with>_milestone_releases/ } end end end |