Skip to content

Commit

Permalink
[memcache] Add multi-instance support for memcache (DataDog#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
npaufler authored and truthbk committed Jul 21, 2017
1 parent e073421 commit b8f363f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 10 deletions.
26 changes: 26 additions & 0 deletions manifests/integrations/memcache.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,45 @@
# url => 'localhost',
# }
#
#
# Sample Usage (Instance):
# class { 'datadog_agent::integrations::memcache' :
# instances => [{
# url => 'localhost',
# port => '11211',
# items => false,
# slabs => false,
# }]
# }
#
class datadog_agent::integrations::memcache (
$url = 'localhost',
$port = 11211,
$tags = [],
$items = false,
$slabs = false,
$instances = undef,
) inherits datadog_agent::params {
include datadog_agent

validate_string($url)
validate_array($tags)
validate_integer($port)

if !$instances and $url {
$_instances = [{
'url' => $url,
'port' => $port,
'tags' => $tags,
'items' => $items,
'slabs' => $slabs,
}]
} elsif !$instances{
$_instances = []
} else {
$_instances = $instances
}

file { "${datadog_agent::params::conf_dir}/mcache.yaml":
ensure => file,
owner => $datadog_agent::params::dd_user,
Expand Down
38 changes: 37 additions & 1 deletion spec/classes/datadog_agent_integrations_memcache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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}]") }

Expand Down Expand Up @@ -62,7 +63,6 @@
let(:params) {{
tags: [ 'foo', '', 'baz' ]
}}

it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) }
end

Expand All @@ -82,4 +82,40 @@
skip("doubly undefined behavior")
end
end

context 'with multiple instances set' do
let(:params) {
{
instances: [
{
'url' => 'localhost',
'port' => '11211',
'items' => true,
'slabs' => true,
'tags' => ['tag1:value1'],
},
{
'url' => 'foo.bar',
'port' => '11212',
'items' => false,
'slabs' => false,
'tags' => ['tag2:value2'],
}
]
}
}
it { should contain_file(conf_file).with_content(%r{instances:}) }
it { should contain_file(conf_file).with_content(%r{ - url: localhost}) }
it { should contain_file(conf_file).with_content(%r{ port: 11211}) }
it { should contain_file(conf_file).with_content(%r{ items: true}) }
it { should contain_file(conf_file).with_content(%r{ slabs: true}) }
it { should contain_file(conf_file).with_content(%r{ tags:}) }
it { should contain_file(conf_file).with_content(%r{ - tag1:value1}) }
it { should contain_file(conf_file).with_content(%r{ - url: foo.bar}) }
it { should contain_file(conf_file).with_content(%r{ port: 11212}) }
it { should contain_file(conf_file).with_content(%r{ items: false}) }
it { should contain_file(conf_file).with_content(%r{ slabs: false}) }
it { should contain_file(conf_file).with_content(%r{ tags:}) }
it { should contain_file(conf_file).with_content(%r{ - tag2:value2}) }
end
end
24 changes: 15 additions & 9 deletions templates/agent-conf.d/mcache.yaml.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#
# MANAGED BY PUPPET
#

init_config:

instances:
- url: <%= @url %>
port: <%= @port %>
<% if @tags and ! @tags.empty? -%>
tags:
<%- Array(@tags).each do |tag| -%>
<%- (Array(@_instances)).each do |instance| -%>
- url: <%= instance['url'] %>
port: <%= instance['port'] %>
<% if instance['tags'] and ! instance['tags'].empty? -%>
tags:
<%- Array(instance['tags']).each do |tag| -%>
<%- if tag != '' -%>
- <%= tag %>
- <%= tag %>
<%- end -%>
<%- end -%>
<% end -%>

options:
items: <%= @items %>
slabs: <%= @slabs %>
options: # Optional
items: <%= instance['items'] %>
slabs: <%= instance['slabs'] %>
<% end -%>

0 comments on commit b8f363f

Please sign in to comment.