Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres dd updates #812

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 51 additions & 31 deletions manifests/integrations/postgres.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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 = []
Expand Down
21 changes: 21 additions & 0 deletions spec/classes/datadog_agent_integrations_postgres_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
21 changes: 21 additions & 0 deletions templates/agent-conf.d/postgres.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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'] %>
Expand All @@ -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 -%>
Expand Down