Skip to content

Commit 1d92be7

Browse files
Seth Clevelandsethcleveland
authored andcommitted
Support use_pscopg2 flag for postgres integrations
1 parent 643d5b1 commit 1d92be7

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

manifests/integrations/postgres.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
# The postgres port number
1414
# $username
1515
# The username for the datadog user
16+
# $use_psycopg2
17+
# Boolean to flag connecting to postgres with psycopg2 instead of pg8000.
18+
# Warning, psycopg2 doesn't support ssl mode.
1619
# $tags
1720
# Optional array of tags
1821
# $tables
@@ -54,6 +57,7 @@
5457
$dbname = 'postgres',
5558
$port = '5432',
5659
$username = 'datadog',
60+
$use_psycopg2 = false,
5761
$tags = [],
5862
$tables = [],
5963
$custom_metrics = {},
@@ -62,6 +66,7 @@
6266

6367
validate_array($tags)
6468
validate_array($tables)
69+
validate_bool($use_psycopg2)
6570

6671
file { "${datadog_agent::params::conf_dir}/postgres.yaml":
6772
ensure => file,

spec/classes/datadog_agent_integrations_postgres_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,19 @@
3535
it { should contain_file(conf_file).with_content(%r{dbname: postgres}) }
3636
it { should contain_file(conf_file).with_content(%r{port: 5432}) }
3737
it { should contain_file(conf_file).with_content(%r{username: datadog}) }
38+
it { should contain_file(conf_file).without_content(%r{^\s*use_psycopg2: }) }
3839
it { should contain_file(conf_file).without_content(%r{tags: })}
3940
it { should contain_file(conf_file).without_content(%r{^[^#]*relations: }) }
4041
end
4142

43+
context 'with use_psycopg2 enabled' do
44+
let(:params) {{
45+
use_psycopg2: true,
46+
password: 'abc123',
47+
}}
48+
it { should contain_file(conf_file).with_content(%r{use_psycopg2: true}) }
49+
end
50+
4251
context 'with parameters set' do
4352
let(:params) {{
4453
host: 'postgres1',

templates/agent-conf.d/postgres.yaml.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ instances:
66
# username: my_username
77
# password: my_password
88
# dbname: db_name
9+
# use_psycopg2: false # Force using psycogp2 instead of pg8000 to connect. WARNING: psycopg2 doesn't support ssl mode.
910
# tags:
1011
# - optional_tag1
1112
# - optional_tag2
@@ -15,6 +16,9 @@ instances:
1516
username: <%= @username %>
1617
password: <%= @password %>
1718
dbname: <%= @dbname %>
19+
<% if @use_psycopg2 == true -%>
20+
use_psycopg2: true
21+
<% end -%>
1822
<% if @tags and ! @tags.empty? -%>
1923
tags:
2024
<%- Array(@tags).each do |tag| -%>

0 commit comments

Comments
 (0)