Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions manifests/integrations/memcache.pp
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 %>