Skip to content

Commit

Permalink
Merge pull request #203 from NoodlesNZ/master
Browse files Browse the repository at this point in the history
Adding memcache integration
  • Loading branch information
truthbk committed Jul 14, 2016
2 parents 71d0987 + 6a9d6c5 commit a0ff7d3
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
44 changes: 44 additions & 0 deletions manifests/integrations/memcache.pp
@@ -0,0 +1,44 @@
# Class: datadog_agent::integrations::memcache
#
# This class will install the necessary configuration for the memcache integration
#
# Parameters:
# $url:
# url used to connect to the memcached instance
# $port:
# $tags
# Optional array of tags
#
# Sample Usage:
#
# include 'datadog_agent::integrations::memcache'
#
# OR
#
# class { 'datadog_agent::integrations::memcache':
# url => 'localhost',
# }
#
class datadog_agent::integrations::memcache (
$url = 'localhost',
$port = 11211,
$tags = [],
$items = false,
$slabs = false,
) inherits datadog_agent::params {
include datadog_agent

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

file { "${datadog_agent::params::conf_dir}/mcache.yaml":
ensure => file,
owner => $datadog_agent::params::dd_user,
group => $datadog_agent::params::dd_group,
mode => '0600',
content => template('datadog_agent/agent-conf.d/mcache.yaml.erb'),
require => Package[$datadog_agent::params::package_name],
notify => Service[$datadog_agent::params::service_name]
}
}
85 changes: 85 additions & 0 deletions spec/classes/datadog_agent_integrations_memcache_spec.rb
@@ -0,0 +1,85 @@
require 'spec_helper'

describe 'datadog_agent::integrations::memcache' 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}/mcache.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{url: localhost}) }
it { should contain_file(conf_file).without_content(/tags:/) }
end

context 'with parameters set' do
let(:params) {{
url: 'foobar',
port: '11212',
items: 'true',
slabs: 'true',
tags: %w{foo bar baz},
}}
it { should contain_file(conf_file).with_content(%r{url: foobar}) }
it { should contain_file(conf_file).with_content(/port: 11212/) }
it { should contain_file(conf_file).with_content(/items: true/) }
it { should contain_file(conf_file).with_content(/slabs: true/) }
end

context 'with tags parameter single value' do
let(:params) {{
tags: 'foo',
}}
it { should_not compile }

skip "this is currently unimplemented behavior" do
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s*?[^-]/m) }
end
end

context 'with tags parameter array' do
let(:params) {{
tags: %w{ foo bar baz },
}}
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) }
end

context 'with tags parameter empty values' do
context 'mixed in with other tags' do
let(:params) {{
tags: [ 'foo', '', 'baz' ]
}}

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

context 'single element array of an empty string' do
let(:params) {{
tags: [''],
}}

skip("undefined behavior")
end

context 'single value empty string' do
let(:params) {{
tags: '',
}}

skip("doubly undefined behavior")
end
end
end
17 changes: 17 additions & 0 deletions templates/agent-conf.d/mcache.yaml.erb
@@ -0,0 +1,17 @@
init_config:

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

options:
items: <%= @items %>
slabs: <%= @slabs %>

0 comments on commit a0ff7d3

Please sign in to comment.