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

Alert rule validation error #143

Closed
gangsta opened this issue Jan 10, 2018 · 7 comments · Fixed by #152
Closed

Alert rule validation error #143

gangsta opened this issue Jan 10, 2018 · 7 comments · Fixed by #152
Labels
bug Something isn't working needs-feedback Further information is requested

Comments

@gangsta
Copy link

gangsta commented Jan 10, 2018

Hi,

Getting error while using puppet-prometheus

init.pp

  class { '::prometheus':
    version              => '2.0.0',
  }

Error shown below

==> prometheus: Error: Execution of '/usr/local/bin/promtool check rules /etc/prometheus/alert.rules20180110-5183-s8nrev' returned 1: Checking /etc/prometheus/alert.rules20180110-5183-s8nrev
==> prometheus:   FAILED:
==> prometheus: yaml: unmarshal errors:
==> prometheus:   line 1: cannot unmarshal !!seq into rulefmt.RuleGroups
==> prometheus: Error: /Stage[main]/Prometheus::Alerts/File[/etc/prometheus/alert.rules]/ensure: change from absent to file failed: Execution of '/usr/local/bin/promtool check rules /etc/prometheus/alert.rules20180110-5183-s8nrev' returned 1: Checking /etc/prometheus/alert.rules20180110-5183-s8nrev
==> prometheus:   FAILED:
==> prometheus: yaml: unmarshal errors:
==> prometheus:   line 1: cannot unmarshal !!seq into rulefmt.RuleGroups

probably something wrong here: https://github.com/voxpupuli/puppet-prometheus/blob/master/manifests/alerts.pp#L36

BR
Karen

@tuxmea tuxmea added bug Something isn't working needs-feedback Further information is requested labels Jan 11, 2018
@tuxmea
Copy link
Member

tuxmea commented Jan 11, 2018

Many thanks for the report. Can you check that the promtool check command works without errors on the new alert file?
I want to verify whether it is the promtool command or the alert file which causes the error.

@gangsta
Copy link
Author

gangsta commented Jan 16, 2018

Hi @tuxmea ,

After getting above described error, I did ssh to vagrant box and added some simple alert.rules file to check promtool command . below copy of terminal .

[root@prometheus ~]# prometheus --version
prometheus, version 2.0.0 (branch: HEAD, revision: 0a74f98628a0463dddc90528220c94de5032d1a0)
  build user:       root@615b82cb36b6
  build date:       20171108-07:11:59
  go version:       go1.9.2
[root@prometheus ~]# cat /etc/prometheus/alert.rules 
groups:
- name: example
  rules:
  - alert: HighErrorRate
    expr: job:request_latency_seconds:mean5m{job="myjob"} > 0.5
    for: 10m
    labels:
      severity: page
    annotations:
      summary: High request latency
[root@prometheus ~]# /usr/local/bin/promtool check rules /etc/prometheus/alert.rules
Checking /etc/prometheus/alert.rules
  SUCCESS: 1 rules found

[root@prometheus ~]# echo $?
0
[root@prometheus ~]# 

BR
Karen

@gangsta
Copy link
Author

gangsta commented Jan 16, 2018

definitely something wrong with alert.rules files . including '::prometheus' should work out of box . I`m wondering that something is wrong here

@gangsta
Copy link
Author

gangsta commented Jan 16, 2018

content => $alerts.to_yaml, I think here converting is not working or we are providing wrong hash . but by default alert.rules is empty . if it`s empty?, validation should giving error .

@gangsta
Copy link
Author

gangsta commented Jan 16, 2018

Found issue . As Far as alert.rule has no default value Validation of empty yaml file is giving above error . so either we should add some default alert.rules to module to get include ::prometheus working out of box , or we should add in Readme that without alertrules your going to get error . I`ll do in minutes pull to Readme file to add Hash to alert.rule >= prometheus2.0.0

@costela
Copy link

costela commented Jan 31, 2018

Empty hashes seem to work, while empty arrays don't:

$ ruby -e "require 'yaml'; puts {}.to_yaml" | promtool check rules /dev/stdin
Checking /dev/stdin
  SUCCESS: 0 rules found

$ ruby -e "require 'yaml'; puts [].to_yaml" | promtool check rules /dev/stdin
Checking /dev/stdin
  FAILED:
yaml: unmarshal errors:
  line 1: cannot unmarshal !!seq into rulefmt.RuleGroups

So we can just change the default to {}. People using 1.* and not providing alert rules would still get a noop, while those providing rules would see no change, since they would override the default.

costela added a commit to costela/puppet-prometheus that referenced this issue Jan 31, 2018
This should fix `promtool` parsing problems for prometheus 2.* and empty alert files. Behaviour for 1.* should remain unchanged.

Fixes voxpupuli#143
@gangsta
Copy link
Author

gangsta commented Jan 31, 2018

Hi @costela ,
Thats a good one , it will solve include ::prometheus without any param , otherwise we should define some alert rules , From me +
Greetings

cegeka-jenkins pushed a commit to cegeka/puppet-prometheus that referenced this issue Aug 28, 2019
This should fix `promtool` parsing problems for prometheus 2.* and empty alert files. Behaviour for 1.* should remain unchanged.

Fixes voxpupuli#143
Rovanion pushed a commit to Rovanion/puppet-prometheus that referenced this issue May 5, 2021
This should fix `promtool` parsing problems for prometheus 2.* and empty alert files. Behaviour for 1.* should remain unchanged.

Fixes voxpupuli#143
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-feedback Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants