Skip to content

Commit a0ff7d3

Browse files
authored
Merge pull request #203 from NoodlesNZ/master
Adding memcache integration
2 parents 71d0987 + 6a9d6c5 commit a0ff7d3

3 files changed

Lines changed: 146 additions & 0 deletions

File tree

manifests/integrations/memcache.pp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Class: datadog_agent::integrations::memcache
2+
#
3+
# This class will install the necessary configuration for the memcache integration
4+
#
5+
# Parameters:
6+
# $url:
7+
# url used to connect to the memcached instance
8+
# $port:
9+
# $tags
10+
# Optional array of tags
11+
#
12+
# Sample Usage:
13+
#
14+
# include 'datadog_agent::integrations::memcache'
15+
#
16+
# OR
17+
#
18+
# class { 'datadog_agent::integrations::memcache':
19+
# url => 'localhost',
20+
# }
21+
#
22+
class datadog_agent::integrations::memcache (
23+
$url = 'localhost',
24+
$port = 11211,
25+
$tags = [],
26+
$items = false,
27+
$slabs = false,
28+
) inherits datadog_agent::params {
29+
include datadog_agent
30+
31+
validate_string($url)
32+
validate_array($tags)
33+
validate_integer($port)
34+
35+
file { "${datadog_agent::params::conf_dir}/mcache.yaml":
36+
ensure => file,
37+
owner => $datadog_agent::params::dd_user,
38+
group => $datadog_agent::params::dd_group,
39+
mode => '0600',
40+
content => template('datadog_agent/agent-conf.d/mcache.yaml.erb'),
41+
require => Package[$datadog_agent::params::package_name],
42+
notify => Service[$datadog_agent::params::service_name]
43+
}
44+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
require 'spec_helper'
2+
3+
describe 'datadog_agent::integrations::memcache' do
4+
let(:facts) {{
5+
operatingsystem: 'Ubuntu',
6+
}}
7+
let(:conf_dir) { '/etc/dd-agent/conf.d' }
8+
let(:dd_user) { 'dd-agent' }
9+
let(:dd_group) { 'root' }
10+
let(:dd_package) { 'datadog-agent' }
11+
let(:dd_service) { 'datadog-agent' }
12+
let(:conf_file) { "#{conf_dir}/mcache.yaml" }
13+
14+
it { should compile.with_all_deps }
15+
it { should contain_file(conf_file).with(
16+
owner: dd_user,
17+
group: dd_group,
18+
mode: '0600',
19+
)}
20+
it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") }
21+
it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") }
22+
23+
context 'with default parameters' do
24+
it { should contain_file(conf_file).with_content(%r{url: localhost}) }
25+
it { should contain_file(conf_file).without_content(/tags:/) }
26+
end
27+
28+
context 'with parameters set' do
29+
let(:params) {{
30+
url: 'foobar',
31+
port: '11212',
32+
items: 'true',
33+
slabs: 'true',
34+
tags: %w{foo bar baz},
35+
}}
36+
it { should contain_file(conf_file).with_content(%r{url: foobar}) }
37+
it { should contain_file(conf_file).with_content(/port: 11212/) }
38+
it { should contain_file(conf_file).with_content(/items: true/) }
39+
it { should contain_file(conf_file).with_content(/slabs: true/) }
40+
end
41+
42+
context 'with tags parameter single value' do
43+
let(:params) {{
44+
tags: 'foo',
45+
}}
46+
it { should_not compile }
47+
48+
skip "this is currently unimplemented behavior" do
49+
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s*?[^-]/m) }
50+
end
51+
end
52+
53+
context 'with tags parameter array' do
54+
let(:params) {{
55+
tags: %w{ foo bar baz },
56+
}}
57+
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) }
58+
end
59+
60+
context 'with tags parameter empty values' do
61+
context 'mixed in with other tags' do
62+
let(:params) {{
63+
tags: [ 'foo', '', 'baz' ]
64+
}}
65+
66+
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) }
67+
end
68+
69+
context 'single element array of an empty string' do
70+
let(:params) {{
71+
tags: [''],
72+
}}
73+
74+
skip("undefined behavior")
75+
end
76+
77+
context 'single value empty string' do
78+
let(:params) {{
79+
tags: '',
80+
}}
81+
82+
skip("doubly undefined behavior")
83+
end
84+
end
85+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
init_config:
2+
3+
instances:
4+
- url: <%= @url %>
5+
port: <%= @port %>
6+
<% if @tags and ! @tags.empty? -%>
7+
tags:
8+
<%- Array(@tags).each do |tag| -%>
9+
<%- if tag != '' -%>
10+
- <%= tag %>
11+
<%- end -%>
12+
<%- end -%>
13+
<% end -%>
14+
15+
options:
16+
items: <%= @items %>
17+
slabs: <%= @slabs %>

0 commit comments

Comments
 (0)