Skip to content

Commit

Permalink
Support use_pscopg2 flag for postgres integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Cleveland committed Oct 5, 2016
1 parent bcc0204 commit 04557eb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions manifests/integrations/postgres.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# The postgres port number
# $username
# The username for the datadog user
# $use_psycopg2
# Boolean to flag connecting to postgres with psycopg2 instead of pg8000.
# Warning, psycopg2 doesn't support ssl mode.
# $tags
# Optional array of tags
# $tables
Expand Down Expand Up @@ -54,6 +57,7 @@
$dbname = 'postgres',
$port = '5432',
$username = 'datadog',
$use_psycopg2 = false,
$tags = [],
$tables = [],
$custom_metrics = {},
Expand All @@ -62,6 +66,7 @@

validate_array($tags)
validate_array($tables)
validate_bool($use_psycopg2)

file { "${datadog_agent::params::conf_dir}/postgres.yaml":
ensure => file,
Expand Down
9 changes: 9 additions & 0 deletions spec/classes/datadog_agent_integrations_postgres_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,19 @@
it { should contain_file(conf_file).with_content(%r{dbname: postgres}) }
it { should contain_file(conf_file).with_content(%r{port: 5432}) }
it { should contain_file(conf_file).with_content(%r{username: datadog}) }
it { should contain_file(conf_file).without_content(%r{^\s*use_psycopg2: }) }
it { should contain_file(conf_file).without_content(%r{tags: })}
it { should contain_file(conf_file).without_content(%r{^[^#]*relations: }) }
end

context 'with use_psycopg2 enabled' do
let(:params) {{
use_psycopg2: true,
password: 'abc123',
}}
it { should contain_file(conf_file).with_content(%r{use_psycopg2: true}) }
end

context 'with parameters set' do
let(:params) {{
host: 'postgres1',
Expand Down
4 changes: 4 additions & 0 deletions templates/agent-conf.d/postgres.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ instances:
# username: my_username
# password: my_password
# dbname: db_name
# use_psycopg2: false # Force using psycogp2 instead of pg8000 to connect. WARNING: psycopg2 doesn't support ssl mode.
# tags:
# - optional_tag1
# - optional_tag2
Expand All @@ -15,6 +16,9 @@ instances:
username: <%= @username %>
password: <%= @password %>
dbname: <%= @dbname %>
<% if @use_psycopg2 == true -%>
use_psycopg2: true
<% end -%>
<% if @tags and ! @tags.empty? -%>
tags:
<%- Array(@tags).each do |tag| -%>
Expand Down

0 comments on commit 04557eb

Please sign in to comment.