Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
parent
f26a304987
commit
57c56a9260
|
|
@ -379,14 +379,16 @@ J --> K[::GitlabSchema.subscriptions.trigger]
|
|||
|
||||
## How to implement a new action
|
||||
|
||||
Implementing a new AI action will require changes in the GitLab monolith as well as in the AI Gateway.
|
||||
Implementing a new AI action will require changes across different components.
|
||||
We'll use the example of wanting to implement an action that allows users to rewrite issue descriptions according to
|
||||
a given prompt.
|
||||
|
||||
### 1. Add your action to the Cloud Connector feature list
|
||||
|
||||
The Cloud Connector configuration stores the permissions needed to access your service, as well as additional metadata.
|
||||
For more information, see [Cloud Connector: Configuration](../cloud_connector/configuration.md).
|
||||
If there's still not an entry for your feature, you'll need to add one in two places:
|
||||
|
||||
- In the GitLab monolith:
|
||||
|
||||
```yaml
|
||||
# ee/config/cloud_connector/access_data.yml
|
||||
|
|
@ -401,6 +403,23 @@ services:
|
|||
- rewrite_issue_description
|
||||
```
|
||||
|
||||
- In [`customers-gitlab-com`](https://gitlab.com/gitlab-org/customers-gitlab-com):
|
||||
|
||||
```yaml
|
||||
# config/cloud_connector.yml
|
||||
|
||||
services:
|
||||
# ...
|
||||
rewrite_description:
|
||||
backend: 'gitlab-ai-gateway'
|
||||
bundled_with:
|
||||
duo_enterprise:
|
||||
unit_primitives:
|
||||
- rewrite_issue_description
|
||||
```
|
||||
|
||||
For more information, see [Cloud Connector: Configuration](../cloud_connector/configuration.md).
|
||||
|
||||
### 2. Create an Agent definition in the AI Gateway
|
||||
|
||||
In [the AI Gateway project](https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist), create a
|
||||
|
|
|
|||
|
|
@ -0,0 +1,50 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module Gitlab
|
||||
module Database
|
||||
class AlterCellSequencesRange
|
||||
MISSING_LIMIT_MSG = 'Either minval or maxval is required to alter sequence range'
|
||||
|
||||
attr_reader :minval, :maxval, :connection, :logger
|
||||
|
||||
def initialize(minval, maxval, connection, logger: Gitlab::AppLogger)
|
||||
raise MISSING_LIMIT_MSG unless minval.present? || maxval.present?
|
||||
|
||||
@minval = minval
|
||||
@maxval = maxval
|
||||
@connection = connection
|
||||
@logger = logger
|
||||
end
|
||||
|
||||
def execute
|
||||
sequences.each do |sequence|
|
||||
with_lock_retries do
|
||||
connection.execute(alter_sequence_query(sequence))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sequences
|
||||
sequences_sql = "SELECT DISTINCT(sequencename) FROM pg_sequences WHERE schemaname = 'public'"
|
||||
connection.select_rows(sequences_sql).flatten
|
||||
end
|
||||
|
||||
def alter_sequence_query(sequence_name)
|
||||
sql = "ALTER SEQUENCE #{sequence_name}"
|
||||
sql += " START #{minval} RESTART #{minval} MINVALUE #{minval}" if minval.present?
|
||||
return sql unless maxval.present?
|
||||
|
||||
sql + " MAXVALUE #{maxval}"
|
||||
end
|
||||
|
||||
def with_lock_retries(&)
|
||||
Gitlab::Database::WithLockRetries.new(
|
||||
connection: connection,
|
||||
logger: logger
|
||||
).run(raise_on_exhaustion: false, &)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -57,7 +57,7 @@ module Gitlab
|
|||
|
||||
private_class_method def self.dictionary_paths
|
||||
::Gitlab::Database.all_database_connections
|
||||
.values.map(&:db_docs_dir).uniq
|
||||
.values.map(&:db_docs_dir).uniq
|
||||
end
|
||||
|
||||
class Entry
|
||||
|
|
@ -144,7 +144,7 @@ module Gitlab
|
|||
raise(
|
||||
GitlabSchema::UnknownSchemaError,
|
||||
"#{file_path} must specify a valid gitlab_schema for #{key_name}. " \
|
||||
"See #{help_page_url}"
|
||||
"See #{help_page_url}"
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# rubocop:disable Gitlab/AvoidGitlabInstanceChecks -- We want to set sequence limits only on Gitlab instances
|
||||
namespace :gitlab do
|
||||
namespace :db do
|
||||
desc 'Alters sequence limits for cell specific tables'
|
||||
task :alter_cell_sequences_range, [:minval, :maxval] => :environment do |_t, args|
|
||||
next unless Gitlab.com_except_jh? || Gitlab.dev_or_test_env?
|
||||
|
||||
Gitlab::Database::EachDatabase.each_connection do |connection, _database_name|
|
||||
Gitlab::Database::AlterCellSequencesRange.new(args.minval&.to_i, args.maxval&.to_i, connection).execute
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
# rubocop:enable Gitlab/AvoidGitlabInstanceChecks
|
||||
|
|
@ -1618,9 +1618,6 @@ msgstr ""
|
|||
msgid "(Limited to %{quota} compute minutes per month)"
|
||||
msgstr ""
|
||||
|
||||
msgid "(No changes)"
|
||||
msgstr ""
|
||||
|
||||
msgid "(UTC %{offset})"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe Gitlab::Database::AlterCellSequencesRange, feature_category: :database do
|
||||
describe '#execute' do
|
||||
let(:connection) { ApplicationRecord.connection }
|
||||
let(:alter_cell_sequences_range) { described_class.new(*params) }
|
||||
let(:params) { [minval, maxval, connection] }
|
||||
let(:minval) { 100_000 }
|
||||
let(:maxval) { 200_000 }
|
||||
let(:default_min) { 1 }
|
||||
let(:default_max) { (2**63) - 1 }
|
||||
|
||||
subject(:execute) { alter_cell_sequences_range.execute }
|
||||
|
||||
context 'without minval and maxval' do
|
||||
let(:minval) { nil }
|
||||
let(:maxval) { nil }
|
||||
|
||||
it 'raises an exception' do
|
||||
expect { execute }.to raise_error(described_class::MISSING_LIMIT_MSG)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'alters sequences range' do
|
||||
it 'updates given limit(s) for all sequences' do
|
||||
execute
|
||||
|
||||
if minval.present?
|
||||
incorrect_min = "SELECT sequencename FROM pg_sequences WHERE min_value != #{minval}"
|
||||
expect(connection.select_rows(incorrect_min).flatten).to be_empty
|
||||
end
|
||||
|
||||
if maxval.present?
|
||||
incorrect_max = "SELECT sequencename FROM pg_sequences WHERE max_value != #{maxval}"
|
||||
expect(connection.select_rows(incorrect_max).flatten).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with both minval and maxval' do
|
||||
it_behaves_like 'alters sequences range'
|
||||
end
|
||||
|
||||
context 'with only minval' do
|
||||
let(:maxval) { nil }
|
||||
|
||||
it_behaves_like 'alters sequences range'
|
||||
end
|
||||
|
||||
context 'with only maxval' do
|
||||
let(:minval) { nil }
|
||||
|
||||
it_behaves_like 'alters sequences range'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
RSpec.describe 'gitlab:db:alter_cell_sequences_range', :silence_stdout, feature_category: :database do
|
||||
before(:all) do
|
||||
Rake.application.rake_require 'tasks/gitlab/db/alter_cell_sequences_range'
|
||||
end
|
||||
|
||||
let(:minval) { 100 }
|
||||
let(:maxval) { 200 }
|
||||
let(:alter_cell_sequence_range) { instance_double(Gitlab::Database::AlterCellSequencesRange) }
|
||||
|
||||
subject(:run_rake) { run_rake_task('gitlab:db:alter_cell_sequences_range', minval, maxval) }
|
||||
|
||||
context 'when run in non Gitlab.com/dev/test environment' do
|
||||
before do
|
||||
allow(Gitlab).to receive_messages(com_except_jh?: false, dev_or_test_env?: false)
|
||||
end
|
||||
|
||||
it 'does not attempt to alter sequence range' do
|
||||
expect(Gitlab::Database::AlterCellSequencesRange).not_to receive(:new)
|
||||
|
||||
run_rake
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'alters cell sequences range' do
|
||||
it 'executes AlterCellSequencesRange' do
|
||||
Gitlab::Database::EachDatabase.each_connection do |connection, _database_name|
|
||||
expect(Gitlab::Database::AlterCellSequencesRange)
|
||||
.to receive(:new).with(minval, maxval, connection).and_return(alter_cell_sequence_range)
|
||||
|
||||
expect(alter_cell_sequence_range).to receive(:execute)
|
||||
end
|
||||
|
||||
run_rake
|
||||
end
|
||||
end
|
||||
|
||||
context 'when run in Gitlab.com but not jh instance' do
|
||||
before do
|
||||
allow(Gitlab).to receive(:com_except_jh?).and_return(true)
|
||||
end
|
||||
|
||||
it_behaves_like 'alters cell sequences range'
|
||||
end
|
||||
|
||||
context 'when run in dev or test env' do
|
||||
before do
|
||||
allow(Gitlab).to receive(:dev_or_test_env?).and_return(true)
|
||||
end
|
||||
|
||||
it_behaves_like 'alters cell sequences range'
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue