From 20a18d1f9bf452c1dd2ef996bee50e34cfcb80f4 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 10 Aug 2022 21:09:39 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- .../system_notes/time_tracking_service.rb | 9 +- config/metrics/aggregates/common.yml | 3 + ...users_updating_work_item_dates_monthly.yml | 25 ++++++ ..._users_updating_work_item_dates_weekly.yml | 25 ++++++ doc/administration/geo/index.md | 4 +- doc/administration/geo/setup/index.md | 1 + doc/development/database/database_lab.md | 2 +- doc/development/migration_style_guide.md | 15 ++++ .../vulnerabilities/index.md | 4 +- doc/user/project/releases/index.md | 6 +- .../known_events/work_items.yml | 5 ++ .../work_item_activity_unique_counter.rb | 5 ++ lib/gitlab/utils/strong_memoize.rb | 2 +- .../work_item_activity_unique_counter_spec.rb | 8 ++ .../time_tracking_service_spec.rb | 82 ++++++++++++++++--- .../work_items/update_service_spec.rb | 10 +++ 16 files changed, 182 insertions(+), 24 deletions(-) create mode 100644 config/metrics/counts_28d/20220725193059_users_updating_work_item_dates_monthly.yml create mode 100644 config/metrics/counts_7d/20220725201348_users_updating_work_item_dates_weekly.yml diff --git a/app/services/system_notes/time_tracking_service.rb b/app/services/system_notes/time_tracking_service.rb index c867cce8032..68df52a03c7 100644 --- a/app/services/system_notes/time_tracking_service.rb +++ b/app/services/system_notes/time_tracking_service.rb @@ -19,10 +19,13 @@ module SystemNotes def change_start_date_or_due_date(changed_dates = {}) return if changed_dates.empty? - if noteable.is_a?(Issue) && changed_dates.key?('due_date') + # Using instance_of because WorkItem < Issue. We don't want to track work item updates as issue updates + if noteable.instance_of?(Issue) && changed_dates.key?('due_date') issue_activity_counter.track_issue_due_date_changed_action(author: author) end + work_item_activity_counter.track_work_item_date_changed_action(author: author) if noteable.is_a?(WorkItem) + create_note( NoteSummary.new(noteable, project, author, changed_date_body(changed_dates), action: 'start_date_or_due_date') ) @@ -147,5 +150,9 @@ module SystemNotes def issue_activity_counter Gitlab::UsageDataCounters::IssueActivityUniqueCounter end + + def work_item_activity_counter + Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter + end end end diff --git a/config/metrics/aggregates/common.yml b/config/metrics/aggregates/common.yml index b8f2d179741..35311858c64 100644 --- a/config/metrics/aggregates/common.yml +++ b/config/metrics/aggregates/common.yml @@ -49,6 +49,7 @@ events: - users_creating_work_items - users_updating_work_item_title + - users_updating_work_item_dates feature_flag: track_work_items_activity - name: xmau_project_management operator: OR @@ -57,6 +58,7 @@ events: - users_creating_work_items - users_updating_work_item_title + - users_updating_work_item_dates feature_flag: track_work_items_activity - name: users_work_items operator: OR @@ -65,4 +67,5 @@ events: - users_creating_work_items - users_updating_work_item_title + - users_updating_work_item_dates feature_flag: track_work_items_activity diff --git a/config/metrics/counts_28d/20220725193059_users_updating_work_item_dates_monthly.yml b/config/metrics/counts_28d/20220725193059_users_updating_work_item_dates_monthly.yml new file mode 100644 index 00000000000..8e214153e9d --- /dev/null +++ b/config/metrics/counts_28d/20220725193059_users_updating_work_item_dates_monthly.yml @@ -0,0 +1,25 @@ +--- +key_path: redis_hll_counters.work_items.users_updating_work_item_dates_monthly +description: Unique users updating a work item's date +product_category: team_planning +product_section: dev +product_stage: plan +product_group: project_management +value_type: number +status: active +milestone: '15.3' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/93231 +time_frame: 28d +data_source: redis_hll +data_category: optional +instrumentation_class: RedisHLLMetric +options: + events: + - users_updating_work_item_dates +distribution: +- ce +- ee +tier: +- free +- premium +- ultimate diff --git a/config/metrics/counts_7d/20220725201348_users_updating_work_item_dates_weekly.yml b/config/metrics/counts_7d/20220725201348_users_updating_work_item_dates_weekly.yml new file mode 100644 index 00000000000..eaed8420bdb --- /dev/null +++ b/config/metrics/counts_7d/20220725201348_users_updating_work_item_dates_weekly.yml @@ -0,0 +1,25 @@ +--- +key_path: redis_hll_counters.work_items.users_updating_work_item_dates_weekly +description: Unique users updating a work item's date +product_category: team_planning +product_section: dev +product_stage: plan +product_group: project_management +value_type: number +status: active +milestone: '15.3' +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/93231 +time_frame: 7d +data_source: redis_hll +data_category: optional +instrumentation_class: RedisHLLMetric +options: + events: + - users_updating_work_item_dates +distribution: +- ce +- ee +tier: +- free +- premium +- ultimate diff --git a/doc/administration/geo/index.md b/doc/administration/geo/index.md index 6056a0c07c3..e3bf5ccdfe7 100644 --- a/doc/administration/geo/index.md +++ b/doc/administration/geo/index.md @@ -119,8 +119,8 @@ The following are required to run Geo: The following operating systems are known to ship with a current version of OpenSSH: - [CentOS](https://www.centos.org) 7.4 or later - [Ubuntu](https://ubuntu.com) 16.04 or later -- PostgreSQL 12 with [Streaming Replication](https://wiki.postgresql.org/wiki/Streaming_Replication) - - PostgreSQL 13 is not supported for Geo, see [epic 3832](https://gitlab.com/groups/gitlab-org/-/epics/3832) +- PostgreSQL 12 or 13 with [Streaming Replication](https://wiki.postgresql.org/wiki/Streaming_Replication) + - Note,[PostgreSQL 12 is deprecated](../../update/deprecations.md#postgresql-12-deprecated) and will be removed in GitLab 16.0. - Git 2.9 or later - Git-lfs 2.4.2 or later on the user side when using LFS - All sites must run [the same GitLab and PostgreSQL versions](setup/database.md#postgresql-replication). diff --git a/doc/administration/geo/setup/index.md b/doc/administration/geo/setup/index.md index 0cd77ac88f6..79b52ef71da 100644 --- a/doc/administration/geo/setup/index.md +++ b/doc/administration/geo/setup/index.md @@ -22,6 +22,7 @@ The steps below should be followed in the order they appear. **Make sure the Git If you installed GitLab using the Omnibus packages (highly recommended): +1. Confirm the [requirements for running Geo](../index.md#requirements-for-running-geo) are met. 1. [Install GitLab Enterprise Edition](https://about.gitlab.com/install/) on the nodes that serve as the **secondary** site. **Do not create an account or log in** to the new **secondary** site. The **GitLab version must match** across primary and secondary sites. 1. [Add the GitLab License](../../../user/admin_area/license.md) on the **primary** site to unlock Geo. The license must be for [GitLab Premium](https://about.gitlab.com/pricing/) or higher. 1. [Confirm network connectivity](../index.md#firewall-rules) between the **primary** and **secondary** site. diff --git a/doc/development/database/database_lab.md b/doc/development/database/database_lab.md index 5346df2690d..1d584a4ec6f 100644 --- a/doc/development/database/database_lab.md +++ b/doc/development/database/database_lab.md @@ -95,7 +95,7 @@ To connect to a clone using `psql`: 1. In the **Clone details** page of the Postgres.ai web interface, copy and run the command to start SSH port forwarding for the clone. 1. In the **Clone details** page of the Postgres.ai web interface, copy and run the `psql` connection string. - Use the password provided at setup. + Use the password provided at setup and set the `dbname` to `gitlabhq_dblab` (or check what databases are available by using `psql -l` with the same query string but `dbname=postgres`). After you connect, use clone like you would any `psql` console in production, but with the added benefit and safety of an isolated writeable environment. diff --git a/doc/development/migration_style_guide.md b/doc/development/migration_style_guide.md index 913964d5d39..64d8b22f1b8 100644 --- a/doc/development/migration_style_guide.md +++ b/doc/development/migration_style_guide.md @@ -756,6 +756,21 @@ If a backport adding a column with a default value is needed for %12.9 or earlie it should use `add_column_with_default` helper. If a [large table](https://gitlab.com/gitlab-org/gitlab/-/blob/master/rubocop/rubocop-migrations.yml#L3) is involved, backporting to %12.9 is contraindicated. +## Removing the column default for non-nullable columns + +If you have added a non-nullable column, and used the default value to populate +existing data, you need to keep that default value around until at least after +the application code is updated. You cannot remove the default value in the +same migration, as the migrations run before the model code is updated and +models will have an old schema cache, meaning they won't know about this column +and won't be able to set it. In this case it's recommended to: + +1. Add the column with default value in a normal migration. +1. Remove the default in a post-deployment migration. + +The post-deployment migration happens after the application restarts, +ensuring the new column has been discovered. + ## Changing the column default One might think that changing a default column with `change_column_default` is an diff --git a/doc/user/application_security/vulnerabilities/index.md b/doc/user/application_security/vulnerabilities/index.md index f0ac01000ef..ad397c3fe04 100644 --- a/doc/user/application_security/vulnerabilities/index.md +++ b/doc/user/application_security/vulnerabilities/index.md @@ -152,8 +152,8 @@ includes a **Resolve with merge request** option. The following scanners are supported by this feature: - [Dependency Scanning](../dependency_scanning/index.md). - Automatic Patch creation is only available for Node.js projects managed with - `yarn` when [FIPS mode](../../../development/fips_compliance.md#enable-fips-mode) is disabled. + Automatic patch creation is only available for Node.js projects managed with + `yarn`. Also, Automatic patch creation is only supported when [FIPS mode](../../../development/fips_compliance.md#enable-fips-mode) is disabled. - [Container Scanning](../container_scanning/index.md). To resolve a vulnerability, you can either: diff --git a/doc/user/project/releases/index.md b/doc/user/project/releases/index.md index 93a808b1706..d3456e086ce 100644 --- a/doc/user/project/releases/index.md +++ b/doc/user/project/releases/index.md @@ -124,10 +124,8 @@ You can create a release directly as part of the GitLab CI/CD pipeline by using The release is created only if the job processes without error. If the API returns an error during release creation, the release job fails. -Methods for creating a release using a CI/CD job include: - -- Create a release when a Git tag is created. -- Create a release when a commit is merged to the default branch. +For examples of how you can create a release of your application in the CI/CD pipeline, +see [Release CI/CD examples](release_cicd_examples.md). ### Use a custom SSL CA certificate authority diff --git a/lib/gitlab/usage_data_counters/known_events/work_items.yml b/lib/gitlab/usage_data_counters/known_events/work_items.yml index 0c9c6026c46..6cd7836ea94 100644 --- a/lib/gitlab/usage_data_counters/known_events/work_items.yml +++ b/lib/gitlab/usage_data_counters/known_events/work_items.yml @@ -9,3 +9,8 @@ redis_slot: users aggregation: weekly feature_flag: track_work_items_activity +- name: users_updating_work_item_dates + category: work_items + redis_slot: users + aggregation: weekly + feature_flag: track_work_items_activity diff --git a/lib/gitlab/usage_data_counters/work_item_activity_unique_counter.rb b/lib/gitlab/usage_data_counters/work_item_activity_unique_counter.rb index 51bca8b51fe..99b4c082310 100644 --- a/lib/gitlab/usage_data_counters/work_item_activity_unique_counter.rb +++ b/lib/gitlab/usage_data_counters/work_item_activity_unique_counter.rb @@ -5,6 +5,7 @@ module Gitlab module WorkItemActivityUniqueCounter WORK_ITEM_CREATED = 'users_creating_work_items' WORK_ITEM_TITLE_CHANGED = 'users_updating_work_item_title' + WORK_ITEM_DATE_CHANGED = 'users_updating_work_item_dates' class << self def track_work_item_created_action(author:) @@ -15,6 +16,10 @@ module Gitlab track_unique_action(WORK_ITEM_TITLE_CHANGED, author) end + def track_work_item_date_changed_action(author:) + track_unique_action(WORK_ITEM_DATE_CHANGED, author) + end + private def track_unique_action(action, author) diff --git a/lib/gitlab/utils/strong_memoize.rb b/lib/gitlab/utils/strong_memoize.rb index 07b436d73ca..50b8428113d 100644 --- a/lib/gitlab/utils/strong_memoize.rb +++ b/lib/gitlab/utils/strong_memoize.rb @@ -113,7 +113,7 @@ module Gitlab # Methods defined within a class method are already public by default, so we don't need to # explicitly make them public. - scope = %i(private protected).find do |scope| + scope = %i[private protected].find do |scope| klass.send("#{scope}_instance_methods") # rubocop:disable GitlabSecurity/PublicSend .include? method_name end diff --git a/spec/lib/gitlab/usage_data_counters/work_item_activity_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/work_item_activity_unique_counter_spec.rb index 0264236f087..0bcdbe82a7a 100644 --- a/spec/lib/gitlab/usage_data_counters/work_item_activity_unique_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/work_item_activity_unique_counter_spec.rb @@ -20,4 +20,12 @@ RSpec.describe Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter, :clean_ it_behaves_like 'work item unique counter' end + + describe '.track_work_item_date_changed_action' do + subject(:track_event) { described_class.track_work_item_date_changed_action(author: user) } + + let(:event_name) { described_class::WORK_ITEM_DATE_CHANGED } + + it_behaves_like 'work item unique counter' + end end diff --git a/spec/services/system_notes/time_tracking_service_spec.rb b/spec/services/system_notes/time_tracking_service_spec.rb index ef07518c707..33608deaa64 100644 --- a/spec/services/system_notes/time_tracking_service_spec.rb +++ b/spec/services/system_notes/time_tracking_service_spec.rb @@ -3,19 +3,20 @@ require 'spec_helper' RSpec.describe ::SystemNotes::TimeTrackingService do - let_it_be(:author) { create(:user) } - let_it_be(:project) { create(:project, :repository) } + let_it_be(:author) { create(:user) } + let_it_be(:project) { create(:project, :repository) } describe '#change_start_date_or_due_date' do + let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:work_item) { create(:work_item, project: project) } + subject(:note) { described_class.new(noteable: noteable, project: project, author: author).change_start_date_or_due_date(changed_dates) } let(:start_date) { Date.today } let(:due_date) { 1.week.from_now.to_date } let(:changed_dates) { { 'due_date' => [nil, due_date], 'start_date' => [nil, start_date] } } - let_it_be(:noteable) { create(:issue, project: project) } - - context 'when noteable is an issue' do + shared_examples 'issuable getting date change notes' do it_behaves_like 'a note with overridable created_at' it_behaves_like 'a system note' do @@ -43,16 +44,16 @@ RSpec.describe ::SystemNotes::TimeTrackingService do context 'when due date is added' do let(:changed_dates) { { 'due_date' => [nil, due_date] } } - it 'tracks the issue event in usage ping' do - expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_due_date_changed_action).with(author: author) - - subject - end - it 'sets the correct note message' do expect(note.note).to eq("changed due date to #{due_date.to_s(:long)}") end + it 'tracks the issue event in usage ping' do + expect(activity_counter_class).to receive(activity_counter_method).with(author: author) + + subject + end + context 'and start date removed' do let(:changed_dates) { { 'due_date' => [nil, due_date], 'start_date' => [start_date, nil] } } @@ -97,14 +98,69 @@ RSpec.describe ::SystemNotes::TimeTrackingService do end end - context 'when noteable is a merge request' do - let_it_be(:noteable) { create(:merge_request, source_project: project) } + context 'when noteable is an issue' do + let(:noteable) { issue } + let(:activity_counter_class) { Gitlab::UsageDataCounters::IssueActivityUniqueCounter } + let(:activity_counter_method) { :track_issue_due_date_changed_action } + + it_behaves_like 'issuable getting date change notes' + + it 'does not track the work item event in usage ping' do + expect(Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter).not_to receive(:track_work_item_date_changed_action) + + subject + end + + it 'tracks the issue event in usage ping' do + expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).to receive(:track_issue_due_date_changed_action).with(author: author) + + subject + end + + context 'when only start_date is added' do + let(:changed_dates) { { 'start_date' => [nil, start_date] } } + + it 'does not track the issue event in usage ping' do + expect(activity_counter_class).not_to receive(activity_counter_method) + + subject + end + end + end + + context 'when noteable is a work item' do + let(:noteable) { work_item } + let(:activity_counter_class) { Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter } + let(:activity_counter_method) { :track_work_item_date_changed_action } + + it_behaves_like 'issuable getting date change notes' it 'does not track the issue event in usage ping' do expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_due_date_changed_action) subject end + + context 'when only start_date is added' do + let(:changed_dates) { { 'start_date' => [nil, start_date] } } + + it 'tracks the issue event in usage ping' do + expect(activity_counter_class).to receive(activity_counter_method).with(author: author) + + subject + end + end + end + + context 'when noteable is a merge request' do + let(:noteable) { create(:merge_request, source_project: project) } + + it 'does not track the issue event in usage ping' do + expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_due_date_changed_action) + expect(Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter).not_to receive(:track_work_item_date_changed_action) + + subject + end end end diff --git a/spec/services/work_items/update_service_spec.rb b/spec/services/work_items/update_service_spec.rb index 7715fad9703..2e0b0051495 100644 --- a/spec/services/work_items/update_service_spec.rb +++ b/spec/services/work_items/update_service_spec.rb @@ -66,6 +66,16 @@ RSpec.describe WorkItems::UpdateService do end end + context 'when dates are changed' do + let(:opts) { { start_date: Date.today } } + + it 'tracks users updating work item dates' do + expect(Gitlab::UsageDataCounters::WorkItemActivityUniqueCounter).to receive(:track_work_item_date_changed_action).with(author: current_user) + + update_work_item + end + end + context 'when updating state_event' do context 'when state_event is close' do let(:opts) { { state_event: 'close' } }