diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 673e9171ef9..adf1eab5180 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -81,10 +81,6 @@ RSpec/ContextWording: RSpec/ExpectChange: Enabled: false -# Offense count: 930 -RSpec/ExpectInHook: - Enabled: false - # Offense count: 2352 # Cop supports --auto-correct. # Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers. diff --git a/.rubocop_todo/rspec/expect_in_hook.yml b/.rubocop_todo/rspec/expect_in_hook.yml new file mode 100644 index 00000000000..346f391a2fe --- /dev/null +++ b/.rubocop_todo/rspec/expect_in_hook.yml @@ -0,0 +1,553 @@ +--- +RSpec/ExpectInHook: + # Offense count: 1074 + # Temporarily disabled due to too many offenses + Enabled: false + Exclude: + - 'ee/spec/controllers/ee/projects/merge_requests/content_controller_spec.rb' + - 'ee/spec/controllers/groups/analytics/productivity_analytics_controller_spec.rb' + - 'ee/spec/controllers/groups/seat_usage_controller_spec.rb' + - 'ee/spec/controllers/projects/boards_controller_spec.rb' + - 'ee/spec/controllers/projects/settings/slacks_controller_spec.rb' + - 'ee/spec/controllers/registrations/groups_controller_spec.rb' + - 'ee/spec/controllers/registrations/groups_projects_controller_spec.rb' + - 'ee/spec/controllers/subscriptions_controller_spec.rb' + - 'ee/spec/controllers/trials_controller_spec.rb' + - 'ee/spec/features/boards/new_issue_spec.rb' + - 'ee/spec/features/projects/feature_flags/user_creates_feature_flag_spec.rb' + - 'ee/spec/features/projects/feature_flags/user_deletes_feature_flag_spec.rb' + - 'ee/spec/features/projects/settings/ee/service_desk_setting_spec.rb' + - 'ee/spec/features/registrations/combined_registration_spec.rb' + - 'ee/spec/features/registrations/trial_during_signup_flow_spec.rb' + - 'ee/spec/features/signup_spec.rb' + - 'ee/spec/features/trial_registrations/company_information_spec.rb' + - 'ee/spec/features/trials/capture_lead_spec.rb' + - 'ee/spec/features/trials/select_namespace_spec.rb' + - 'ee/spec/finders/license_template_finder_spec.rb' + - 'ee/spec/finders/projects/integrations/jira/issues_finder_spec.rb' + - 'ee/spec/finders/template_finder_spec.rb' + - 'ee/spec/graphql/mutations/gitlab_subscriptions/activate_spec.rb' + - 'ee/spec/helpers/billing_plans_helper_spec.rb' + - 'ee/spec/helpers/ee/ci/runners_helper_spec.rb' + - 'ee/spec/helpers/ee/issues_helper_spec.rb' + - 'ee/spec/helpers/ee/namespace_storage_limit_alert_helper_spec.rb' + - 'ee/spec/helpers/ee/welcome_helper_spec.rb' + - 'ee/spec/helpers/kerberos_spnego_helper_spec.rb' + - 'ee/spec/helpers/vulnerabilities_helper_spec.rb' + - 'ee/spec/lib/ee/gitlab/auth/ldap/sync/group_spec.rb' + - 'ee/spec/lib/ee/gitlab/gon_helper_spec.rb' + - 'ee/spec/lib/ee/gitlab/hook_data/user_builder_spec.rb' + - 'ee/spec/lib/gitlab/auth/smartcard/certificate_spec.rb' + - 'ee/spec/lib/gitlab/checks/diff_check_spec.rb' + - 'ee/spec/lib/gitlab/ci/minutes/cost_factor_spec.rb' + - 'ee/spec/lib/gitlab/code_owners/validator_spec.rb' + - 'ee/spec/lib/gitlab/code_owners_spec.rb' + - 'ee/spec/lib/gitlab/geo/replication/job_artifact_retriever_spec.rb' + - 'ee/spec/lib/gitlab/geo_spec.rb' + - 'ee/spec/lib/gitlab/git_access_spec.rb' + - 'ee/spec/lib/gitlab/graphql/aggregations/epics/lazy_epic_aggregate_spec.rb' + - 'ee/spec/lib/gitlab/graphql/aggregations/issues/lazy_block_aggregate_spec.rb' + - 'ee/spec/lib/gitlab/mirror_spec.rb' + - 'ee/spec/lib/gitlab/sitemaps/generator_spec.rb' + - 'ee/spec/lib/gitlab/subscription_portal/clients/graphql_spec.rb' + - 'ee/spec/lib/gitlab/usage/metrics/instrumentations/advanced_search/build_type_metric_spec.rb' + - 'ee/spec/lib/gitlab/usage/metrics/instrumentations/advanced_search/distribution_metric_spec.rb' + - 'ee/spec/lib/gitlab/usage/metrics/instrumentations/advanced_search/lucene_version_metric_spec.rb' + - 'ee/spec/lib/gitlab/usage/metrics/instrumentations/advanced_search/version_metric_spec.rb' + - 'ee/spec/models/application_setting_spec.rb' + - 'ee/spec/models/concerns/ee/issuable_spec.rb' + - 'ee/spec/models/concerns/geo/replicable_model_spec.rb' + - 'ee/spec/models/container_repository_spec.rb' + - 'ee/spec/models/dora/daily_metrics_spec.rb' + - 'ee/spec/models/ee/namespace_spec.rb' + - 'ee/spec/models/gitlab_subscription_spec.rb' + - 'ee/spec/models/license_spec.rb' + - 'ee/spec/models/project_import_state_spec.rb' + - 'ee/spec/models/project_spec.rb' + - 'ee/spec/presenters/group_member_presenter_spec.rb' + - 'ee/spec/requests/api/geo_spec.rb' + - 'ee/spec/requests/api/graphql/ci/runner_spec.rb' + - 'ee/spec/requests/api/internal/base_spec.rb' + - 'ee/spec/requests/groups/analytics/devops_adoption_controller_spec.rb' + - 'ee/spec/requests/omniauth_kerberos_spnego_spec.rb' + - 'ee/spec/services/analytics/cycle_analytics/stages/update_service_spec.rb' + - 'ee/spec/services/app_sec/dast/profiles/update_service_spec.rb' + - 'ee/spec/services/auto_merge/add_to_merge_train_when_pipeline_succeeds_service_spec.rb' + - 'ee/spec/services/ci/minutes/batch_reset_service_spec.rb' + - 'ee/spec/services/ci/runners/assign_runner_service_spec.rb' + - 'ee/spec/services/ci/runners/register_runner_service_spec.rb' + - 'ee/spec/services/ci/runners/unassign_runner_service_spec.rb' + - 'ee/spec/services/ci/sync_reports_to_approval_rules_service_spec.rb' + - 'ee/spec/services/ee/ci/job_artifacts/destroy_batch_service_spec.rb' + - 'ee/spec/services/ee/issues/update_service_spec.rb' + - 'ee/spec/services/ee/post_receive_service_spec.rb' + - 'ee/spec/services/ee/protected_branches/destroy_service_spec.rb' + - 'ee/spec/services/geo/blob_download_service_spec.rb' + - 'ee/spec/services/geo/project_housekeeping_service_spec.rb' + - 'ee/spec/services/geo/registry_consistency_service_spec.rb' + - 'ee/spec/services/gitlab_subscriptions/fetch_subscription_plans_service_spec.rb' + - 'ee/spec/services/gitlab_subscriptions/plan_upgrade_service_spec.rb' + - 'ee/spec/services/groups/update_repository_storage_service_spec.rb' + - 'ee/spec/services/members/activate_service_spec.rb' + - 'ee/spec/services/merge_requests/approval_service_spec.rb' + - 'ee/spec/services/namespaces/check_storage_size_service_spec.rb' + - 'ee/spec/services/projects/create_from_template_service_spec.rb' + - 'ee/spec/services/projects/mark_for_deletion_service_spec.rb' + - 'ee/spec/services/projects/update_mirror_service_spec.rb' + - 'ee/spec/services/security/findings/cleanup_service_spec.rb' + - 'ee/spec/services/upcoming_reconciliations/update_service_spec.rb' + - 'ee/spec/support/shared_examples/controllers/namespace_storage_limit_alert_shared_examples.rb' + - 'ee/spec/support/shared_examples/controllers/registrations/projects_controller_shared_examples.rb' + - 'ee/spec/support/shared_examples/models/concerns/elastic/cannot_read_cross_project_shared_examples.rb' + - 'ee/spec/support/shared_examples/models/concerns/verifiable_replicator_shared_examples.rb' + - 'ee/spec/support/shared_examples/services/base_sync_service_shared_examples.rb' + - 'ee/spec/support/shared_examples/status_page/reference_links_examples.rb' + - 'ee/spec/tasks/gitlab/license_rake_spec.rb' + - 'ee/spec/tasks/gitlab/spdx_rake_spec.rb' + - 'ee/spec/workers/analytics/cycle_analytics/consistency_worker_spec.rb' + - 'ee/spec/workers/concerns/elastic/indexing_control_spec.rb' + - 'ee/spec/workers/elastic_index_bulk_cron_worker_spec.rb' + - 'ee/spec/workers/elastic_indexing_control_worker_spec.rb' + - 'ee/spec/workers/elastic_remove_expired_namespace_subscriptions_from_index_cron_worker_spec.rb' + - 'ee/spec/workers/geo/secondary/registry_consistency_worker_spec.rb' + - 'ee/spec/workers/geo/verification_state_backfill_worker_spec.rb' + - 'qa/qa/specs/features/browser_ui/3_create/jira/jira_basic_integration_spec.rb' + - 'qa/qa/specs/features/browser_ui/5_package/dependency_proxy/dependency_proxy_spec.rb' + - 'qa/qa/specs/features/browser_ui/5_package/package_registry/composer_registry_spec.rb' + - 'qa/qa/specs/features/browser_ui/5_package/package_registry/generic_repository_spec.rb' + - 'qa/qa/specs/features/browser_ui/5_package/package_registry/pypi_repository_spec.rb' + - 'qa/qa/specs/features/ee/browser_ui/12_geo/wiki_http_push_to_secondary_spec.rb' + - 'qa/qa/specs/features/ee/browser_ui/1_manage/instance/instance_audit_logs_spec.rb' + - 'qa/qa/specs/features/ee/browser_ui/1_manage/project/project_audit_logs_spec.rb' + - 'qa/qa/specs/features/ee/browser_ui/1_manage/project/project_templates_spec.rb' + - 'spec/commands/metrics_server/metrics_server_spec.rb' + - 'spec/controllers/autocomplete_controller_spec.rb' + - 'spec/controllers/concerns/controller_with_cross_project_access_check_spec.rb' + - 'spec/controllers/concerns/spammable_actions/captcha_check/html_format_actions_support_spec.rb' + - 'spec/controllers/concerns/spammable_actions/captcha_check/json_format_actions_support_spec.rb' + - 'spec/controllers/concerns/spammable_actions/captcha_check/rest_api_actions_support_spec.rb' + - 'spec/controllers/groups/boards_controller_spec.rb' + - 'spec/controllers/groups/dependency_proxy_for_containers_controller_spec.rb' + - 'spec/controllers/profiles/two_factor_auths_controller_spec.rb' + - 'spec/controllers/projects/blob_controller_spec.rb' + - 'spec/controllers/projects/boards_controller_spec.rb' + - 'spec/controllers/projects/commits_controller_spec.rb' + - 'spec/controllers/projects/compare_controller_spec.rb' + - 'spec/controllers/projects/deployments_controller_spec.rb' + - 'spec/controllers/projects/environments_controller_spec.rb' + - 'spec/controllers/projects/error_tracking/projects_controller_spec.rb' + - 'spec/controllers/projects/error_tracking/stack_traces_controller_spec.rb' + - 'spec/controllers/projects/error_tracking_controller_spec.rb' + - 'spec/controllers/projects/issues_controller_spec.rb' + - 'spec/controllers/projects/labels_controller_spec.rb' + - 'spec/controllers/projects/merge_requests/content_controller_spec.rb' + - 'spec/controllers/projects/merge_requests_controller_spec.rb' + - 'spec/controllers/projects/notes_controller_spec.rb' + - 'spec/controllers/projects/prometheus/alerts_controller_spec.rb' + - 'spec/controllers/projects/settings/ci_cd_controller_spec.rb' + - 'spec/controllers/projects/settings/operations_controller_spec.rb' + - 'spec/controllers/projects/tree_controller_spec.rb' + - 'spec/controllers/projects_controller_spec.rb' + - 'spec/controllers/search_controller_spec.rb' + - 'spec/controllers/snippets/notes_controller_spec.rb' + - 'spec/features/admin/admin_mode/login_spec.rb' + - 'spec/features/admin/admin_projects_spec.rb' + - 'spec/features/boards/issue_ordering_spec.rb' + - 'spec/features/boards/new_issue_spec.rb' + - 'spec/features/boards/reload_boards_on_browser_back_spec.rb' + - 'spec/features/dashboard/groups_list_spec.rb' + - 'spec/features/expand_collapse_diffs_spec.rb' + - 'spec/features/file_uploads/maven_package_spec.rb' + - 'spec/features/groups/container_registry_spec.rb' + - 'spec/features/groups/group_settings_spec.rb' + - 'spec/features/issues/filtered_search/dropdown_hint_spec.rb' + - 'spec/features/markdown/markdown_spec.rb' + - 'spec/features/merge_request/user_merges_when_pipeline_succeeds_spec.rb' + - 'spec/features/merge_request/user_sees_versions_spec.rb' + - 'spec/features/oauth_login_spec.rb' + - 'spec/features/profiles/password_spec.rb' + - 'spec/features/projects/clusters/gcp_spec.rb' + - 'spec/features/projects/container_registry_spec.rb' + - 'spec/features/projects/feature_flags/user_deletes_feature_flag_spec.rb' + - 'spec/features/projects/files/user_creates_files_spec.rb' + - 'spec/features/projects/issuable_templates_spec.rb' + - 'spec/features/projects/show/user_sees_git_instructions_spec.rb' + - 'spec/features/projects/show/user_sees_setup_shortcut_buttons_spec.rb' + - 'spec/features/projects/user_sees_sidebar_spec.rb' + - 'spec/features/protected_branches_spec.rb' + - 'spec/features/snippets/spam_snippets_spec.rb' + - 'spec/features/users/login_spec.rb' + - 'spec/graphql/mutations/design_management/move_spec.rb' + - 'spec/helpers/commits_helper_spec.rb' + - 'spec/helpers/invite_members_helper_spec.rb' + - 'spec/helpers/projects_helper_spec.rb' + - 'spec/helpers/search_helper_spec.rb' + - 'spec/helpers/users_helper_spec.rb' + - 'spec/initializers/omniauth_spec.rb' + - 'spec/initializers/validate_database_config_spec.rb' + - 'spec/lib/api/entities/merge_request_changes_spec.rb' + - 'spec/lib/api/helpers/variables_helpers_spec.rb' + - 'spec/lib/api/helpers_spec.rb' + - 'spec/lib/backup/manager_spec.rb' + - 'spec/lib/banzai/reference_redactor_spec.rb' + - 'spec/lib/bulk_imports/ndjson_pipeline_spec.rb' + - 'spec/lib/bulk_imports/projects/pipelines/project_attributes_pipeline_spec.rb' + - 'spec/lib/container_registry/gitlab_api_client_spec.rb' + - 'spec/lib/file_size_validator_spec.rb' + - 'spec/lib/gitlab/alert_management/fingerprint_spec.rb' + - 'spec/lib/gitlab/auth/request_authenticator_spec.rb' + - 'spec/lib/gitlab/auth_spec.rb' + - 'spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb' + - 'spec/lib/gitlab/background_migration/legacy_upload_mover_spec.rb' + - 'spec/lib/gitlab/bitbucket_server_import/importer_spec.rb' + - 'spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb' + - 'spec/lib/gitlab/checks/changes_access_spec.rb' + - 'spec/lib/gitlab/checks/matching_merge_request_spec.rb' + - 'spec/lib/gitlab/checks/single_change_access_spec.rb' + - 'spec/lib/gitlab/ci/artifact_file_reader_spec.rb' + - 'spec/lib/gitlab/ci/build/prerequisite/factory_spec.rb' + - 'spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb' + - 'spec/lib/gitlab/ci/build/rules/rule/clause/exists_spec.rb' + - 'spec/lib/gitlab/ci/config/entry/ports_spec.rb' + - 'spec/lib/gitlab/ci/config/entry/processable_spec.rb' + - 'spec/lib/gitlab/ci/parsers/test/junit_spec.rb' + - 'spec/lib/gitlab/ci/pipeline/chain/cancel_pending_pipelines_spec.rb' + - 'spec/lib/gitlab/ci/pipeline/chain/command_spec.rb' + - 'spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb' + - 'spec/lib/gitlab/ci/status/build/failed_spec.rb' + - 'spec/lib/gitlab/ci/trace/archive_spec.rb' + - 'spec/lib/gitlab/ci/trace/remote_checksum_spec.rb' + - 'spec/lib/gitlab/ci/yaml_processor_spec.rb' + - 'spec/lib/gitlab/cleanup/orphan_lfs_file_references_spec.rb' + - 'spec/lib/gitlab/cleanup/project_uploads_spec.rb' + - 'spec/lib/gitlab/cleanup/remote_uploads_spec.rb' + - 'spec/lib/gitlab/contributions_calendar_spec.rb' + - 'spec/lib/gitlab/current_settings_spec.rb' + - 'spec/lib/gitlab/daemon_spec.rb' + - 'spec/lib/gitlab/database/background_migration/batched_migration_spec.rb' + - 'spec/lib/gitlab/database/load_balancing/host_spec.rb' + - 'spec/lib/gitlab/database/load_balancing/load_balancer_spec.rb' + - 'spec/lib/gitlab/database/migration_helpers_spec.rb' + - 'spec/lib/gitlab/database/migrations/background_migration_helpers_spec.rb' + - 'spec/lib/gitlab/database/migrations/runner_spec.rb' + - 'spec/lib/gitlab/database/partitioning_migration_helpers/table_management_helpers_spec.rb' + - 'spec/lib/gitlab/database/partitioning_spec.rb' + - 'spec/lib/gitlab/database/query_analyzer_spec.rb' + - 'spec/lib/gitlab/database/with_lock_retries_outside_transaction_spec.rb' + - 'spec/lib/gitlab/database/with_lock_retries_spec.rb' + - 'spec/lib/gitlab/database_importers/common_metrics/importer_spec.rb' + - 'spec/lib/gitlab/database_importers/instance_administrators/create_group_spec.rb' + - 'spec/lib/gitlab/database_importers/self_monitoring/project/create_service_spec.rb' + - 'spec/lib/gitlab/diff/highlight_cache_spec.rb' + - 'spec/lib/gitlab/email/service_desk_receiver_spec.rb' + - 'spec/lib/gitlab/error_tracking_spec.rb' + - 'spec/lib/gitlab/faraday/error_callback_spec.rb' + - 'spec/lib/gitlab/fips_spec.rb' + - 'spec/lib/gitlab/git/repository_spec.rb' + - 'spec/lib/gitlab/git_access_snippet_spec.rb' + - 'spec/lib/gitlab/gitaly_client/commit_service_spec.rb' + - 'spec/lib/gitlab/gitaly_client/operation_service_spec.rb' + - 'spec/lib/gitlab/gitaly_client/repository_service_spec.rb' + - 'spec/lib/gitlab/gitaly_client_spec.rb' + - 'spec/lib/gitlab/github_import/importer/diff_note_importer_spec.rb' + - 'spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb' + - 'spec/lib/gitlab/github_import/parallel_importer_spec.rb' + - 'spec/lib/gitlab/github_import/parallel_scheduling_spec.rb' + - 'spec/lib/gitlab/github_import/user_finder_spec.rb' + - 'spec/lib/gitlab/gpg_spec.rb' + - 'spec/lib/gitlab/graphql/generic_tracing_spec.rb' + - 'spec/lib/gitlab/health_checks/gitaly_check_spec.rb' + - 'spec/lib/gitlab/health_checks/probes/collection_spec.rb' + - 'spec/lib/gitlab/health_checks/puma_check_spec.rb' + - 'spec/lib/gitlab/http_spec.rb' + - 'spec/lib/gitlab/import_export/base/relation_factory_spec.rb' + - 'spec/lib/gitlab/import_export/base/relation_object_saver_spec.rb' + - 'spec/lib/gitlab/import_export/command_line_util_spec.rb' + - 'spec/lib/gitlab/import_export/group/tree_restorer_spec.rb' + - 'spec/lib/gitlab/import_export/import_failure_service_spec.rb' + - 'spec/lib/gitlab/import_export/json/legacy_reader/shared_example.rb' + - 'spec/lib/gitlab/import_export/json/ndjson_reader_spec.rb' + - 'spec/lib/gitlab/import_export/lfs_saver_spec.rb' + - 'spec/lib/gitlab/import_export/project/tree_restorer_spec.rb' + - 'spec/lib/gitlab/import_export/reader_spec.rb' + - 'spec/lib/gitlab/import_export/saver_spec.rb' + - 'spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb' + - 'spec/lib/gitlab/import_export/snippets_repo_restorer_spec.rb' + - 'spec/lib/gitlab/jira_import/labels_importer_spec.rb' + - 'spec/lib/gitlab/kas/client_spec.rb' + - 'spec/lib/gitlab/kubernetes/helm/api_spec.rb' + - 'spec/lib/gitlab/kubernetes/kube_client_spec.rb' + - 'spec/lib/gitlab/kubernetes/kubeconfig/template_spec.rb' + - 'spec/lib/gitlab/memory/instrumentation_spec.rb' + - 'spec/lib/gitlab/metrics/boot_time_tracker_spec.rb' + - 'spec/lib/gitlab/metrics/exporter/metrics_middleware_spec.rb' + - 'spec/lib/gitlab/metrics/samplers/puma_sampler_spec.rb' + - 'spec/lib/gitlab/middleware/memory_report_spec.rb' + - 'spec/lib/gitlab/middleware/multipart_spec.rb' + - 'spec/lib/gitlab/omniauth_initializer_spec.rb' + - 'spec/lib/gitlab/pagination/gitaly_keyset_pager_spec.rb' + - 'spec/lib/gitlab/patch/database_config_spec.rb' + - 'spec/lib/gitlab/project_search_results_spec.rb' + - 'spec/lib/gitlab/redis/queues_spec.rb' + - 'spec/lib/gitlab/repository_cache_adapter_spec.rb' + - 'spec/lib/gitlab/sidekiq_daemon/monitor_spec.rb' + - 'spec/lib/gitlab/tracking/destinations/snowplow_spec.rb' + - 'spec/lib/gitlab/usage/metrics/instrumentations/collected_data_categories_metric_spec.rb' + - 'spec/lib/gitlab/usage/metrics/instrumentations/generic_metric_spec.rb' + - 'spec/lib/gitlab/usage_data/topology_spec.rb' + - 'spec/lib/gitlab/usage_data_spec.rb' + - 'spec/lib/gitlab/utils/usage_data_spec.rb' + - 'spec/lib/gitlab/verify/job_artifacts_spec.rb' + - 'spec/lib/gitlab/verify/lfs_objects_spec.rb' + - 'spec/lib/gitlab/verify/uploads_spec.rb' + - 'spec/lib/gitlab/zentao/query_spec.rb' + - 'spec/lib/gitlab_spec.rb' + - 'spec/lib/learn_gitlab/onboarding_spec.rb' + - 'spec/lib/omni_auth/strategies/jwt_spec.rb' + - 'spec/lib/prometheus/pid_provider_spec.rb' + - 'spec/lib/sidebars/projects/menus/external_issue_tracker_menu_spec.rb' + - 'spec/lib/sidebars/projects/menus/external_wiki_menu_spec.rb' + - 'spec/lib/sidebars/projects/menus/learn_gitlab_menu_spec.rb' + - 'spec/mailers/emails/service_desk_spec.rb' + - 'spec/metrics_server/metrics_server_spec.rb' + - 'spec/migrations/20210406144743_backfill_total_tuple_count_for_batched_migrations_spec.rb' + - 'spec/models/ability_spec.rb' + - 'spec/models/application_setting_spec.rb' + - 'spec/models/ci/build_spec.rb' + - 'spec/models/ci/namespace_mirror_spec.rb' + - 'spec/models/ci/pipeline_spec.rb' + - 'spec/models/ci/runner_spec.rb' + - 'spec/models/clusters/applications/cert_manager_spec.rb' + - 'spec/models/clusters/platforms/kubernetes_spec.rb' + - 'spec/models/clusters/providers/aws_spec.rb' + - 'spec/models/clusters/providers/gcp_spec.rb' + - 'spec/models/commit_range_spec.rb' + - 'spec/models/concerns/cacheable_attributes_spec.rb' + - 'spec/models/concerns/featurable_spec.rb' + - 'spec/models/concerns/issuable_spec.rb' + - 'spec/models/container_repository_spec.rb' + - 'spec/models/deployment_metrics_spec.rb' + - 'spec/models/design_management/version_spec.rb' + - 'spec/models/environment_spec.rb' + - 'spec/models/event_spec.rb' + - 'spec/models/group_spec.rb' + - 'spec/models/integrations/emails_on_push_spec.rb' + - 'spec/models/member_spec.rb' + - 'spec/models/merge_request_diff_spec.rb' + - 'spec/models/merge_request_spec.rb' + - 'spec/models/personal_access_token_spec.rb' + - 'spec/models/postgresql/replication_slot_spec.rb' + - 'spec/models/project_import_state_spec.rb' + - 'spec/models/project_spec.rb' + - 'spec/models/repository_spec.rb' + - 'spec/models/route_spec.rb' + - 'spec/models/snippet_repository_spec.rb' + - 'spec/models/snippet_spec.rb' + - 'spec/models/ssh_host_key_spec.rb' + - 'spec/models/user_spec.rb' + - 'spec/policies/ci/bridge_policy_spec.rb' + - 'spec/presenters/ci/build_presenter_spec.rb' + - 'spec/presenters/ci/pipeline_presenter_spec.rb' + - 'spec/presenters/commit_presenter_spec.rb' + - 'spec/presenters/commit_status_presenter_spec.rb' + - 'spec/presenters/group_member_presenter_spec.rb' + - 'spec/presenters/project_member_presenter_spec.rb' + - 'spec/requests/api/avatar_spec.rb' + - 'spec/requests/api/ci/runner/jobs_request_post_spec.rb' + - 'spec/requests/api/ci/runner/runners_post_spec.rb' + - 'spec/requests/api/graphql/mutations/award_emojis/add_spec.rb' + - 'spec/requests/api/graphql/mutations/award_emojis/toggle_spec.rb' + - 'spec/requests/api/graphql/mutations/jira_import/import_users_spec.rb' + - 'spec/requests/api/graphql/mutations/notes/update/image_diff_note_spec.rb' + - 'spec/requests/api/graphql/project/error_tracking/sentry_detailed_error_request_spec.rb' + - 'spec/requests/api/graphql/terraform/state/lock_spec.rb' + - 'spec/requests/api/graphql/terraform/state/unlock_spec.rb' + - 'spec/requests/api/group_export_spec.rb' + - 'spec/requests/api/group_import_spec.rb' + - 'spec/requests/api/groups_spec.rb' + - 'spec/requests/api/helpers_spec.rb' + - 'spec/requests/api/internal/base_spec.rb' + - 'spec/requests/api/issues/post_projects_issues_spec.rb' + - 'spec/requests/api/issues/put_projects_issues_spec.rb' + - 'spec/requests/api/merge_requests_spec.rb' + - 'spec/requests/api/npm_project_packages_spec.rb' + - 'spec/requests/api/project_debian_distributions_spec.rb' + - 'spec/requests/api/project_packages_spec.rb' + - 'spec/requests/api/projects_spec.rb' + - 'spec/requests/api/protected_branches_spec.rb' + - 'spec/requests/api/v3/github_spec.rb' + - 'spec/requests/health_controller_spec.rb' + - 'spec/requests/import/gitlab_groups_controller_spec.rb' + - 'spec/requests/openid_connect_spec.rb' + - 'spec/requests/projects/merge_requests/diffs_spec.rb' + - 'spec/rubocop/cop/performance/ar_count_each_spec.rb' + - 'spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb' + - 'spec/scripts/setup/find_jh_branch_spec.rb' + - 'spec/serializers/diffs_metadata_entity_spec.rb' + - 'spec/serializers/merge_request_diff_entity_spec.rb' + - 'spec/services/auto_merge/merge_when_pipeline_succeeds_service_spec.rb' + - 'spec/services/award_emojis/add_service_spec.rb' + - 'spec/services/captcha/captcha_verification_service_spec.rb' + - 'spec/services/ci/create_pipeline_service/logger_spec.rb' + - 'spec/services/ci/create_pipeline_service_spec.rb' + - 'spec/services/ci/delete_objects_service_spec.rb' + - 'spec/services/ci/generate_kubeconfig_service_spec.rb' + - 'spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb' + - 'spec/services/ci/job_artifacts/destroy_batch_service_spec.rb' + - 'spec/services/ci/register_job_service_spec.rb' + - 'spec/services/clusters/applications/check_installation_progress_service_spec.rb' + - 'spec/services/clusters/applications/check_uninstall_progress_service_spec.rb' + - 'spec/services/clusters/applications/create_service_spec.rb' + - 'spec/services/clusters/applications/install_service_spec.rb' + - 'spec/services/clusters/applications/patch_service_spec.rb' + - 'spec/services/clusters/applications/prometheus_update_service_spec.rb' + - 'spec/services/clusters/applications/uninstall_service_spec.rb' + - 'spec/services/clusters/applications/upgrade_service_spec.rb' + - 'spec/services/clusters/aws/fetch_credentials_service_spec.rb' + - 'spec/services/clusters/integrations/prometheus_health_check_service_spec.rb' + - 'spec/services/container_expiration_policies/cleanup_service_spec.rb' + - 'spec/services/database/consistency_check_service_spec.rb' + - 'spec/services/dependency_proxy/find_cached_manifest_service_spec.rb' + - 'spec/services/dependency_proxy/image_ttl_group_policies/update_service_spec.rb' + - 'spec/services/design_management/copy_design_collection/copy_service_spec.rb' + - 'spec/services/design_management/generate_image_versions_service_spec.rb' + - 'spec/services/design_management/save_designs_service_spec.rb' + - 'spec/services/discussions/capture_diff_note_position_service_spec.rb' + - 'spec/services/environments/reset_auto_stop_service_spec.rb' + - 'spec/services/error_tracking/base_service_spec.rb' + - 'spec/services/error_tracking/issue_details_service_spec.rb' + - 'spec/services/error_tracking/issue_latest_event_service_spec.rb' + - 'spec/services/error_tracking/issue_update_service_spec.rb' + - 'spec/services/error_tracking/list_projects_service_spec.rb' + - 'spec/services/git/base_hooks_service_spec.rb' + - 'spec/services/git/branch_push_service_spec.rb' + - 'spec/services/git/wiki_push_service/change_spec.rb' + - 'spec/services/groups/update_service_spec.rb' + - 'spec/services/import/github_service_spec.rb' + - 'spec/services/import/gitlab_projects/create_project_service_spec.rb' + - 'spec/services/import/gitlab_projects/file_acquisition_strategies/remote_file_s3_spec.rb' + - 'spec/services/issues/relative_position_rebalancing_service_spec.rb' + - 'spec/services/issues/zoom_link_service_spec.rb' + - 'spec/services/jira_import/start_import_service_spec.rb' + - 'spec/services/labels/update_service_spec.rb' + - 'spec/services/lfs/file_transformer_spec.rb' + - 'spec/services/loose_foreign_keys/batch_cleaner_service_spec.rb' + - 'spec/services/members/destroy_service_spec.rb' + - 'spec/services/merge_requests/cleanup_refs_service_spec.rb' + - 'spec/services/merge_requests/merge_service_spec.rb' + - 'spec/services/merge_requests/mergeability/check_broken_status_service_spec.rb' + - 'spec/services/merge_requests/mergeability/check_ci_status_service_spec.rb' + - 'spec/services/merge_requests/mergeability/check_discussions_status_service_spec.rb' + - 'spec/services/merge_requests/mergeability/check_draft_status_service_spec.rb' + - 'spec/services/merge_requests/mergeability/check_open_status_service_spec.rb' + - 'spec/services/merge_requests/mergeability/run_checks_service_spec.rb' + - 'spec/services/merge_requests/mergeability_check_service_spec.rb' + - 'spec/services/merge_requests/squash_service_spec.rb' + - 'spec/services/merge_requests/update_service_spec.rb' + - 'spec/services/notes/quick_actions_service_spec.rb' + - 'spec/services/notification_recipients/builder/default_spec.rb' + - 'spec/services/notification_recipients/builder/new_note_spec.rb' + - 'spec/services/packages/debian/process_changes_service_spec.rb' + - 'spec/services/packages/generic/create_package_file_service_spec.rb' + - 'spec/services/packages/helm/extract_file_metadata_service_spec.rb' + - 'spec/services/packages/helm/process_file_service_spec.rb' + - 'spec/services/packages/mark_package_files_for_destruction_service_spec.rb' + - 'spec/services/packages/maven/metadata/sync_service_spec.rb' + - 'spec/services/packages/rubygems/process_gem_service_spec.rb' + - 'spec/services/packages/update_package_file_service_spec.rb' + - 'spec/services/pages/zip_directory_service_spec.rb' + - 'spec/services/pages_domains/obtain_lets_encrypt_certificate_service_spec.rb' + - 'spec/services/projects/after_import_service_spec.rb' + - 'spec/services/projects/after_rename_service_spec.rb' + - 'spec/services/projects/branches_by_mode_service_spec.rb' + - 'spec/services/projects/container_repository/cleanup_tags_service_spec.rb' + - 'spec/services/projects/container_repository/delete_tags_service_spec.rb' + - 'spec/services/projects/container_repository/gitlab/delete_tags_service_spec.rb' + - 'spec/services/projects/container_repository/third_party/delete_tags_service_spec.rb' + - 'spec/services/projects/create_from_template_service_spec.rb' + - 'spec/services/projects/destroy_rollback_service_spec.rb' + - 'spec/services/projects/destroy_service_spec.rb' + - 'spec/services/projects/import_export/export_service_spec.rb' + - 'spec/services/projects/import_service_spec.rb' + - 'spec/services/projects/lfs_pointers/lfs_download_service_spec.rb' + - 'spec/services/projects/lfs_pointers/lfs_object_download_list_service_spec.rb' + - 'spec/services/projects/overwrite_project_service_spec.rb' + - 'spec/services/projects/refresh_build_artifacts_size_statistics_service_spec.rb' + - 'spec/services/projects/transfer_service_spec.rb' + - 'spec/services/projects/update_pages_service_spec.rb' + - 'spec/services/projects/update_remote_mirror_service_spec.rb' + - 'spec/services/projects/update_repository_storage_service_spec.rb' + - 'spec/services/protected_branches/create_service_spec.rb' + - 'spec/services/protected_branches/destroy_service_spec.rb' + - 'spec/services/protected_branches/update_service_spec.rb' + - 'spec/services/repositories/destroy_rollback_service_spec.rb' + - 'spec/services/repositories/destroy_service_spec.rb' + - 'spec/services/search_service_spec.rb' + - 'spec/services/serverless/associate_domain_service_spec.rb' + - 'spec/services/snippets/update_repository_storage_service_spec.rb' + - 'spec/services/suggestions/apply_service_spec.rb' + - 'spec/services/suggestions/create_service_spec.rb' + - 'spec/services/system_notes/commit_service_spec.rb' + - 'spec/services/system_notes/issuables_service_spec.rb' + - 'spec/services/user_project_access_changed_service_spec.rb' + - 'spec/support/services/issuable_update_service_shared_examples.rb' + - 'spec/support/services/migrate_to_ghost_user_service_shared_examples.rb' + - 'spec/support/shared_contexts/sentry_error_tracking_shared_context.rb' + - 'spec/support/shared_examples/controllers/wiki_actions_shared_examples.rb' + - 'spec/support/shared_examples/csp.rb' + - 'spec/support/shared_examples/features/wiki/user_views_wiki_page_shared_examples.rb' + - 'spec/support/shared_examples/graphql/notes_creation_shared_examples.rb' + - 'spec/support/shared_examples/lib/gitlab/ci/ci_trace_shared_examples.rb' + - 'spec/support/shared_examples/lib/gitlab/diff_file_collections_shared_examples.rb' + - 'spec/support/shared_examples/lib/wikis_api_examples.rb' + - 'spec/support/shared_examples/metrics/sampler_shared_examples.rb' + - 'spec/support/shared_examples/models/concerns/counter_attribute_shared_examples.rb' + - 'spec/support/shared_examples/models/concerns/has_wiki_shared_examples.rb' + - 'spec/support/shared_examples/models/concerns/update_namespace_statistics_shared_examples.rb' + - 'spec/support/shared_examples/models/mentionable_shared_examples.rb' + - 'spec/support/shared_examples/models/wiki_shared_examples.rb' + - 'spec/support/shared_examples/quick_actions/issuable/close_quick_action_shared_examples.rb' + - 'spec/support/shared_examples/requests/api/helm_packages_shared_examples.rb' + - 'spec/support/shared_examples/requests/api/repositories_shared_context.rb' + - 'spec/support/shared_examples/serializers/note_entity_shared_examples.rb' + - 'spec/support/shared_examples/services/boards/boards_recent_visit_shared_examples.rb' + - 'spec/support/shared_examples/services/error_tracking_service_shared_examples.rb' + - 'spec/support/shared_examples/services/projects/update_repository_storage_service_shared_examples.rb' + - 'spec/support/shared_examples/services/repositories/housekeeping_shared_examples.rb' + - 'spec/support/shared_examples/services/wiki_pages/destroy_service_shared_examples.rb' + - 'spec/support/shared_examples/uploaders/object_storage_shared_examples.rb' + - 'spec/support/shared_examples/workers/background_migration_worker_shared_examples.rb' + - 'spec/support/shared_examples/workers/concerns/git_garbage_collect_methods_shared_examples.rb' + - 'spec/tasks/gitlab/backup_rake_spec.rb' + - 'spec/tasks/gitlab/cleanup_rake_spec.rb' + - 'spec/tasks/gitlab/gitaly_rake_spec.rb' + - 'spec/tasks/gitlab/praefect_rake_spec.rb' + - 'spec/tasks/gitlab/task_helpers_spec.rb' + - 'spec/tooling/danger/feature_flag_spec.rb' + - 'spec/tooling/danger/specs_spec.rb' + - 'spec/tooling/rspec_flaky/listener_spec.rb' + - 'spec/uploaders/file_mover_spec.rb' + - 'spec/uploaders/gitlab_uploader_spec.rb' + - 'spec/uploaders/object_storage_spec.rb' + - 'spec/uploaders/workers/object_storage/migrate_uploads_worker_spec.rb' + - 'spec/views/shared/runners/_runner_details.html.haml_spec.rb' + - 'spec/workers/build_finished_worker_spec.rb' + - 'spec/workers/ci/build_finished_worker_spec.rb' + - 'spec/workers/concerns/gitlab/github_import/object_importer_spec.rb' + - 'spec/workers/concerns/limited_capacity/job_tracker_spec.rb' + - 'spec/workers/concerns/limited_capacity/worker_spec.rb' + - 'spec/workers/create_commit_signature_worker_spec.rb' + - 'spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb' + - 'spec/workers/gitlab/jira_import/import_issue_worker_spec.rb' + - 'spec/workers/gitlab/jira_import/stage/finish_import_worker_spec.rb' + - 'spec/workers/gitlab_performance_bar_stats_worker_spec.rb' + - 'spec/workers/group_import_worker_spec.rb' + - 'spec/workers/integrations/create_external_cross_reference_worker_spec.rb' + - 'spec/workers/packages/helm/extraction_worker_spec.rb' + - 'spec/workers/packages/nuget/extraction_worker_spec.rb' + - 'spec/workers/post_receive_spec.rb' + - 'spec/workers/projects/git_garbage_collect_worker_spec.rb' + - 'spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb' + - 'spec/workers/run_pipeline_schedule_worker_spec.rb' + - 'spec/workers/service_desk_email_receiver_worker_spec.rb' + - 'spec/workers/upload_checksum_worker_spec.rb' diff --git a/app/assets/javascripts/diffs/components/diff_content.vue b/app/assets/javascripts/diffs/components/diff_content.vue index b4bffdcb07f..1eba12a3ae9 100644 --- a/app/assets/javascripts/diffs/components/diff_content.vue +++ b/app/assets/javascripts/diffs/components/diff_content.vue @@ -156,7 +156,7 @@ export default { :link-href="author.path" :img-src="author.avatar_url" :img-alt="author.name" - :img-size="40" + :img-size="48" class="d-none d-sm-block new-comment" /> - [Deprecated](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/78132) in GitLab 14.9. WARNING: -This feature is in its end-of-life process. It is [deprecated](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/78132) in GitLab -14.9 and replaced with `artifacts:reports:coverage_report` in 14.10. +This feature is in its end-of-life process. It is [deprecated](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/78132) +in GitLab 14.9 and planned for removal in GitLab 15.0. The alternative `artifacts:reports:coverage_report` +is available GitLab 14.10. The `cobertura` report collects [Cobertura coverage XML files](../../user/project/merge_requests/test_coverage_visualization.md). The collected Cobertura coverage reports upload to GitLab as an artifact. @@ -100,7 +101,7 @@ JavaScript, Python, and Ruby. ## `artifacts:reports:coverage_report` -> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/344533) in GitLab 14.9. +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/344533) in GitLab 14.10. Use `coverage_report` to collect coverage report in Cobertura format, similar to `artifacts:reports:cobertura`. diff --git a/doc/development/service_ping/metrics_instrumentation.md b/doc/development/service_ping/metrics_instrumentation.md index 3d56f3e777f..42f93d6ae24 100644 --- a/doc/development/service_ping/metrics_instrumentation.md +++ b/doc/development/service_ping/metrics_instrumentation.md @@ -40,6 +40,7 @@ We have built a domain-specific language (DSL) to define the metrics instrumenta - `start`: Specifies the start value of the batch counting, by default is `relation.minimum(:id)`. - `finish`: Specifies the end value of the batch counting, by default is `relation.maximum(:id)`. - `cache_start_and_finish_as`: Specifies the cache key for `start` and `finish` values and sets up caching them. Use this call when `start` and `finish` are expensive queries that should be reused between different metric calculations. +- `available?`: Specifies whether the metric should be reported. The default is `true`. [Example of a merge request that adds a database metric](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/60022). @@ -123,6 +124,37 @@ options: counter_class: SourceCodeCounter ``` +### Availability-restrained Redis metrics + +If the Redis metric should only be available in the report under some conditions, then you must specify these conditions in a new class that is a child of the `RedisMetric` class. + +```ruby +# frozen_string_literal: true + +module Gitlab + module Usage + module Metrics + module Instrumentations + class MergeUsageCountRedisMetric < RedisMetric + available? { Feature.enabled?(:merge_usage_data_missing_key_paths) } + end + end + end + end +end +``` + +You must also use the class's name in the YAML setup. + +```yaml +time_frame: all +data_source: redis +instrumentation_class: 'MergeUsageCountRedisMetric' +options: + event: pushes + counter_class: SourceCodeCounter +``` + ## Redis HyperLogLog metrics [Example of a merge request that adds a `RedisHLL` metric](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/61685). @@ -138,8 +170,42 @@ options: - i_quickactions_approve ``` +### Availability-restrained Redis HyperLogLog metrics + +If the Redis HyperLogLog metric should only be available in the report under some conditions, then you must specify these conditions in a new class that is a child of the `RedisHLLMetric` class. + +```ruby +# frozen_string_literal: true + +module Gitlab + module Usage + module Metrics + module Instrumentations + class MergeUsageCountRedisHLLMetric < RedisHLLMetric + available? { Feature.enabled?(:merge_usage_data_missing_key_paths) } + end + end + end + end +end +``` + +You must also use the class's name in the YAML setup. + +```yaml +time_frame: 28d +data_source: redis_hll +instrumentation_class: 'MergeUsageCountRedisHLLMetric' +options: + events: + - i_quickactions_approve +``` + ## Generic metrics +- `value`: Specifies the value of the metric. +- `available?`: Specifies whether the metric should be reported. The default is `true`. + [Example of a merge request that adds a generic metric](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/60256). ```ruby diff --git a/lib/gitlab/database/query_analyzer.rb b/lib/gitlab/database/query_analyzer.rb index 0c78dda734c..6f64d04270f 100644 --- a/lib/gitlab/database/query_analyzer.rb +++ b/lib/gitlab/database/query_analyzer.rb @@ -30,28 +30,50 @@ module Gitlab end end - def within(user_analyzers = nil) - # Due to singleton nature of analyzers - # only an outer invocation of the `.within` - # is allowed to initialize them - if already_within? - raise 'Query analyzers are already defined, cannot re-define them.' if user_analyzers - - return yield - end - - begin!(user_analyzers || all_analyzers) + def within(analyzers = all_analyzers) + newly_enabled_analyzers = begin!(analyzers) begin yield ensure - end! + end!(newly_enabled_analyzers) end end - def already_within? - # If analyzers are set they are already configured - !enabled_analyzers.nil? + # Enable query analyzers (only the ones that were not yet enabled) + # Returns a list of newly enabled analyzers + def begin!(analyzers) + analyzers.select do |analyzer| + next if enabled_analyzers.include?(analyzer) + + if analyzer.enabled? + analyzer.begin! + enabled_analyzers.append(analyzer) + + true + end + rescue StandardError, ::Gitlab::Database::QueryAnalyzers::Base::QueryAnalyzerError => e + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e) + + false + end + end + + # Disable enabled query analyzers (only the ones that were enabled previously) + def end!(analyzers) + analyzers.each do |analyzer| + next unless enabled_analyzers.delete(analyzer) + + analyzer.end! + rescue StandardError, ::Gitlab::Database::QueryAnalyzers::Base::QueryAnalyzerError => e + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e) + end + end + + private + + def enabled_analyzers + Thread.current[:query_analyzer_enabled_analyzers] ||= [] end def process_sql(sql, connection) @@ -71,40 +93,6 @@ module Gitlab end end - # Enable query analyzers - def begin!(analyzers = all_analyzers) - analyzers = analyzers.select do |analyzer| - if analyzer.enabled? - analyzer.begin! - - true - end - rescue StandardError, ::Gitlab::Database::QueryAnalyzers::Base::QueryAnalyzerError => e - Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e) - - false - end - - Thread.current[:query_analyzer_enabled_analyzers] = analyzers - end - - # Disable enabled query analyzers - def end! - enabled_analyzers.select do |analyzer| - analyzer.end! - rescue StandardError, ::Gitlab::Database::QueryAnalyzers::Base::QueryAnalyzerError => e - Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e) - end - - Thread.current[:query_analyzer_enabled_analyzers] = nil - end - - private - - def enabled_analyzers - Thread.current[:query_analyzer_enabled_analyzers] - end - def parse(sql, connection) parsed = PgQuery.parse(sql) return unless parsed diff --git a/lib/gitlab/usage/metric.rb b/lib/gitlab/usage/metric.rb index 24e044c5740..cf48aa49938 100644 --- a/lib/gitlab/usage/metric.rb +++ b/lib/gitlab/usage/metric.rb @@ -18,19 +18,25 @@ module Gitlab end def with_value - unflatten_key_path(intrumentation_object.value) + with_availability(proc { instrumentation_object.value }) end def with_instrumentation - unflatten_key_path(intrumentation_object.instrumentation) + with_availability(proc { instrumentation_object.instrumentation }) end def with_suggested_name - unflatten_key_path(intrumentation_object.suggested_name) + with_availability(proc { instrumentation_object.suggested_name }) end private + def with_availability(value_proc) + return {} unless instrumentation_object.available? + + unflatten_key_path(value_proc.call) + end + def unflatten_key_path(value) ::Gitlab::Usage::Metrics::KeyPathProcessor.process(definition.key_path, value) end @@ -39,8 +45,8 @@ module Gitlab "Gitlab::Usage::Metrics::Instrumentations::#{definition.instrumentation_class}" end - def intrumentation_object - instrumentation_class.constantize.new( + def instrumentation_object + @instrumentation_object ||= instrumentation_class.constantize.new( time_frame: definition.time_frame, options: definition.attributes[:options] ) diff --git a/lib/gitlab/usage/metrics/instrumentations/base_metric.rb b/lib/gitlab/usage/metrics/instrumentations/base_metric.rb index a264f9484f3..f76ed1753b2 100644 --- a/lib/gitlab/usage/metrics/instrumentations/base_metric.rb +++ b/lib/gitlab/usage/metrics/instrumentations/base_metric.rb @@ -11,6 +11,18 @@ module Gitlab attr_reader :time_frame attr_reader :options + class << self + def available?(&block) + return @metric_available = block if block_given? + + return @metric_available.call if instance_variable_defined?('@metric_available') + + true + end + + attr_reader :metric_available + end + def initialize(time_frame:, options: {}) @time_frame = time_frame @options = options @@ -19,6 +31,10 @@ module Gitlab def instrumentation value end + + def available? + self.class.available? + end end end end diff --git a/spec/lib/gitlab/database/query_analyzer_spec.rb b/spec/lib/gitlab/database/query_analyzer_spec.rb index 3b4cbc79de2..0b849063562 100644 --- a/spec/lib/gitlab/database/query_analyzer_spec.rb +++ b/spec/lib/gitlab/database/query_analyzer_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe Gitlab::Database::QueryAnalyzer, query_analyzers: false do let(:analyzer) { double(:query_analyzer) } - let(:user_analyzer) { double(:query_analyzer) } + let(:user_analyzer) { double(:user_query_analyzer) } let(:disabled_analyzer) { double(:disabled_query_analyzer) } before do @@ -49,14 +49,36 @@ RSpec.describe Gitlab::Database::QueryAnalyzer, query_analyzers: false do end end - it 'does not evaluate enabled? again do yield block' do - expect(analyzer).not_to receive(:enabled?) + it 'does initialize analyzer only once' do + expect(analyzer).to receive(:enabled?).once + expect(analyzer).to receive(:begin!).once + expect(analyzer).to receive(:end!).once expect { |b| described_class.instance.within(&b) }.to yield_control end - it 'raises exception when trying to re-define analyzers' do - expect { |b| described_class.instance.within([user_analyzer], &b) }.to raise_error /Query analyzers are already defined, cannot re-define them/ + it 'does initialize user analyzer when enabled' do + expect(user_analyzer).to receive(:enabled?).and_return(true) + expect(user_analyzer).to receive(:begin!) + expect(user_analyzer).to receive(:end!) + + expect { |b| described_class.instance.within([user_analyzer], &b) }.to yield_control + end + + it 'does initialize user analyzer only once' do + expect(user_analyzer).to receive(:enabled?).and_return(false, true) + expect(user_analyzer).to receive(:begin!).once + expect(user_analyzer).to receive(:end!).once + + expect { |b| described_class.instance.within([user_analyzer, user_analyzer, user_analyzer], &b) }.to yield_control + end + + it 'does not initializer user analyzer when disabled' do + expect(user_analyzer).to receive(:enabled?).and_return(false) + expect(user_analyzer).not_to receive(:begin!) + expect(user_analyzer).not_to receive(:end!) + + expect { |b| described_class.instance.within([user_analyzer], &b) }.to yield_control end end @@ -162,7 +184,7 @@ RSpec.describe Gitlab::Database::QueryAnalyzer, query_analyzers: false do def process_sql(sql) described_class.instance.within do ApplicationRecord.load_balancer.read_write do |connection| - described_class.instance.process_sql(sql, connection) + described_class.instance.send(:process_sql, sql, connection) end end end diff --git a/spec/lib/gitlab/database/query_analyzers/gitlab_schemas_metrics_spec.rb b/spec/lib/gitlab/database/query_analyzers/gitlab_schemas_metrics_spec.rb index b8c1ecd9089..0d687db0f96 100644 --- a/spec/lib/gitlab/database/query_analyzers/gitlab_schemas_metrics_spec.rb +++ b/spec/lib/gitlab/database/query_analyzers/gitlab_schemas_metrics_spec.rb @@ -140,7 +140,7 @@ RSpec.describe Gitlab::Database::QueryAnalyzers::GitlabSchemasMetrics, query_ana def process_sql(model, sql) Gitlab::Database::QueryAnalyzer.instance.within do # Skip load balancer and retrieve connection assigned to model - Gitlab::Database::QueryAnalyzer.instance.process_sql(sql, model.retrieve_connection) + Gitlab::Database::QueryAnalyzer.instance.send(:process_sql, sql, model.retrieve_connection) end end end diff --git a/spec/lib/gitlab/database/query_analyzers/restrict_allowed_schemas_spec.rb b/spec/lib/gitlab/database/query_analyzers/restrict_allowed_schemas_spec.rb index a2c7916fa01..261bef58bb6 100644 --- a/spec/lib/gitlab/database/query_analyzers/restrict_allowed_schemas_spec.rb +++ b/spec/lib/gitlab/database/query_analyzers/restrict_allowed_schemas_spec.rb @@ -155,7 +155,7 @@ RSpec.describe Gitlab::Database::QueryAnalyzers::RestrictAllowedSchemas, query_a yield if block_given? # Skip load balancer and retrieve connection assigned to model - Gitlab::Database::QueryAnalyzer.instance.process_sql(sql, model.retrieve_connection) + Gitlab::Database::QueryAnalyzer.instance.send(:process_sql, sql, model.retrieve_connection) end end end diff --git a/spec/lib/gitlab/usage/metric_spec.rb b/spec/lib/gitlab/usage/metric_spec.rb index 19d2d3048eb..10ae94e746b 100644 --- a/spec/lib/gitlab/usage/metric_spec.rb +++ b/spec/lib/gitlab/usage/metric_spec.rb @@ -51,4 +51,31 @@ RSpec.describe Gitlab::Usage::Metric do expect(described_class.new(issue_count_metric_definiton).with_suggested_name).to eq({ counts: { issues: 'count_issues' } }) end end + + context 'unavailable metric' do + let(:instrumentation_class) { "UnavailableMetric" } + let(:issue_count_metric_definiton) do + double(:issue_count_metric_definiton, + attributes.merge({ attributes: attributes, instrumentation_class: instrumentation_class }) + ) + end + + before do + unavailable_metric_class = Class.new(Gitlab::Usage::Metrics::Instrumentations::CountIssuesMetric) do + def available? + false + end + end + + stub_const("Gitlab::Usage::Metrics::Instrumentations::#{instrumentation_class}", unavailable_metric_class) + end + + [:with_value, :with_instrumentation, :with_suggested_name].each do |method_name| + describe "##{method_name}" do + it 'returns an empty hash' do + expect(described_class.new(issue_count_metric_definiton).public_send(method_name)).to eq({}) + end + end + end + end end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb index ea5ae1970de..cd7eb44c83d 100644 --- a/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb +++ b/spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb @@ -71,6 +71,33 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::DatabaseMetric do end end + context 'with availability defined' do + subject do + described_class.tap do |metric_class| + metric_class.relation { Issue } + metric_class.operation :count + metric_class.available? { false } + end.new(time_frame: 'all') + end + + it 'responds to #available? properly' do + expect(subject.available?).to eq(false) + end + end + + context 'with availability not defined' do + subject do + Class.new(described_class) do + relation { Issue } + operation :count + end.new(time_frame: 'all') + end + + it 'responds to #available? properly' do + expect(subject.available?).to eq(true) + end + end + context 'with cache_start_and_finish_as called' do subject do described_class.tap do |metric_class| diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/redis_hll_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/redis_hll_metric_spec.rb index 347a2c779cb..97306051533 100644 --- a/spec/lib/gitlab/usage/metrics/instrumentations/redis_hll_metric_spec.rb +++ b/spec/lib/gitlab/usage/metrics/instrumentations/redis_hll_metric_spec.rb @@ -25,4 +25,28 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::RedisHLLMetric, :clean_ it 'raise exception if events options is not present' do expect { described_class.new(time_frame: '28d') }.to raise_error(ArgumentError) end + + describe 'children classes' do + let(:options) { { events: ['i_quickactions_approve'] } } + + context 'availability not defined' do + subject { Class.new(described_class).new(time_frame: nil, options: options) } + + it 'returns default availability' do + expect(subject.available?).to eq(true) + end + end + + context 'availability defined' do + subject do + Class.new(described_class) do + available? { false } + end.new(time_frame: nil, options: options) + end + + it 'returns defined availability' do + expect(subject.available?).to eq(false) + end + end + end end diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/redis_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/redis_metric_spec.rb index fb3bd1ba834..831f775ec9a 100644 --- a/spec/lib/gitlab/usage/metrics/instrumentations/redis_metric_spec.rb +++ b/spec/lib/gitlab/usage/metrics/instrumentations/redis_metric_spec.rb @@ -20,4 +20,28 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::RedisMetric, :clean_git it 'raises an exception if counter_class option is not present' do expect { described_class.new(event: 'pushes') }.to raise_error(ArgumentError) end + + describe 'children classes' do + let(:options) { { event: 'pushes', counter_class: 'SourceCodeCounter' } } + + context 'availability not defined' do + subject { Class.new(described_class).new(time_frame: nil, options: options) } + + it 'returns default availability' do + expect(subject.available?).to eq(true) + end + end + + context 'availability defined' do + subject do + Class.new(described_class) do + available? { false } + end.new(time_frame: nil, options: options) + end + + it 'returns defined availability' do + expect(subject.available?).to eq(false) + end + end + end end diff --git a/spec/support/database/query_analyzer.rb b/spec/support/database/query_analyzer.rb index 6d6627d54b9..aaa1b3516a3 100644 --- a/spec/support/database/query_analyzer.rb +++ b/spec/support/database/query_analyzer.rb @@ -6,13 +6,17 @@ RSpec.configure do |config| config.before do |example| if example.metadata.fetch(:query_analyzers, true) - ::Gitlab::Database::QueryAnalyzer.instance.begin! + ::Gitlab::Database::QueryAnalyzer.instance.begin!( + ::Gitlab::Database::QueryAnalyzer.instance.all_analyzers + ) end end config.after do |example| if example.metadata.fetch(:query_analyzers, true) - ::Gitlab::Database::QueryAnalyzer.instance.end! + ::Gitlab::Database::QueryAnalyzer.instance.end!( + ::Gitlab::Database::QueryAnalyzer.instance.all_analyzers + ) end end end diff --git a/spec/support/shared_examples/services/issuable/destroy_service_shared_examples.rb b/spec/support/shared_examples/services/issuable/destroy_service_shared_examples.rb index e776c098fa0..31571b1ffb9 100644 --- a/spec/support/shared_examples/services/issuable/destroy_service_shared_examples.rb +++ b/spec/support/shared_examples/services/issuable/destroy_service_shared_examples.rb @@ -1,21 +1,33 @@ # frozen_string_literal: true -shared_examples_for 'service deleting todos' do +shared_examples_for 'service scheduling async deletes' do it 'destroys associated todos asynchronously' do - expect(TodosDestroyer::DestroyedIssuableWorker) + expect(worker_class) .to receive(:perform_async) .with(issuable.id, issuable.class.name) subject.execute(issuable) end + + it 'works inside a transaction' do + expect(worker_class) + .to receive(:perform_async) + .with(issuable.id, issuable.class.name) + + ApplicationRecord.transaction do + subject.execute(issuable) + end + end +end + +shared_examples_for 'service deleting todos' do + it_behaves_like 'service scheduling async deletes' do + let(:worker_class) { TodosDestroyer::DestroyedIssuableWorker } + end end shared_examples_for 'service deleting label links' do - it 'destroys associated label links asynchronously' do - expect(Issuable::LabelLinksDestroyWorker) - .to receive(:perform_async) - .with(issuable.id, issuable.class.name) - - subject.execute(issuable) + it_behaves_like 'service scheduling async deletes' do + let(:worker_class) { Issuable::LabelLinksDestroyWorker } end end diff --git a/tooling/danger/project_helper.rb b/tooling/danger/project_helper.rb index fc87498f5d0..ad58907c20d 100644 --- a/tooling/danger/project_helper.rb +++ b/tooling/danger/project_helper.rb @@ -26,6 +26,7 @@ module Tooling %r{\Adoc/.*(\.(md|png|gif|jpg|yml))\z} => :docs, %r{\A(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(\.md)?\z} => :docs, %r{\Adata/whats_new/} => :docs, + %r{\Adb/docs/.yml\z} => :docs, %r{\Adata/deprecations/} => :none, %r{\Adata/removals/} => :none,