Skip to content
Open
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
3 changes: 2 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ driver:

provisioner:
name: chef_zero
deprecations_as_errors: true
resource_cloning: false
data_path: test/shared

platforms:
Expand Down Expand Up @@ -53,7 +55,6 @@ suites:
- recipe[prometheus::default]
provisioner:
name: chef_zero
require_chef_omnibus: 11.12.4
attributes:
prometheus:
init_style: 'init'
Expand Down
35 changes: 0 additions & 35 deletions .rubocop.yml

This file was deleted.

10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Coding Standards
The submitted code should be compatible with the standard Ruby coding guidelines.
Here are some additional resources:

- [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide)
- [Cookstyle Guide](https://github.com/chef/cookstyle)
- [GitHub Styleguide](https://github.com/styleguide/ruby)

This cookbook is equipped with Rubocop, which will fail the build for violating
This cookbook is equipped with Cookstyle, which will fail the build for violating
these standards.

Testing
Expand All @@ -29,7 +29,7 @@ re-introduced.

We understand that not all users are familiar with the testing ecosystem. This
cookbook is fully-tested using [Foodcritic](https://github.com/acrmp/foodcritic),
[Rubocop](https://github.com/bbatsov/rubocop),
[Cookstyle](https://github.com/chef/cookstyle),
and [Test Kitchen](https://github.com/test-kitchen/test-kitchen) with
[Serverspec](https://github.com/serverspec/serverspec) bussers.

Expand All @@ -39,9 +39,9 @@ Process

$ git clone git@github.com:rayrod2030/chef-prometheus.git

2. Make sure you have a sane [ChefDK][] development environment:
2. Make sure you have a sane [ChefDK][] development environment (2.X):

$ chef version
$ chef --version

3. Make any changes
4. Write tests to support those changes.
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ group :unit do
end

group :lint do
gem 'foodcritic', '~> 8.1.0'
gem 'rubocop', '~> 0.47.1'
gem 'foodcritic'
gem 'cookstyle'
end

group :kitchen_common do
Expand Down
10 changes: 7 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'bundler/setup'
require 'cookstyle'
require 'rubocop/rake_task'
require 'foodcritic'
require 'kitchen'
Expand All @@ -7,15 +8,18 @@ require 'rspec/core/rake_task'
# Unit Tests. rspec/chefspec
RSpec::Core::RakeTask.new(:unit)

# Style tests. Rubocop and Foodcritic
# Style tests. Cookstyle and Foodcritic
namespace :style do
desc 'Run Ruby style checks'
RuboCop::RakeTask.new(:ruby)
# RuboCop::RakeTask.new(:ruby)
RuboCop::RakeTask.new(:ruby) do |task|
task.options << '--display-cop-names'
end

desc 'Run Chef style checks'
FoodCritic::Rake::LintTask.new(:chef) do |t|
t.options = {
fail_tags: ['any']
fail_tags: ['any'],
}
end
end
Expand Down
6 changes: 3 additions & 3 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
mysql: {
server_root_password: 'rootpass',
server_debian_password: 'debpass',
server_repl_password: 'replpass'
}
server_repl_password: 'replpass',
},
}

chef.run_list = [
'recipe[prometheus::default]',
'recipe[prometheus::alertmanager]'
'recipe[prometheus::alertmanager]',
]
end
end
44 changes: 21 additions & 23 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,24 @@
default['prometheus']['install_method'] = 'binary'

# Init style.
# rubocop:disable Style/ConditionalAssignment
case node['platform_family']
when 'debian'
if node['platform'] == 'ubuntu' && node['platform_version'].to_f < 15.04
default['prometheus']['init_style'] = 'upstart'
elsif node['platform'] == 'debian' && node['platform_version'].to_f < 8.0
default['prometheus']['init_style'] = 'runit'
else
default['prometheus']['init_style'] = 'systemd'
end
when 'rhel', 'fedora'
if node['platform_version'].to_i >= 7
default['prometheus']['init_style'] = 'systemd'
else
default['prometheus']['init_style'] = 'init'
end
else
default['prometheus']['init_style'] = 'init'
end
# rubocop:enable Style/ConditionalAssignment
default['prometheus']['init_style'] = case node['platform_family']
when 'debian'
if node['platform'] == 'ubuntu' && node['platform_version'].to_f < 15.04
'upstart'
elsif node['platform'] == 'debian' && node['platform_version'].to_f < 8.0
'runit'
else
'systemd'
end
when 'rhel', 'fedora'
if node['platform_version'].to_i >= 7
'systemd'
else
'init'
end
else
'init'
end

# Location for Prometheus logs
default['prometheus']['log_dir'] = '/var/log/prometheus'
Expand Down Expand Up @@ -88,8 +86,8 @@
# Prometheus configuration file name.

default['prometheus']['v2_cli_flags'] = [
'web.enable-lifecycle'
]
'web.enable-lifecycle',
]

default['prometheus']['flags']['config.file'] = "#{node['prometheus']['dir']}/prometheus.yml"
default['prometheus']['v2_cli_opts']['config.file'] = "#{node['prometheus']['dir']}/prometheus.yml"
Expand Down Expand Up @@ -214,7 +212,7 @@
# web.use-local-assets flag got removed in 0.17
# https://github.com/prometheus/prometheus/commit/a542cc86096e1bad694e04d307301a807583dfc6
if Gem::Version.new(node['prometheus']['version']) <= Gem::Version.new('0.16.2')
default['prometheus']['flags']['web.use-local-assets'] = false
default['prometheus']['flags']['web.use-local-assets'] = false
end

# Path to static asset directory, available at /user.
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name 'prometheus'
maintainer 'Elijah Wright'
maintainer_email 'elijah.wright@gmail.com'
license 'Apache 2.0'
license 'Apache-2.0'
description 'Installs/Configures Prometheus'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.6.4'
Expand Down
12 changes: 4 additions & 8 deletions recipes/alertmanager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
variables(
notification_config: node['prometheus']['alertmanager']['notification']
)
notifies :restart, 'service[alertmanager]'
notifies :restart, 'service[alertmanager]'
end

# -- Do the install -- #
Expand All @@ -84,7 +84,6 @@
action [:enable, :load]
end
when 'systemd'
# rubocop:disable Style/HashSyntax
dist_dir, conf_dir, env_file = value_for_platform_family(
['fedora'] => %w(fedora sysconfig alertmanager),
['rhel'] => %w(redhat sysconfig alertmanager),
Expand All @@ -94,7 +93,7 @@
template '/etc/systemd/system/alertmanager.service' do
source 'systemd/alertmanager.service.erb'
mode '0644'
variables(:sysconfig_file => "/etc/#{conf_dir}/#{env_file}")
variables(sysconfig_file: "/etc/#{conf_dir}/#{env_file}")
notifies :restart, 'service[alertmanager]', :delayed
end

Expand All @@ -105,10 +104,9 @@
end

service 'alertmanager' do
supports :status => true, :restart => true
supports status: true, restart: true
action [:enable, :start]
end
# rubocop:enable Style/HashSyntax
when 'upstart'
template '/etc/init/alertmanager.conf' do
source 'upstart/alertmanager.service.erb'
Expand All @@ -130,11 +128,9 @@
end
end

# rubocop:disable Style/HashSyntax
service 'alertmanager' do
supports :status => true, :restart => true
supports status: true, restart: true
end
# rubocop:enable Style/HashSyntax

service 'alertmanager' do
action [:enable, :start]
Expand Down
2 changes: 1 addition & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
variables(
rule_filenames: node['prometheus']['rule_filenames']
)
notifies :reload, 'service[prometheus]'
notifies :reload, 'service[prometheus]'
end

# monitor our server instance
Expand Down
10 changes: 3 additions & 7 deletions recipes/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
action [:enable, :load]
end
when 'systemd'
# rubocop:disable Style/HashSyntax
dist_dir, conf_dir, env_file = value_for_platform_family(
['fedora'] => %w(fedora sysconfig prometheus),
['rhel'] => %w(redhat sysconfig prometheus),
Expand All @@ -44,7 +43,7 @@
template '/etc/systemd/system/prometheus.service' do
source 'systemd/prometheus.service.erb'
mode '0644'
variables(:sysconfig_file => "/etc/#{conf_dir}/#{env_file}")
variables(sysconfig_file: "/etc/#{conf_dir}/#{env_file}")
notifies :restart, 'service[prometheus]', :delayed
end

Expand All @@ -55,10 +54,9 @@
end

service 'prometheus' do
supports :status => true, :restart => true
supports status: true, restart: true
action [:enable, :start]
end
# rubocop:enable Style/HashSyntax
when 'upstart'
template '/etc/init/prometheus.conf' do
source 'upstart/prometheus.service.erb'
Expand All @@ -80,8 +78,6 @@
end
end

# rubocop:disable Style/HashSyntax
service 'prometheus' do
supports :status => true, :restart => true, :reload => true
supports status: true, restart: true, reload: true
end
# rubocop:enable Style/HashSyntax
2 changes: 1 addition & 1 deletion resources/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

action :create do
with_run_context :root do
edit_resource(:template, config_file) do |new_resource|
edit_resource(:template, new_resource.config_file) do |new_resource|
cookbook new_resource.source
variables[:jobs] ||= {}
variables[:jobs][new_resource.name] ||= {}
Expand Down
2 changes: 0 additions & 2 deletions spec/unit/recipes/alertmanager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
require 'spec_helper'

# Caution: This is a carbon-copy of default_spec.rb with some variable replacements.

# rubocop:disable Metrics/BlockLength
describe 'prometheus::alertmanager' do
let(:chef_run) do
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/tmp/chef/cache').converge(described_recipe)
Expand Down
2 changes: 0 additions & 2 deletions spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
require 'spec_helper'

# rubocop:disable Metrics/BlockLength
describe 'prometheus::default' do
let(:chef_run) do
ChefSpec::SoloRunner.new(platform: 'ubuntu', version: '16.04', file_cache_path: '/tmp/chef/cache').converge(described_recipe)
Expand Down