Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added recipe for go_expvar metrics collection #298

Merged
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
24 changes: 24 additions & 0 deletions recipes/go_expvar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
include_recipe 'datadog::dd-agent'

# Monitor Go metrics exported via expvar
# node['datadog']['go_expvar']['instances'] = [
# {
# 'expvar_url' => 'http://localhost:8080/debug/vars',
# 'tags' => [
# 'application:my_go_app'
# ],
# 'metrics' => [
# {
# 'path' => 'test_metrics_name_1', 'alias' => 'go_expvar.test_metrics_name_1', 'type' => 'gauge'
# },
# {
# 'path' => 'test_metrics_name_2', 'alias' => 'go_expvar.test_metrics_name_2', 'type' => 'gauge', 'tags' => ['tag1', 'tag2']
# }
# ]
# }
# ]

datadog_monitor 'go_expvar' do
init_config node['datadog']['go_expvar']['init_config']
instances node['datadog']['go_expvar']['instances']
end
60 changes: 60 additions & 0 deletions spec/integrations/go_expvar_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
describe 'datadog::go_expvar' do
expected_yaml = <<-EOF
init_config: {}
instances:
- expvar_url: http://localhost:8080/debug/vars
tags:
- application:my_go_app
metrics:
- path: test_metric_name_1
alias: go_expvar.test_metric_name_1
type: gauge
- path: test_metric_name_2
alias: go_expvar.test_metric_name_2
type: rate
tags:
- category:customtag1
- customtag2
EOF

cached(:chef_run) do
ChefSpec::SoloRunner.new(step_into: ['datadog_monitor']) do |node|
node.automatic['languages'] = { 'python' => { 'version' => '2.7.2' } }

node.set['datadog'] = {
'api_key' => 'someapikey',
'go_expvar' => {
init_config: nil,
instances: [
{
'expvar_url' => 'http://localhost:8080/debug/vars',
'tags' => ['application:my_go_app'],
'metrics' => [
{
'path' => 'test_metric_name_1', 'alias' => 'go_expvar.test_metric_name_1', 'type' => 'gauge'
},
{
'path' => 'test_metric_name_2', 'alias' => 'go_expvar.test_metric_name_2', 'type' => 'rate', 'tags' => ['category:customtag1', 'customtag2']
}
]
}
]
}
}
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('go_expvar') }

it 'renders expected YAML config file' do
expect(chef_run).to render_file('/etc/dd-agent/conf.d/go_expvar.yaml').with_content { |content|
expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json)
}
end
end
3 changes: 3 additions & 0 deletions templates/default/go_expvar.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(({ 'init_config' => @init_config, 'instances' => @instances}).to_json).to_yaml %>