Skip to content

Commit

Permalink
[Integrations] Add logic to install extra_packages agent checks
Browse files Browse the repository at this point in the history
- Let the datadog:dd-agent recipe install any package found in the
  `extra_packages` attribute, and configure it
- add some tests with the twemproxy integration
  • Loading branch information
tmichelet committed Mar 24, 2016
1 parent 4e59a32 commit 557232a
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,22 @@ suites:
- name: test2
host: localhost
port: 5678


- name: datadog_integrations
run_list:
- recipe[datadog::dd-agent]
attributes:
datadog:
<<: *DATADOG
extra_packages:
twemproxy:
name: dd-check-twemproxy
version: 0.0.8-1
twemproxy:
instances:
- url: http://localhost:22222

- name: datadog_postfix
run_list:
- recipe[sudo]
Expand Down
3 changes: 3 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@
default['datadog']['statsd_forward_host'] = nil
default['datadog']['statsd_forward_port'] = 8125

# extra_packages to install
default['datadog']['extra_packages'] = {}

# For service-specific configuration, use the integration recipes included
# in this cookbook, and apply them to the appropirate node's run list.
# Read more at http://docs.datadoghq.com/
Expand Down
7 changes: 5 additions & 2 deletions providers/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ def whyrun_supported?
owner 'dd-agent'
mode 00600
end

source 'integration.yaml.erb' if new_resource.use_integration_template

variables(
:init_config => new_resource.init_config,
:instances => new_resource.instances
init_config: new_resource.init_config,
instances: new_resource.instances
)
cookbook new_resource.cookbook
notifies :restart, 'service[datadog-agent]', :delayed if node['datadog']['agent_start']
Expand Down
3 changes: 3 additions & 0 deletions recipes/dd-agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,6 @@
end
subscribes :restart, "template[#{agent_config_file}]", :delayed unless node['datadog']['agent_start'] == false
end

# Install integration packages
include_recipe 'datadog::integrations' if node['platform_family'] != 'windows'
43 changes: 43 additions & 0 deletions recipes/integrations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Cookbook Name:: datadog
# Recipe:: integrations
#
# Copyright 2011-2015, Datadog
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe 'datadog::repository' if node['datadog']['installrepo']

# Install all specified integrations
# example:
# default['datadog']['extra_packages']['twemproxy'] = {
# 'name' => 'dd-check-twemproxy',
# 'version' => '1.0.0-1'
# }
# default['datadog']['twemproxy']['instances'] = [
# {
# 'url' => 'http://localhost:22222'
# }
node['datadog']['extra_packages'].each do |name, options|
package options['name'] do
version options['version']
action :install
end

datadog_monitor name do
init_config node['datadog'][name]['init_config']
instances node['datadog'][name]['instances']
use_integration_template true
end
end
1 change: 1 addition & 0 deletions resources/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
# is evaluated.
attribute :init_config, :kind_of => Hash, :required => false, :default => {}
attribute :instances, :kind_of => Array, :required => false, :default => []
attribute :use_integration_template, :kind_of => [TrueClass, FalseClass], :required => false, :default => false
3 changes: 3 additions & 0 deletions templates/default/integration.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Generated by Chef, local modifications will be overwritten

<%= JSON.parse(({ 'instances' => @instances, 'init_config' => @init_config }).to_json).to_yaml %>
1 change: 1 addition & 0 deletions test/integration/datadog_integrations/serverspec/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Encoding: utf-8
require 'spec_helper'

AGENT_CONFIG = File.join(@agent_config_dir, 'conf.d/twemproxy.yaml')

describe service(@agent_service_name) do
it { should be_running }
end

describe file(AGENT_CONFIG) do
it { should be_a_file }

it 'is valid yaml matching input values' do
generated = YAML.load_file(AGENT_CONFIG)

expected = {
instances: [
{
url: 'http://localhost:22222'
}
],
init_config: {}
}

expect(generated.to_json).to be_json_eql expected.to_json
end

if @agent_check_dir
describe file('/opt/datadog-agent/3rd-party/twemproxy/check.py') do
it { should be_a_file }
end
end
end
3 changes: 3 additions & 0 deletions test/integration/helpers/serverspec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
@agent_package_name = 'Datadog Agent'
@agent_service_name = 'DatadogAgent'
@agent_config_dir = "#{ENV['ProgramData']}/Datadog"
@agent_check_dir = ''
else
set :backend, :exec
@agent_package_name = 'datadog-agent'
@agent_service_name = 'datadog-agent'
@agent_config_dir = '/etc/dd-agent'
@agent_check_dir = '/opt/datadog-agent/agent/checks.d'

end

set :path, '/sbin:/usr/local/sbin:$PATH' unless os[:family] == 'windows'

0 comments on commit 557232a

Please sign in to comment.