diff --git a/manifests/integrations/postgres.pp b/manifests/integrations/postgres.pp index 00f3f22f..e8b1bf80 100644 --- a/manifests/integrations/postgres.pp +++ b/manifests/integrations/postgres.pp @@ -30,6 +30,16 @@ # Boolean to enable collecting database size metrics. Default value is True but they might be slow with large databases # $collect_default_database # Boolean to enable collecting statistics from the default database 'postgres' in the check metrics, default to false +# $dbm +# Boolean to enable collecting metrics from the dbm tables, default value is False. +# $database_autodiscovery +# Boolean to enable database autodiscovery, default value is False. +# $collect_schemas +# Boolean to enable collecting schema metrics, default value is False. +# $database_autodiscovery_includes +# Array of strings to include in the database autodiscovery, default value is empty array. +# $database_autodiscovery_excludes +# Array of strings to exclude in the database autodiscovery, default value is empty array. # $tags # Optional array of tags # $tables @@ -83,22 +93,27 @@ # - ["tag_column", "tag_column.datadog.tag"] # class datadog_agent::integrations::postgres( - Optional[String] $password = undef, - String $host = 'localhost', - String $dbname = 'postgres', - Variant[String, Integer] $port = '5432', - String $username = 'datadog', - Boolean $ssl = false, - Boolean $use_psycopg2 = false, - Boolean $collect_function_metrics = false, - Boolean $collect_count_metrics = false, - Boolean $collect_activity_metrics = false, - Boolean $collect_database_size_metrics = false, - Boolean $collect_default_database = false, - Array[String] $tags = [], - Array[String] $tables = [], - Hash $custom_metrics = {}, - Optional[Array] $instances = undef, + Optional[String] $password = undef, + String $host = 'localhost', + String $dbname = 'postgres', + Variant[String, Integer] $port = '5432', + String $username = 'datadog', + Boolean $ssl = false, + Boolean $use_psycopg2 = false, + Boolean $collect_function_metrics = false, + Boolean $collect_count_metrics = false, + Boolean $collect_activity_metrics = false, + Boolean $collect_database_size_metrics = false, + Boolean $collect_default_database = false, + Boolean $dbm = false, + Boolean $database_autodiscovery = false, + Boolean $collect_schemas = false, + Array[String] $database_autodiscovery_includes = [], + Array[String] $database_autodiscovery_excludes = [], + Array[String] $tags = [], + Array[String] $tables = [], + Hash $custom_metrics = {}, + Optional[Array] $instances = undef, ) inherits datadog_agent::params { require ::datadog_agent @@ -124,21 +139,26 @@ if !$instances and $host { $_instances = [{ - 'host' => $host, - 'password' => $password, - 'dbname' => $dbname, - 'port' => $port, - 'username' => $username, - 'ssl' => $ssl, - 'use_psycopg2' => $use_psycopg2, - 'tags' => $tags, - 'tables' => $tables, - 'custom_metrics' => $custom_metrics, - 'collect_function_metrics' => $collect_function_metrics, - 'collect_count_metrics' => $collect_count_metrics, - 'collect_activity_metrics' => $collect_activity_metrics, - 'collect_database_size_metrics' => $collect_database_size_metrics, - 'collect_default_database' => $collect_default_database, + 'host' => $host, + 'password' => $password, + 'dbname' => $dbname, + 'port' => $port, + 'username' => $username, + 'ssl' => $ssl, + 'dbm' => $dbm, + 'database_autodiscovery' => $database_autodiscovery, + 'database_autodiscovery_includes' => $database_autodiscovery_includes, + 'database_autodiscovery_excludes' => $database_autodiscovery_excludes, + 'collect_schemas' => $collect_schemas, + 'use_psycopg2' => $use_psycopg2, + 'tags' => $tags, + 'tables' => $tables, + 'custom_metrics' => $custom_metrics, + 'collect_function_metrics' => $collect_function_metrics, + 'collect_count_metrics' => $collect_count_metrics, + 'collect_activity_metrics' => $collect_activity_metrics, + 'collect_database_size_metrics' => $collect_database_size_metrics, + 'collect_default_database' => $collect_default_database, }] } elsif !$instances{ $_instances = [] diff --git a/spec/classes/datadog_agent_integrations_postgres_spec.rb b/spec/classes/datadog_agent_integrations_postgres_spec.rb index c1d065f7..24348183 100644 --- a/spec/classes/datadog_agent_integrations_postgres_spec.rb +++ b/spec/classes/datadog_agent_integrations_postgres_spec.rb @@ -71,6 +71,27 @@ } end + context 'with dbm enabled' do + let(:params) do + { + password: 'abc123', + dbm: true, + database_autodiscovery: true, + collect_schemas: true, + database_autodiscovery_includes: ['foo', 'bar'], + database_autodiscovery_excludes: ['baz', 'qux'], + } + end + + it { + is_expected.to contain_file(conf_file) + .with_content(%r{dbm: true}) + .with_content(%r{database_autodiscovery:\s+enabled: true}) + .with_content(%r{collect_schemas: true}) + .with_content(%r{database_autodiscovery:\s+includes:\s+- foo\s+- bar}) + .with_content(%r{database_autodiscovery:\s+excludes:\s+- baz\s+- qux}) + } + end context 'with use_psycopg2' do let(:params) do { diff --git a/templates/agent-conf.d/postgres.yaml.erb b/templates/agent-conf.d/postgres.yaml.erb index bf9a0455..8b061945 100644 --- a/templates/agent-conf.d/postgres.yaml.erb +++ b/templates/agent-conf.d/postgres.yaml.erb @@ -17,6 +17,7 @@ instances: <%- (Array(@_instances)).each do |instance| -%> - host: <%= instance['host'] %> port: <%= instance['port'] %> + dbm: <%= instance['dbm'] %> username: <%= instance['username'] %> password: <%= instance['password'] %> dbname: <%= instance['dbname'] %> @@ -25,6 +26,26 @@ instances: collect_activity_metrics: <%= instance['collect_activity_metrics'] %> collect_database_size_metrics: <%= instance['collect_database_size_metrics'] %> collect_default_database: <%= instance['collect_default_database'] %> + collect_schemas: + enabled: <%= instance['collect_schemas'] %> + database_autodiscovery: + enabled: <%= instance['database_autodiscovery'] %> +<% if instance['database_autodiscovery_includes'] and ! instance['database_autodiscovery_includes'].empty? -%> + includes: + <%- Array(instance['database_autodiscovery_includes'] ).each do |include| -%> + <%- if include != '' -%> + - <%= include %> + <%- end -%> + <%- end -%> +<% end -%> +<% if instance['database_autodiscovery_excludes'] and ! instance['database_autodiscovery_excludes'].empty? -%> + excludes: + <%- Array(instance['database_autodiscovery_excludes'] ).each do |exclude| -%> + <%- if exclude != '' -%> + - <%= exclude %> + <%- end -%> + <%- end -%> +<% end -%> <% if instance['ssl'] == true -%> ssl: true <% end -%>