-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Render jmx.yaml template based on data input
After multiple passes at attempting to cover all cases of inclusion of instance details into a given YAML file, this lays the foundation for leaving the details up to the end-user to implement the instance hash, instead of trying to capture each possible flag. This should help future-proof the recipe and template, so any new flags can be appended as data. See #88, #93 and fixes #116, #121. Tests and examples updated.
- Loading branch information
1 parent
fcfbe9d
commit c2e0dbf
Showing
6 changed files
with
105 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
include_recipe 'datadog::dd-agent' | ||
|
||
# Build a data structure with configuration. | ||
# @see https://github.com/DataDog/dd-agent/blob/master/conf.d/jmx.yaml.example JMX Example | ||
# @example | ||
# node.override['datadog']['jmx']['instances'] = [ | ||
# { | ||
# 'host' => 'localhost', | ||
# 'port' => '7199', | ||
# 'name' 'prod_jmx_app', | ||
# 'conf' => [ | ||
# 'include' => { | ||
# 'attributes' => ['Capacity', 'Used'], | ||
# 'bean_name' => 'com.datadoghq.test:type=BeanType,tag1=my_bean_name', | ||
# 'domain' => 'com.datadoghq.test' | ||
# } | ||
# ] | ||
# } | ||
# ] | ||
datadog_monitor 'jmx' do | ||
instances node['datadog']['jmx']['instances'] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,5 @@ | ||
<% excluded_keys = ["host", "server", "conf", "include", "exclude"] -%> | ||
instances: | ||
<% @instances.each do |i| -%> | ||
- host: <%= i["server"] %> | ||
<% (i.keys - excluded_keys).each do |key| -%> | ||
<%= key %>: <%= i[key] %> | ||
<% end -%> | ||
<% if i.key?("include") || i.key?("exclude") -%> | ||
conf: | ||
<% i["include"].each do |c| -%> | ||
- include: | ||
<% if c.key?("domain") -%> | ||
domain: <%= c["domain"] %> | ||
<% end -%> | ||
<% if c.key?("bean") -%> | ||
bean: <%= c["bean"] %> | ||
<% end -%> | ||
<% if c.key?("attributes") -%> | ||
attribute: | ||
<% c["attributes"].each do |a| -%> | ||
attribute<%= c["attributes"].index(a) %>: | ||
metric_type: <%= a["metric_type"] %> | ||
alias: <%= a["alias"] %> | ||
<% end -%> | ||
<% end -%> | ||
<% end -%> | ||
<% i["exclude"].each do |c| -%> | ||
- exclude: | ||
<% if c.key?("domain") -%> | ||
domain: <%= c["domain"] %> | ||
<% end -%> | ||
<% if c.key?("bean") -%> | ||
bean: <%= c["bean"] %> | ||
<% end -%> | ||
<% if c.key?("attributes") -%> | ||
attribute: | ||
<% c["attributes"].each do |a| -%> | ||
attribute<%= c["attributes"].index(a) %>: | ||
metric_type: <%= a["metric_type"] %> | ||
alias: <%= a["alias"] %> | ||
<% end -%> | ||
<% end -%> | ||
<% end -%> | ||
<% end -%> | ||
<% end -%> | ||
<%# Sanitize the compiled Mash to standard Array/Hash objects by way of JSON -%> | ||
<%= JSON.parse(({ 'instances' => @instances }).to_json).to_yaml %> | ||
|
||
init_config: | ||
# Nothing to configure here |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'json_spec', '~> 1.1' |
61 changes: 61 additions & 0 deletions
61
test/integration/dd-agent-jmx/serverspec/dd-agent-jmx_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Encoding: utf-8 | ||
require 'json_spec' | ||
require 'serverspec' | ||
require 'yaml' | ||
|
||
set :backend, :exec | ||
set :path, '/sbin:/usr/local/sbin:$PATH' | ||
|
||
JMX_CONFIG = '/etc/dd-agent/conf.d/jmx.yaml' | ||
|
||
describe service('datadog-agent') do | ||
it { should be_running } | ||
end | ||
|
||
describe file(JMX_CONFIG) do | ||
it { should be_a_file } | ||
|
||
it 'is valid yaml matching input values' do | ||
generated = YAML.load_file(JMX_CONFIG) | ||
|
||
expected = { | ||
'init_config' => nil, | ||
'instances' => [ | ||
{ | ||
'conf' => [ | ||
{ | ||
'exclude' => [ | ||
{ | ||
'domain' => 'evil_domain' | ||
} | ||
], | ||
'include' => { | ||
'attribute' => { | ||
'bytesReceived' => { 'metric_type' => 'counter', 'alias' => 'tomcat.bytes_rcvd' }, | ||
'maxThreads' => { 'metric_type' => 'gauge', 'alias' => 'tomcat.threads.max' } | ||
}, | ||
'bean' => 'tomcat_bean', | ||
'domain' => 'domain0', | ||
'type' => 'ThreadPool' | ||
}, | ||
'include' => { | ||
'attributes' => [ | ||
'BloomFilterDiskSpaceUsed', | ||
'Capacity' | ||
], | ||
'bean_name' => 'com.datadoghq.test:type=BeanType,tag1=my_bean_name', | ||
'domain' => 'org.apache.cassandra.db', | ||
'foo' => 'bar' | ||
} | ||
} | ||
], | ||
'extra_key' => 'extra_val', | ||
'host' => 'localhost', | ||
'port' => 9999 | ||
} | ||
] | ||
} | ||
|
||
expect(generated.to_json).to be_json_eql expected.to_json | ||
end | ||
end |