Add mesos slave integration recipe
Adding the mesos slave integration in a similar fashion to the mesos_master integration
MODIFY
kitchen.yml
kitchen.yml
@@ -436,11 +436,20 @@ suites:
- tata
init_config:
default_timeout: 10
+
+- name: datadog_mesos_slave
+ run_list:
+ - recipe[datadog::mesos_slave]
+ excludes: *WINDOWS_PLATFORMS
+ attributes:
+ datadog:
+ <<: *DATADOG
+ mesos_slave:
instances:
- url: localhost:5050
timeout: 8
tags:
- - toto
+ - slave
- tata
init_config:
default_timeout: 10

ADD
recipes/mesos_slave.rb
+#
+# Cookbook Name:: datadog
+# Recipe:: mesos_slave
+#
+# 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::dd-agent'
+
+# Build a data structure with configuration.
+# @example
+# node.override['datadog']['mesos'] =
+# instances: [{
+# url: 'https://server:port',
+# timeout: 8,
+# tags: [
+# 'optional_tag1',
+# 'optional_tag2'
+# ]
+# }],
+# init_config: {
+# default_timeout: 10
+# }
+
+datadog_monitor 'mesos_slave' do
+ init_config node['datadog']['mesos_slave']['init_config']
+ instances node['datadog']['mesos_slave']['instances']
+ logs node['datadog']['mesos_slave']['logs']
+ action :add
+ notifies :restart, 'service[datadog-agent]' if node['datadog']['agent_start']
+end

ADD
spec/integrations/mesos_slave_spec.rb
+describe 'datadog::mesos_slave' do
+ expected_yaml = <<-EOF
+ logs: ~
+ init_config:
+ default_timeout: 10
+ instances:
+ - url: 'localhost:5050'
+ timeout: 8,
+ tags:
+ - slave
+ - tata
+ EOF
+
+ cached(:chef_run) do
+ ChefSpec::SoloRunner.new(
+ platform: 'ubuntu',
+ version: '16.04',
+ step_into: ['datadog_monitor']
+ ) do |node|
+ node.automatic['languages'] = { 'python' => { 'version' => '2.7.2' } }
+ node.normal['datadog'] = {
+ api_key: 'someapikey',
+ mesos_slave: {
+ init_config: {
+ default_timeout: 10
+ },
+ instances: [
+ {
+ url: 'localhost:5050',
+ timeout: 8,
+ tags: ['slave', 'tata']
+ }
+ ]
+ }
+ }
+ end.converge(described_recipe)
+ end
+
+ subject { chef_run }
+
+ it_behaves_like 'datadog-agent'
+
+ it { is_expected.to include_recipe('datadog::dd-agent') }
+
+ it { is_expected.to add_datadog_monitor('mesos_slave') }
+
+ it 'renders expected YAML config file' do
+ expect(chef_run).to(render_file('/etc/datadog-agent/conf.d/mesos_slave.yaml').with_content { |content|
+ expect(YAML.safe_load(content).to_json).to be_json_eql(YAML.safe_load(expected_yaml).to_json)
+ })
+ end
+end

ADD
templates/default/mesos_slave.yaml.erb
+# Generated by Chef, local modifications will be overwritten
+
+<%= JSON.parse(({ 'instances' => @instances, 'logs' => @logs }).to_json).to_yaml %>
+
+init_config:
+ <% if @init_config.key?('default_timeout') -%>
+ default_timeout: <%= @init_config['default_timeout'] %>
+ <% end -%>

ADD
test/integration/datadog_mesos_slave/serverspec/Gemfile
+source 'https://rubygems.org'
+
+gem 'json_spec', '~> 1.1.0'

ADD
test/integration/datadog_mesos_slave/serverspec/mesos_spec.rb
+# Encoding: utf-8
+
+require 'spec_helper'
+
+AGENT_CONFIG = File.join(@agent_config_dir, 'conf.d/mesos_slave.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: 'localhost:5050',
+ timeout: 8,
+ tags: ['slave', 'tata']
+ }
+ ],
+ 'logs' => nil,
+ init_config: {
+ default_timeout: 10
+ }
+ }
+
+ expect(generated.to_json).to be_json_eql expected.to_json
+ end
+end

Add mesos slave integration recipe

Adding the mesos slave integration in a similar fashion to the mesos_master integration