Skip to content

Commit

Permalink
[cassandra] YAML configuration template versioning
Browse files Browse the repository at this point in the history
* Enhance `DatadogMonitor` resource with a `version` attribute.
* Use `version` attribute in `cassandra` recipe to version, i.e.
  select the appriopriate YAML configuration file.
  Two versions are currently available
  * `1` (Default): Legacy YAML configuration file, compatible with
    Cassandra < 2.2.
  * `2`: Required for Cassandra > 2.2, use the YAML configuration file
  * introduced with
    DataDog/dd-agent@2df7566
* Enable `cassandra_aliasing` option to comply with
  DataDog/dd-agent#2035

More information:
DataDog/dd-agent#2142
  • Loading branch information
yannmh authored and sethrosenblum committed Apr 22, 2016
1 parent 6c0d3e6 commit 876af73
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 26 deletions.
15 changes: 15 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ suites:
password: somepass
process_name_regex: .*cassandra.*

- name: datadog_cassandra_version
run_list:
- recipe[datadog::cassandra]
attributes:
datadog:
<<: *DATADOG
cassandra:
version: 2
instances:
- host: localhost
port: 7199
user: someuser
password: somepass
process_name_regex: .*cassandra.*

- name: datadog_couchdb
run_list:
- recipe[datadog::couchdb]
Expand Down
1 change: 1 addition & 0 deletions attributes/cassandra.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default['datadog']['cassandra']['version'] = 1
3 changes: 2 additions & 1 deletion providers/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def whyrun_supported?
end
variables(
:init_config => new_resource.init_config,
:instances => new_resource.instances
:instances => new_resource.instances,
:version => new_resource.version
)
cookbook new_resource.cookbook
sensitive true if Chef::Resource.instance_methods(false).include?(:sensitive)
Expand Down
60 changes: 36 additions & 24 deletions recipes/cassandra.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
include_recipe 'datadog::dd-agent'

# Monitor cassandra
#
# Assuming you have 2 clusters "test" and "prod",
# one with and one without authentication
# you need to set up the following attributes
#
# node['datadog']['cassandra']['instances'] = [
# {
# host: 'localhost',
# port: 7199,
# name: 'prod',
# user: 'username',
# password: 'secret'
# },
# {
# server: 'localhost',
# port: 8199,
# name: 'test'
# }
# ]
#
# See here for more configuration values:
# https://github.com/DataDog/dd-agent/blob/master/conf.d/cassandra.yaml.example
#
# Monitor Cassandra

# Set the following attributes
# * `instances` (required)
# List of Cassandra clusters to monitor. Each cluster is generally a dictionary with a `host`, `port` and a `name`.
# More attributes are available. For more information, please refer to : https://github.com/DataDog/dd-agent/blob/master/conf.d/cassandra.yaml.example
# * `version` (optional)
# Select the appropriate configuration file template. Available options are:
# * `1` (Default, recommended for Cassandra < 2.2).
# Use Cassandra legacy metrics, i.e. https://github.com/DataDog/dd-agent/blob/5.6.x/conf.d/cassandra.yaml.example#L23-L74
# * `2` (recommended for Cassandra >= 2.2).
# Use Cassandra expanded metrics (CASSANDRA-4009) introduced in 1.2 (https://wiki.apache.org/cassandra/Metrics),
# i.e. https://github.com/DataDog/dd-agent/blob/master/conf.d/cassandra.yaml.example#L23-L102

# Example:

# ```
# node['datadog']['cassandra'] =
# instances: [
# {
# host: 'localhost',
# port: 7199,
# name: 'prod',
# user: 'username',
# password: 'secret'
# },
# {
# server: 'localhost',
# port: 8199,
# name: 'test'
# }],
# version: 2
# }
# ```

datadog_monitor 'cassandra' do
instances node['datadog']['cassandra']['instances']
version node['datadog']['cassandra']['version']
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 :version, :kind_of => Integer, :required => false, :default => nil
87 changes: 87 additions & 0 deletions templates/default/cassandra.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,94 @@ instances:
<% (i.keys - ['host']).each do |key| -%>
<%= key %>: <%= i[key] %>
<% end -%>
cassandra_aliasing: true
<% end -%>

