Skip to content

Commit

Permalink
datadog integration for twemproxy, options for haproxy (DataDog#326)
Browse files Browse the repository at this point in the history
* add instances parameter

* building config from instances

* spec test for instances set

* adding datadog integration for twemproxy

* add options to haproxy integration

* following instances pattern for twemproxy integration

* fix twemproxy template typo

* fix twemproxy template typo

* fix twemproxy param error

* fix spec test
  • Loading branch information
swwolf authored and truthbk committed Jul 21, 2017
1 parent 231e906 commit 279cb6f
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 12 deletions.
15 changes: 9 additions & 6 deletions manifests/integrations/haproxy.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@
# Sample Usage:
#
# class { 'datadog_agent::integrations::haproxy' :
# url => 'http://localhost:8080',
# creds => { username => 'admin',
# password => 'password',
# },
# url => 'http://localhost:8080',
# creds => { username => 'admin',
# password => 'password',
# },
# options => { collect_aggregates_only => 'False' },
# }
#
class datadog_agent::integrations::haproxy(
$creds = {},
$url = "http://${::ipaddress}:8080",
$options = {},
$instances = undef,
) inherits datadog_agent::params {
include datadog_agent

if !$instances and $url {
$_instances = [{
'creds' => $creds,
'url' => $url,
'creds' => $creds,
'url' => $url,
'options' => $options,
}]
} elsif !$instances {
$_instances = []
Expand Down
53 changes: 53 additions & 0 deletions manifests/integrations/twemproxy.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Class: datadog_agent::integrations::twemproxy
#
# This class will install the necessary configuration for the twemproxy aka nutcracker integration
#
# Parameters:
# $host:
# The host twemproxy is running on. Defaults to '127.0.0.1'
# $port
# The twemproxy password for the datadog user. Defaults to 22222
#
# Sample Usage:
#
# class { 'datadog_agent::integrations::twemproxy' :
# instances => [
# {
# 'host' => 'localhost',
# 'port' => '22222',
# },
# {
# 'host' => 'localhost',
# 'port' => '22223',
# },
# ]
# }
#
class datadog_agent::integrations::twemproxy(
$host = 'localhost',
$port = '22222',
$instances = undef,
) inherits datadog_agent::params {
include datadog_agent

if !$instances and $host {
$_instances = [{
'host' => $host,
'port' => $port,
}]
} elsif !$instances{
$_instances = []
} else {
$_instances = $instances
}

file { "${datadog_agent::params::conf_dir}/twemproxy.yaml":
ensure => file,
owner => $datadog_agent::params::dd_user,
group => $datadog_agent::params::dd_group,
mode => '0600',
content => template('datadog_agent/agent-conf.d/twemproxy.yaml.erb'),
require => Package[$datadog_agent::params::package_name],
notify => Service[$datadog_agent::params::service_name]
}
}
29 changes: 23 additions & 6 deletions spec/classes/datadog_agent_integrations_haproxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,47 @@
end
end

context 'with options set' do
let(:params) {{
options: {
'optionk' => 'optionv',
},
}}
it { should contain_file(conf_file).with_content(%r{optionk: optionv}) }
end

context 'with instances set' do
let(:params) {{
instances: [
{
'url' => 'http://foo.bar:8421',
'creds' => {
'url' => 'http://foo.bar:8421',
'creds' => {
'username' => 'foo',
'password' => 'bar',
}
},
'options' => {
'optionk1' => 'optionv1',
},
},
{
'url' => 'http://shoe.baz:1248',
'creds' => {
'url' => 'http://shoe.baz:1248',
'creds' => {
'username' => 'shoe',
'password' => 'baz',
}
},
'options' => {
'optionk2' => 'optionv2',
},
},
]
}}
it { should contain_file(conf_file).with_content(%r{url: http://foo.bar:8421}) }
it { should contain_file(conf_file).with_content(%r{username: foo}) }
it { should contain_file(conf_file).with_content(%r{password: bar}) }
it { should contain_file(conf_file).with_content(%r{optionk1: optionv1}) }
it { should contain_file(conf_file).with_content(%r{url: http://shoe.baz:1248}) }
it { should contain_file(conf_file).with_content(%r{username: shoe}) }
it { should contain_file(conf_file).with_content(%r{password: baz}) }
it { should contain_file(conf_file).with_content(%r{optionk2: optionv2}) }
end
end
46 changes: 46 additions & 0 deletions spec/classes/datadog_agent_integrations_twemproxy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'spec_helper'

describe 'datadog_agent::integrations::twemproxy' do
let(:facts) {{
operatingsystem: 'Ubuntu',
}}
let(:conf_dir) { '/etc/dd-agent/conf.d' }
let(:dd_user) { 'dd-agent' }
let(:dd_group) { 'root' }
let(:dd_package) { 'datadog-agent' }
let(:dd_service) { 'datadog-agent' }
let(:conf_file) { "#{conf_dir}/twemproxy.yaml" }

it { should compile.with_all_deps }
it { should contain_file(conf_file).with(
owner: dd_user,
group: dd_group,
mode: '0600',
)}
it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") }
it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") }

context 'with default parameters' do
it { should contain_file(conf_file).with_content(%r{host: localhost}) }
it { should contain_file(conf_file).with_content(%r{port: 22222}) }
end

context 'with parameters set' do
let(:params) {{
instances: [
{
'host' => 'twemproxy1',
'port' => '1234',
},
{
'host' => 'twemproxy2',
'port' => '4567',
}
]
}}
it { should contain_file(conf_file).with_content(%r{host: twemproxy1}) }
it { should contain_file(conf_file).with_content(%r{port: 1234}) }
it { should contain_file(conf_file).with_content(%r{host: twemproxy2}) }
it { should contain_file(conf_file).with_content(%r{port: 4567}) }
end
end
5 changes: 5 additions & 0 deletions templates/agent-conf.d/haproxy.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ instances:
<%= k %>: <%= v %>
<%- end -%>
<%- end -%>
<%- if instance['options'] -%>
<%- instance['options'].each do |k, v| -%>
<%= k %>: <%= v %>
<%- end -%>
<%- end -%>
<% end -%>
11 changes: 11 additions & 0 deletions templates/agent-conf.d/twemproxy.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# MANAGED BY PUPPET
#

init_config:

instances:
<%- (Array(@_instances)).each do |instance| -%>
- host: <%= instance['host'] %>
port: <%= instance['port'] %>
<% end -%>

0 comments on commit 279cb6f

Please sign in to comment.