Rules migration step fails if no *.rules files are available
These two lines: https://gitlab.com/gitlab-cookbooks/gitlab-prometheus/blob/master/recipes/prometheus.rb#L59 and https://gitlab.com/gitlab-cookbooks/gitlab-prometheus/blob/master/recipes/prometheus.rb#L67 are failing if there is no *.rules
file in recording or alert rules directories. E.g. in https://gitlab.com/gitlab-com/ci-prometheus-configuration we currently have only *.rules.yml
files (since the configuration was created with Prometheus 2.0 in mind) or don't have any alerting rules and chef-client
execution fails with:
[2018-01-15T16:58:26+00:00] INFO: git[/var/chef/cache/runbooks] sending run action to execute[migrate_alert_rules] (delayed)
* execute[migrate_alert_rules] action run[2018-01-15T16:58:26+00:00] INFO: Processing execute[migrate_alert_rules] action run (gitlab-prometheus::prometheus line 58)
[execute] promtool: error: path '/opt/prometheus/prometheus/alerts/*.rules' does not exist, try --help
================================================================================
Error executing action `run` on resource 'execute[migrate_alert_rules]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of /opt/prometheus/prometheus/promtool update rules /opt/prometheus/prometheus/alerts/*.rules ----
STDOUT:
STDERR: promtool: error: path '/opt/prometheus/prometheus/alerts/*.rules' does not exist, try --help
---- End output of /opt/prometheus/prometheus/promtool update rules /opt/prometheus/prometheus/alerts/*.rules ----
Ran /opt/prometheus/prometheus/promtool update rules /opt/prometheus/prometheus/alerts/*.rules returned 1
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/gitlab-prometheus/recipes/prometheus.rb
58: execute "migrate_alert_rules" do
59: command "#{rules_migration_tool} update rules #{node['prometheus']['alerting_rules_dir']}/*.rules"
60: user node["prometheus"]["user"]
61: action :nothing
62: notifies :hup, "runit_service[prometheus]", :delayed
63: only_if { Gem::Version.new(node["prometheus"]["version"]) >= Gem::Version.new("2.0.0") }
64: end
65:
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/gitlab-prometheus/recipes/prometheus.rb:58:in `from_file'
execute("migrate_alert_rules") do
action [:nothing]
retries 0
retry_delay 2
default_guard_interpreter :execute
command "/opt/prometheus/prometheus/promtool update rules /opt/prometheus/prometheus/alerts/*.rules"
backup 5
returns 0
user "prometheus"
declared_type :execute
cookbook_name "gitlab-prometheus"
recipe_name "prometheus"
only_if { #code block }
end
Platform:
---------
x86_64-linux
[2018-01-15T16:58:27+00:00] INFO: git[/var/chef/cache/runbooks] sending run action to execute[migrate_recording_rules] (delayed)
* execute[migrate_recording_rules] action run[2018-01-15T16:58:27+00:00] INFO: Processing execute[migrate_recording_rules] action run (gitlab-prometheus::prometheus line 66)
[execute] promtool: error: path '/opt/prometheus/prometheus/recordings/*.rules' does not exist, try --help
================================================================================
Error executing action `run` on resource 'execute[migrate_recording_rules]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of /opt/prometheus/prometheus/promtool update rules /opt/prometheus/prometheus/recordings/*.rules ----
STDOUT:
STDERR: promtool: error: path '/opt/prometheus/prometheus/recordings/*.rules' does not exist, try --help
---- End output of /opt/prometheus/prometheus/promtool update rules /opt/prometheus/prometheus/recordings/*.rules ----
Ran /opt/prometheus/prometheus/promtool update rules /opt/prometheus/prometheus/recordings/*.rules returned 1
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/gitlab-prometheus/recipes/prometheus.rb
66: execute "migrate_recording_rules" do
67: command "#{rules_migration_tool} update rules #{node['prometheus']['recording_rules_dir']}/*.rules"
68: user node["prometheus"]["user"]
69: action :nothing
70: notifies :hup, "runit_service[prometheus]", :delayed
71: only_if { Gem::Version.new(node["prometheus"]["version"]) >= Gem::Version.new("2.0.0") }
72: end
73:
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/gitlab-prometheus/recipes/prometheus.rb:66:in `from_file'
execute("migrate_recording_rules") do
action [:nothing]
retries 0
retry_delay 2
default_guard_interpreter :execute
command "/opt/prometheus/prometheus/promtool update rules /opt/prometheus/prometheus/recordings/*.rules"
backup 5
returns 0
user "prometheus"
declared_type :execute
cookbook_name "gitlab-prometheus"
recipe_name "prometheus"
only_if { #code block }
end
Platform:
---------
x86_64-linux