From 6a5de847bffd20e1791c017dd483092972d0fc75 Mon Sep 17 00:00:00 2001 From: Max Woolf Date: Wed, 14 Sep 2022 16:52:32 +0100 Subject: [PATCH 1/4] Add jitsu key to project when created Changelog: added --- ...0220914130800_add_jitsu_key_to_projects.rb | 21 +++++++++++++++++++ ...49_add_text_limit_to_projects_jitsu_key.rb | 13 ++++++++++++ db/schema_migrations/20220914130800 | 1 + db/schema_migrations/20220914131449 | 1 + db/structure.sql | 4 +++- .../product_analytics/jitsu_authentication.rb | 10 ++++++++- .../initialize_stack_service.rb | 2 +- .../jitsu_authentication_spec.rb | 6 ++++++ .../initialize_stack_service_spec.rb | 2 +- spec/requests/api/project_attributes.yml | 1 + 10 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20220914130800_add_jitsu_key_to_projects.rb create mode 100644 db/migrate/20220914131449_add_text_limit_to_projects_jitsu_key.rb create mode 100644 db/schema_migrations/20220914130800 create mode 100644 db/schema_migrations/20220914131449 diff --git a/db/migrate/20220914130800_add_jitsu_key_to_projects.rb b/db/migrate/20220914130800_add_jitsu_key_to_projects.rb new file mode 100644 index 00000000000000..435e231c09b5b8 --- /dev/null +++ b/db/migrate/20220914130800_add_jitsu_key_to_projects.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +# rubocop:disable Migration/AddColumnsToWideTables +# rubocop:disable Migration/AddLimitToTextColumns +class AddJitsuKeyToProjects < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + with_lock_retries do + add_column :projects, :jitsu_key, :text + end + end + + def down + with_lock_retries do + remove_column :projects, :jitsu_key + end + end +end +# rubocop:enable Migration/AddColumnsToWideTables +# rubocop:enable Migration/AddLimitToTextColumns diff --git a/db/migrate/20220914131449_add_text_limit_to_projects_jitsu_key.rb b/db/migrate/20220914131449_add_text_limit_to_projects_jitsu_key.rb new file mode 100644 index 00000000000000..80e3f768c88451 --- /dev/null +++ b/db/migrate/20220914131449_add_text_limit_to_projects_jitsu_key.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class AddTextLimitToProjectsJitsuKey < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + def up + add_text_limit :projects, :jitsu_key, 100 + end + + def down + remove_text_limit :projects, :jitsu_key + end +end diff --git a/db/schema_migrations/20220914130800 b/db/schema_migrations/20220914130800 new file mode 100644 index 00000000000000..2fab1dfd4b9161 --- /dev/null +++ b/db/schema_migrations/20220914130800 @@ -0,0 +1 @@ +c0a3269fbd44428439932f3b12b154425eafaab0b0638f7f27a03e784d0f0e32 \ No newline at end of file diff --git a/db/schema_migrations/20220914131449 b/db/schema_migrations/20220914131449 new file mode 100644 index 00000000000000..f735b7867d107c --- /dev/null +++ b/db/schema_migrations/20220914131449 @@ -0,0 +1 @@ +205f1fee1ed33a2b069e51a76b94c72702300c72c4705569be2368f8804f3bce \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 122ad10e9aeed4..1d08b75b0b8c18 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -20208,7 +20208,9 @@ CREATE TABLE projects ( autoclose_referenced_issues boolean, suggestion_commit_message character varying(255), project_namespace_id bigint, - hidden boolean DEFAULT false NOT NULL + hidden boolean DEFAULT false NOT NULL, + jitsu_key text, + CONSTRAINT check_5e0e3e0d77 CHECK ((char_length(jitsu_key) <= 100)) ); CREATE SEQUENCE projects_id_seq diff --git a/ee/app/models/product_analytics/jitsu_authentication.rb b/ee/app/models/product_analytics/jitsu_authentication.rb index bdf6b71b9ea87e..4bd6c7e8fa2e03 100644 --- a/ee/app/models/product_analytics/jitsu_authentication.rb +++ b/ee/app/models/product_analytics/jitsu_authentication.rb @@ -2,6 +2,8 @@ module ProductAnalytics class JitsuAuthentication + attr_reader :project + def initialize(jid, project) @jid = jid @project = project @@ -28,7 +30,13 @@ def create_api_key! json = Gitlab::Json.parse(response.body) - response.success? ? { jsAuth: json['jsAuth'], uid: json['uid'] } : log_jitsu_api_error(json) + if response.success? + @project.update(jitsu_key: json['jsAuth']) + + return { jsAuth: json['jsAuth'], uid: json['uid'] } + end + + log_jitsu_api_error(json) rescue StandardError => e Gitlab::ErrorTracking.track_exception(e) end diff --git a/ee/app/services/product_analytics/initialize_stack_service.rb b/ee/app/services/product_analytics/initialize_stack_service.rb index bfc042b74daeb1..63d3ab2ead35d9 100644 --- a/ee/app/services/product_analytics/initialize_stack_service.rb +++ b/ee/app/services/product_analytics/initialize_stack_service.rb @@ -3,7 +3,7 @@ module ProductAnalytics class InitializeStackService < BaseContainerService def execute - return unless ::Feature.enabled?(:jitsu_connection_proof_of_concept, container.group) + return unless ::Feature.enabled?(:cube_api_proxy, container.group) ::ProductAnalytics::InitializeAnalyticsWorker.perform_async(container.id) end diff --git a/ee/spec/models/product_analytics/jitsu_authentication_spec.rb b/ee/spec/models/product_analytics/jitsu_authentication_spec.rb index 951a47ca0b2c5b..5c330ac1dd2cf7 100644 --- a/ee/spec/models/product_analytics/jitsu_authentication_spec.rb +++ b/ee/spec/models/product_analytics/jitsu_authentication_spec.rb @@ -81,6 +81,12 @@ end it { is_expected.to eq({ jsAuth: 'Mp1N4PYvRXNk1KIh2MLDE7BYghnSwdnt', uid: 'yijlmncqjot0xy9h6rv54p.s7zz20' }) } + + it 'stores the JS key on the project instance' do + subject + + expect(auth.project.jitsu_key).to eq('Mp1N4PYvRXNk1KIh2MLDE7BYghnSwdnt') + end end context 'when request is unsuccessful' do diff --git a/ee/spec/services/product_analytics/initialize_stack_service_spec.rb b/ee/spec/services/product_analytics/initialize_stack_service_spec.rb index 09cccf54486e30..a349972f203c4a 100644 --- a/ee/spec/services/product_analytics/initialize_stack_service_spec.rb +++ b/ee/spec/services/product_analytics/initialize_stack_service_spec.rb @@ -18,7 +18,7 @@ context 'when feature flag is disabled' do before do - stub_feature_flags(jitsu_connection_proof_of_concept: false) + stub_feature_flags(cube_api_proxy: false) end it 'does not enqueue a job' do diff --git a/spec/requests/api/project_attributes.yml b/spec/requests/api/project_attributes.yml index 73b23e8b701b7e..c444fbce321597 100644 --- a/spec/requests/api/project_attributes.yml +++ b/spec/requests/api/project_attributes.yml @@ -11,6 +11,7 @@ itself: # project - has_external_wiki - hidden - import_source + - jitsu_key - jobs_cache_index - last_repository_check_at - last_repository_check_failed -- GitLab From 071a480f517e7864d54f08c4fe0c35665873a9d7 Mon Sep 17 00:00:00 2001 From: Robert Hunt Date: Tue, 27 Sep 2022 12:27:32 +0100 Subject: [PATCH 2/4] Remove unused feature flag Signed-off-by: Robert Hunt --- .../development/jitsu_connection_proof_of_concept.yml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 ee/config/feature_flags/development/jitsu_connection_proof_of_concept.yml diff --git a/ee/config/feature_flags/development/jitsu_connection_proof_of_concept.yml b/ee/config/feature_flags/development/jitsu_connection_proof_of_concept.yml deleted file mode 100644 index 7494e073844acc..00000000000000 --- a/ee/config/feature_flags/development/jitsu_connection_proof_of_concept.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: jitsu_connection_proof_of_concept -introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/95999 -rollout_issue_url: -milestone: '15.5' -type: development -group: group::product analytics -default_enabled: false -- GitLab From 1c0e79cd6467e2c5ed5ac8608bf49381ae85e4bf Mon Sep 17 00:00:00 2001 From: Robert Hunt Date: Tue, 27 Sep 2022 14:03:57 +0100 Subject: [PATCH 3/4] Backend reviewer feedback - Added comment to migration noting that the limit is applied elsewhere - Removed the attr_reader from jitsu_authentication.rb - Changed project jitsu_key test to check for a change in the model Signed-off-by: Robert Hunt --- db/migrate/20220914130800_add_jitsu_key_to_projects.rb | 1 + ee/app/models/product_analytics/jitsu_authentication.rb | 2 -- .../models/product_analytics/jitsu_authentication_spec.rb | 7 +------ 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/db/migrate/20220914130800_add_jitsu_key_to_projects.rb b/db/migrate/20220914130800_add_jitsu_key_to_projects.rb index 435e231c09b5b8..8061b4d8de4d4b 100644 --- a/db/migrate/20220914130800_add_jitsu_key_to_projects.rb +++ b/db/migrate/20220914130800_add_jitsu_key_to_projects.rb @@ -2,6 +2,7 @@ # rubocop:disable Migration/AddColumnsToWideTables # rubocop:disable Migration/AddLimitToTextColumns +# limit is added in 20220914131449_add_text_limit_to_projects_jitsu_key.rb class AddJitsuKeyToProjects < Gitlab::Database::Migration[2.0] disable_ddl_transaction! diff --git a/ee/app/models/product_analytics/jitsu_authentication.rb b/ee/app/models/product_analytics/jitsu_authentication.rb index 4bd6c7e8fa2e03..1b206047543877 100644 --- a/ee/app/models/product_analytics/jitsu_authentication.rb +++ b/ee/app/models/product_analytics/jitsu_authentication.rb @@ -2,8 +2,6 @@ module ProductAnalytics class JitsuAuthentication - attr_reader :project - def initialize(jid, project) @jid = jid @project = project diff --git a/ee/spec/models/product_analytics/jitsu_authentication_spec.rb b/ee/spec/models/product_analytics/jitsu_authentication_spec.rb index 5c330ac1dd2cf7..683a785c56fad9 100644 --- a/ee/spec/models/product_analytics/jitsu_authentication_spec.rb +++ b/ee/spec/models/product_analytics/jitsu_authentication_spec.rb @@ -81,12 +81,7 @@ end it { is_expected.to eq({ jsAuth: 'Mp1N4PYvRXNk1KIh2MLDE7BYghnSwdnt', uid: 'yijlmncqjot0xy9h6rv54p.s7zz20' }) } - - it 'stores the JS key on the project instance' do - subject - - expect(auth.project.jitsu_key).to eq('Mp1N4PYvRXNk1KIh2MLDE7BYghnSwdnt') - end + it { expect { subject }.to change(project.reload, :jitsu_key).from(nil).to('Mp1N4PYvRXNk1KIh2MLDE7BYghnSwdnt') } end context 'when request is unsuccessful' do -- GitLab From 26f1e48a6ebe4013989bfc882e8848f906536924 Mon Sep 17 00:00:00 2001 From: Max Woolf Date: Mon, 3 Oct 2022 13:18:08 +0100 Subject: [PATCH 4/4] Move new column to project_settings --- db/migrate/20220914130800_add_jitsu_key_to_projects.rb | 6 ++---- .../20220914131449_add_text_limit_to_projects_jitsu_key.rb | 4 ++-- db/structure.sql | 6 +++--- ee/app/models/product_analytics/jitsu_authentication.rb | 2 +- .../models/product_analytics/jitsu_authentication_spec.rb | 6 +++++- spec/requests/api/project_attributes.yml | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/db/migrate/20220914130800_add_jitsu_key_to_projects.rb b/db/migrate/20220914130800_add_jitsu_key_to_projects.rb index 8061b4d8de4d4b..91c0695c4a6d7a 100644 --- a/db/migrate/20220914130800_add_jitsu_key_to_projects.rb +++ b/db/migrate/20220914130800_add_jitsu_key_to_projects.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -# rubocop:disable Migration/AddColumnsToWideTables # rubocop:disable Migration/AddLimitToTextColumns # limit is added in 20220914131449_add_text_limit_to_projects_jitsu_key.rb class AddJitsuKeyToProjects < Gitlab::Database::Migration[2.0] @@ -8,15 +7,14 @@ class AddJitsuKeyToProjects < Gitlab::Database::Migration[2.0] def up with_lock_retries do - add_column :projects, :jitsu_key, :text + add_column :project_settings, :jitsu_key, :text end end def down with_lock_retries do - remove_column :projects, :jitsu_key + remove_column :project_settings, :jitsu_key end end end -# rubocop:enable Migration/AddColumnsToWideTables # rubocop:enable Migration/AddLimitToTextColumns diff --git a/db/migrate/20220914131449_add_text_limit_to_projects_jitsu_key.rb b/db/migrate/20220914131449_add_text_limit_to_projects_jitsu_key.rb index 80e3f768c88451..93aa27ffaa2d2c 100644 --- a/db/migrate/20220914131449_add_text_limit_to_projects_jitsu_key.rb +++ b/db/migrate/20220914131449_add_text_limit_to_projects_jitsu_key.rb @@ -4,10 +4,10 @@ class AddTextLimitToProjectsJitsuKey < Gitlab::Database::Migration[2.0] disable_ddl_transaction! def up - add_text_limit :projects, :jitsu_key, 100 + add_text_limit :project_settings, :jitsu_key, 100 end def down - remove_text_limit :projects, :jitsu_key + remove_text_limit :project_settings, :jitsu_key end end diff --git a/db/structure.sql b/db/structure.sql index 1d08b75b0b8c18..51fb654d03d7aa 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -20072,7 +20072,9 @@ CREATE TABLE project_settings ( enforce_auth_checks_on_uploads boolean DEFAULT true NOT NULL, selective_code_owner_removals boolean DEFAULT false NOT NULL, show_diff_preview_in_email boolean DEFAULT true NOT NULL, + jitsu_key text, suggested_reviewers_enabled boolean DEFAULT false NOT NULL, + CONSTRAINT check_2981f15877 CHECK ((char_length(jitsu_key) <= 100)), CONSTRAINT check_3a03e7557a CHECK ((char_length(previous_default_branch) <= 4096)), CONSTRAINT check_b09644994b CHECK ((char_length(squash_commit_template) <= 500)), CONSTRAINT check_bde223416c CHECK ((show_default_award_emojis IS NOT NULL)), @@ -20208,9 +20210,7 @@ CREATE TABLE projects ( autoclose_referenced_issues boolean, suggestion_commit_message character varying(255), project_namespace_id bigint, - hidden boolean DEFAULT false NOT NULL, - jitsu_key text, - CONSTRAINT check_5e0e3e0d77 CHECK ((char_length(jitsu_key) <= 100)) + hidden boolean DEFAULT false NOT NULL ); CREATE SEQUENCE projects_id_seq diff --git a/ee/app/models/product_analytics/jitsu_authentication.rb b/ee/app/models/product_analytics/jitsu_authentication.rb index 1b206047543877..79658edd6ed72f 100644 --- a/ee/app/models/product_analytics/jitsu_authentication.rb +++ b/ee/app/models/product_analytics/jitsu_authentication.rb @@ -29,7 +29,7 @@ def create_api_key! json = Gitlab::Json.parse(response.body) if response.success? - @project.update(jitsu_key: json['jsAuth']) + @project.project_setting.update(jitsu_key: json['jsAuth']) return { jsAuth: json['jsAuth'], uid: json['uid'] } end diff --git a/ee/spec/models/product_analytics/jitsu_authentication_spec.rb b/ee/spec/models/product_analytics/jitsu_authentication_spec.rb index 683a785c56fad9..0628cd25fb76a7 100644 --- a/ee/spec/models/product_analytics/jitsu_authentication_spec.rb +++ b/ee/spec/models/product_analytics/jitsu_authentication_spec.rb @@ -81,7 +81,11 @@ end it { is_expected.to eq({ jsAuth: 'Mp1N4PYvRXNk1KIh2MLDE7BYghnSwdnt', uid: 'yijlmncqjot0xy9h6rv54p.s7zz20' }) } - it { expect { subject }.to change(project.reload, :jitsu_key).from(nil).to('Mp1N4PYvRXNk1KIh2MLDE7BYghnSwdnt') } + + it do + expect { subject }.to change(project.reload.project_setting, :jitsu_key).from(nil) + .to('Mp1N4PYvRXNk1KIh2MLDE7BYghnSwdnt') + end end context 'when request is unsuccessful' do diff --git a/spec/requests/api/project_attributes.yml b/spec/requests/api/project_attributes.yml index c444fbce321597..e7a5e890e685a2 100644 --- a/spec/requests/api/project_attributes.yml +++ b/spec/requests/api/project_attributes.yml @@ -11,7 +11,6 @@ itself: # project - has_external_wiki - hidden - import_source - - jitsu_key - jobs_cache_index - last_repository_check_at - last_repository_check_failed @@ -163,6 +162,7 @@ project_setting: - selective_code_owner_removals - show_diff_preview_in_email - suggested_reviewers_enabled + - jitsu_key build_service_desk_setting: # service_desk_setting unexposed_attributes: -- GitLab