diff --git a/recipes/go_expvar.rb b/recipes/go_expvar.rb new file mode 100644 index 00000000..35a744ed --- /dev/null +++ b/recipes/go_expvar.rb @@ -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 diff --git a/spec/integrations/go_expvar_spec.rb b/spec/integrations/go_expvar_spec.rb new file mode 100644 index 00000000..9de79c26 --- /dev/null +++ b/spec/integrations/go_expvar_spec.rb @@ -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 diff --git a/templates/default/go_expvar.yaml.erb b/templates/default/go_expvar.yaml.erb new file mode 100644 index 00000000..32812bc0 --- /dev/null +++ b/templates/default/go_expvar.yaml.erb @@ -0,0 +1,3 @@ +# Generated by Chef, local modifications will be overwritten + +<%= JSON.parse(({ 'init_config' => @init_config, 'instances' => @instances}).to_json).to_yaml %>