Class: Gitlab::Database::Sos::PlatformConfigInfo

Inherits:
BaseDbStatsHandler show all
Defined in:
lib/gitlab/database/sos/platform_config_info.rb

Constant Summary collapse

QUERY =
<<~SQL
 SELECT name AS key,
 setting AS value
FROM pg_settings
WHERE name IN ('server_version', 'data_directory', 'rds.extensions',
  'cloudsql.iam_authentication', 'azure.extensions')
OR name LIKE 'alloydb%'
UNION ALL
SELECT 'System information', version();
SQL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDbStatsHandler

#execute_query, #initialize, #write_to_csv

Constructor Details

This class inherits a constructor from Gitlab::Database::Sos::BaseDbStatsHandler

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



7
8
9
# File 'lib/gitlab/database/sos/platform_config_info.rb', line 7

def connection
  @connection
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/gitlab/database/sos/platform_config_info.rb', line 7

def name
  @name
end

#outputObject (readonly)

Returns the value of attribute output.



7
8
9
# File 'lib/gitlab/database/sos/platform_config_info.rb', line 7

def output
  @output
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gitlab/database/sos/platform_config_info.rb', line 20

def run
  query_results = execute_query(QUERY)

  config_info = connection.pool.db_config.configuration_hash.except(:username, :password)

  file_path = File.join(name, "platform_config_info.csv")

  output.write_file(file_path) do |f|
    CSV.open(f, "w+") do |csv|
      csv << %w[source key value]

      query_results.each do |row|
        csv << ['database', row['key'], row['value']]
      end

      config_info.each do |key, value|
        csv << ['config', key.to_s, value.to_s]
      end
    end
  end
rescue StandardError => e
  Gitlab::AppLogger.error("Error writing platform config info for DB:#{name} with error message:#{e.message}")
end