diff --git a/config/metrics/settings/20211201012652_flavor.yml b/config/metrics/settings/20211201012652_flavor.yml index 8148ad7ad89903197958d1deaa644083cb9e77a6..01c73de57c02d17ff25031437f4b23ec4f081f01 100644 --- a/config/metrics/settings/20211201012652_flavor.yml +++ b/config/metrics/settings/20211201012652_flavor.yml @@ -3,7 +3,7 @@ key_path: database.flavor description: What PostgreSQL flavor is being used. Possible values are "Amazon Aurora PostgreSQL", "PostgreSQL on Amazon RDS", "Cloud SQL for PostgreSQL", "Azure Database for PostgreSQL - Single Server", "Azure Database for PostgreSQL - Flexible Server", - or "null". + "AlloyDB for PostgreSQL", or "null". product_section: enablement product_stage: enablement product_group: database diff --git a/lib/gitlab/database/reflection.rb b/lib/gitlab/database/reflection.rb index 33c965cb150842cf02908f58ea9762264820023b..6c4e46728d4c942a7c8dea37028768a7639aa36a 100644 --- a/lib/gitlab/database/reflection.rb +++ b/lib/gitlab/database/reflection.rb @@ -124,7 +124,11 @@ def flavor # - https://docs.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-servers # - https://docs.microsoft.com/en-us/azure/postgresql/concepts-servers#managing-your-server # this database is present on both Flexible and Single server, so we should check the former first. - 'Azure Database for PostgreSQL - Single Server' => { statement: "SELECT datname FROM pg_database WHERE datname = 'azure_maintenance'" } + 'Azure Database for PostgreSQL - Single Server' => { statement: "SELECT datname FROM pg_database WHERE datname = 'azure_maintenance'" }, + # Based on + # - https://cloud.google.com/sql/docs/postgres/flags + # running a query to detect flag names that begin with 'alloydb + 'AlloyDB for PostgreSQL' => { statement: "SELECT name FROM pg_settings WHERE name LIKE 'alloydb%'" } }.each do |flavor, conditions| return flavor if connection.execute(conditions[:statement]).to_a.present? rescue ActiveRecord::StatementInvalid => e diff --git a/spec/lib/gitlab/database/reflection_spec.rb b/spec/lib/gitlab/database/reflection_spec.rb index efc5bd1c1e1c729f0c41af4e510d2a6bf0335d16..389e93364c8ae585640e93f94417299e97f526f3 100644 --- a/spec/lib/gitlab/database/reflection_spec.rb +++ b/spec/lib/gitlab/database/reflection_spec.rb @@ -314,6 +314,12 @@ def stub_statements(statements) expect(database.flavor).to eq('Azure Database for PostgreSQL - Single Server') end + it 'recognizes AlloyDB for PostgreSQL' do + stub_statements("SELECT name FROM pg_settings WHERE name LIKE 'alloydb%'") + + expect(database.flavor).to eq('AlloyDB for PostgreSQL') + end + it 'returns nil if can not recognize the flavor' do expect(database.flavor).to be_nil end