<% if @version == 2 %>
init_config:
# List of metrics to be collected by the integration
# Read http://docs.datadoghq.com/integrations/java/ to learn how to customize it
conf:
- include:
domain: org.apache.cassandra.metrics
type: ClientRequest
scope:
- Read
- Write
name:
- Latency
- Timeouts
- Unavailables
attribute:
- Count
- OneMinuteRate
- include:
domain: org.apache.cassandra.metrics
type: ClientRequest
scope:
- Read
- Write
name:
- TotalLatency
- include:
domain: org.apache.cassandra.metrics
type: Storage
name:
- Load
- Exceptions
- include:
domain: org.apache.cassandra.metrics
type: ColumnFamily
name:
- TotalDiskSpaceUsed
- BloomFilterDiskSpaceUsed
- BloomFilterFalsePositives
- BloomFilterFalseRatio
- CompressionRatio
- LiveDiskSpaceUsed
- LiveSSTableCount
- MaxRowSize
- MeanRowSize
- MemtableColumnsCount
- MemtableLiveDataSize
- MemtableSwitchCount
- MinRowSize
exclude:
keyspace:
- system
- system_auth
- system_distributed
- system_traces
- include:
domain: org.apache.cassandra.metrics
type: Cache
name:
- Capacity
- Size
attribute:
- Value
- include:
domain: org.apache.cassandra.metrics
type: Cache
name:
- Hits
- Requests
attribute:
- Count
- include:
domain: org.apache.cassandra.metrics
type: ThreadPools
path: request
name:
- ActiveTasks
- CompletedTasks
- PendingTasks
- CurrentlyBlockedTasks
- include:
domain: org.apache.cassandra.db
attribute:
- UpdateInterval
<% else %>
# List of metrics to be collected.
init_config:
conf:
Expand Down Expand Up @@ -57,3 +143,4 @@ init_config:
domain: org.apache.cassandra.net
attribute:
- TotalTimeouts
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
port: 7199,
user: 'someuser',
password: 'somepass',
process_name_regex: '.*cassandra.*'
process_name_regex: '.*cassandra.*',
cassandra_aliasing: true
}
],
'init_config' => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Encoding: utf-8
require 'spec_helper'

AGENT_CONFIG = File.join(@agent_config_dir, 'conf.d/cassandra.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' => [
{
host: 'localhost',
port: 7199,
user: 'someuser',
password: 'somepass',
process_name_regex: '.*cassandra.*',
cassandra_aliasing: true
}
],
'init_config' => {
conf: [
{
include: {
domain: 'org.apache.cassandra.metrics',
type: 'ClientRequest',
scope: [
'Read',
'Write'
],
name: [
'Latency',
'Timeouts',
'Unavailables'
],
attribute: [
'Count',
'OneMinuteRate'
]
}
},
{
include: {
domain: 'org.apache.cassandra.metrics',
type: 'ClientRequest',
scope: [
'Read',
'Write'
],
name: [
'TotalLatency'
]
}
},
{
include: {
domain: 'org.apache.cassandra.metrics',
type: 'Storage',
name: [
'Load',
'Exceptions'
]
}
},
{
include: {
domain: 'org.apache.cassandra.metrics',
type: 'ColumnFamily',
name: %w(
TotalDiskSpaceUsed
BloomFilterDiskSpaceUsed
BloomFilterFalsePositives
BloomFilterFalseRatio
CompressionRatio
LiveDiskSpaceUsed
LiveSSTableCount
MaxRowSize
MeanRowSize
MemtableColumnsCount
MemtableLiveDataSize
MemtableSwitchCount
MinRowSize)
},
exclude: {
keyspace: [
'system',
'system_auth',
'system_distributed',
'system_traces'
]
}
},
{
include: {
domain: 'org.apache.cassandra.metrics',
type: 'Cache',
name: [
'Capacity',
'Size'
],
attribute: [
'Value'
]
}
},
{
include: {
domain: 'org.apache.cassandra.metrics',
type: 'Cache',
name: [
'Hits',
'Requests'
],
attribute: [
'Count'
]
}
},
{
include: {
domain: 'org.apache.cassandra.metrics',
type: 'ThreadPools',
path: 'request',
name: [
'ActiveTasks',
'CompletedTasks',
'PendingTasks',
'CurrentlyBlockedTasks'
]
}
},
{
include: {
domain: 'org.apache.cassandra.db',
attribute: [
'UpdateInterval'
]
}
}
]
}
}

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

0 comments on commit 876af73

Please sign in to comment.