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 0000000000000000000000000000000000000000..91c0695c4a6d7a43b174f0cd2de04ed0a5250237 --- /dev/null +++ b/db/migrate/20220914130800_add_jitsu_key_to_projects.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# 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! + + def up + with_lock_retries do + add_column :project_settings, :jitsu_key, :text + end + end + + def down + with_lock_retries do + remove_column :project_settings, :jitsu_key + end + end +end +# 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 0000000000000000000000000000000000000000..93aa27ffaa2d2c6df72eb6c1f031ab0e16e48f13 --- /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 :project_settings, :jitsu_key, 100 + end + + def down + remove_text_limit :project_settings, :jitsu_key + end +end diff --git a/db/schema_migrations/20220914130800 b/db/schema_migrations/20220914130800 new file mode 100644 index 0000000000000000000000000000000000000000..2fab1dfd4b9161e3e52e276f04ef480e1d1729a1 --- /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 0000000000000000000000000000000000000000..f735b7867d107cc5c12d0ab71733ad1703a5e5fc --- /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 122ad10e9aeed498aced27ac75ec471cd5aea27d..51fb654d03d7aa2f8c96dff85f3c0a269986fb6a 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)), diff --git a/ee/app/models/product_analytics/jitsu_authentication.rb b/ee/app/models/product_analytics/jitsu_authentication.rb index bdf6b71b9ea87e4de79c433694e3a1b848a82825..79658edd6ed72f3baa1521e3be51de2b3d48d962 100644 --- a/ee/app/models/product_analytics/jitsu_authentication.rb +++ b/ee/app/models/product_analytics/jitsu_authentication.rb @@ -28,7 +28,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.project_setting.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 bfc042b74daeb1b083898ec611765905b1664b2b..63d3ab2ead35d981fb1a855bf270aedfd0c1ede8 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/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 7494e073844accf89df4c909f6aaebc146a5f66a..0000000000000000000000000000000000000000 --- 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 diff --git a/ee/spec/models/product_analytics/jitsu_authentication_spec.rb b/ee/spec/models/product_analytics/jitsu_authentication_spec.rb index 951a47ca0b2c5b73a43ee7d7458de390f6d4e9ac..0628cd25fb76a7c06ccd4b6afdb2f44f46feda06 100644 --- a/ee/spec/models/product_analytics/jitsu_authentication_spec.rb +++ b/ee/spec/models/product_analytics/jitsu_authentication_spec.rb @@ -81,6 +81,11 @@ end it { is_expected.to eq({ jsAuth: 'Mp1N4PYvRXNk1KIh2MLDE7BYghnSwdnt', uid: 'yijlmncqjot0xy9h6rv54p.s7zz20' }) } + + 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/ee/spec/services/product_analytics/initialize_stack_service_spec.rb b/ee/spec/services/product_analytics/initialize_stack_service_spec.rb index 09cccf54486e30848992eea4ce89465e2c255225..a349972f203c4a8cebbc7342e2f59c70476d861a 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 73b23e8b701b7e7b7e371090acaec512e9f207f4..e7a5e890e685a2f34179b5fd0033bd6494cddd61 100644 --- a/spec/requests/api/project_attributes.yml +++ b/spec/requests/api/project_attributes.yml @@ -162,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: