voxpupuli / puppet-prometheus

Puppet module for prometheus
https://forge.puppet.com/puppet/prometheus
Apache License 2.0
60 stars 240 forks source link

prometheus.yaml broken syntax when generated from hiera #108

Closed TomaszUrugOlszewski closed 4 months ago

TomaszUrugOlszewski commented 6 years ago

Hello,

I keep prometheus config in hiera, looks like this:

prometheus::scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets:
        - 'localhost:9090'
        labels:
          instance: 'prometheus'
  - job_name: 'linux'
    static_configs:
      - targets:
        - 'ser1:9100'
        - 'ser2:9100'
        - 'ser3:9100'

After switching to latest master commit, my /etc/prometheus/prometheus.yaml transformed from nice yaml into "garbage":

---
"global":
  "scrape_interval": >-
    15s
  "evaluation_interval": >-
    15s
  "external_labels":
    "monitor": >-
      master
"rule_files":
- >-
  /etc/prometheus/alert.rules
"scrape_configs":
- "job_name": >-
    prometheus
  "static_configs":
  - "targets":
    - >-
      localhost:9090

After little digging I found out that it's related to change introduced in https://github.com/voxpupuli/puppet-prometheus/commit/681bc1b4d86b8c6a64c976d538b629296e683eb7

Some details about environment

bastelfreak commented 6 years ago

Hi @TomaszUrugOlszewski, thanks for the issue. Are you able to provide a PR for this?

benpollardcts commented 6 years ago

I've just tested this using the YAML pasted above and I'm unable to replicate the issue. Can you confirm your versions match the below? I assume they do as I've installed from the packages you have listed.

Enviroment: Debian GNU/Linux 8.9 puppet 4.10.8 hiera 3.3.2 ruby 2.1.9p490

tuxmea commented 6 years ago

@TomaszUrugOlszewski can you please verify the comment from @benpollardcts

TomaszUrugOlszewski commented 6 years ago

Yes, of course. I'll try to find out what's wrong.

TomaszUrugOlszewski commented 6 years ago

I was able to recreate my issue on fresh vagrant environment with image debian/contrib-jessie64

ii  puppet-agent                   1.10.9-1jessie              amd64        The Puppet Agent package contains all of the elements needed to run puppet, including ruby, facter, hiera and mcollective.
ii  puppetlabs-release-pc1         1.1.0-2jessie               all          Release packages for the Puppet Labs PC1 repository
ii  puppetserver                   2.8.0-1puppetlabs1          all          Puppet Labs puppetserver

Test code

vagrant@contrib-jessie:~$ cat /etc/puppetlabs/code/environments/production/manifests/site.pp 
$ble = {
  'scrape_configs' =>
    [
      {
        'job_name'       => 'bleble',
        'static_configs' =>
          [
            {
              'targets' =>
                [
                  'mongo-badabum2a:9216',
                  'mongo-badabum2b:9216',
                  'mongo-badabum2c:9216',
                ],

                'labels' =>
                  {
                    'cluster' => 'something-somewhere-sometime',
                  }
            }
          ]
      }
    ]
}

$template = @(END)
<% require 'yaml' -%>
<%= @ble.to_yaml(options = {:line_width => -1}) -%>
END

file { '/tmp/test.yaml':
  content => inline_template($template)
}

Result

"scrape_configs":
- "job_name": >-
    bleble
  "static_configs":
  - "targets":
    - >-
      mongo-badabum2a:9216
    - >-
      mongo-badabum2b:9216
    - >-
      mongo-badabum2c:9216
    "labels":
      "cluster": >-
        something-somewhere-sometime

After changing line_width "-1" to "800":

root@contrib-jessie:/home/vagrant# cat /tmp/test.yaml 
---
scrape_configs:
- job_name: bleble
  static_configs:
  - targets:
    - mongo-badabum2a:9216
    - mongo-badabum2b:9216
    - mongo-badabum2c:9216
    labels:
      cluster: something-somewhere-sometime

To be honest, I have no idea how to debug it, I'm not familar with ruby. My suggestion is to change it from -1 to some bigger value than 80, or revert, to keep compability with older(?) puppet/puppetserver/debian versions.

tuxmea commented 6 years ago

@TomaszUrugOlszewski one question: is the yaml file with the weird syntax working? I want to know whether this is just ugly looking or whether it affects the service.

ghost commented 6 years ago

Initially I thought that it's broken syntax, but after removing my "dirty fix" looks like everything is fine. Works as expected.

tuxmea commented 6 years ago

@TomekClearcode thanks. @TomaszUrugOlszewski can you confirm that the ugly looking syntax is working? Please let us know if you are OK with having ugly looking but working syntax. In this case we could close this issue.

TomaszUrugOlszewski commented 6 years ago

Sorry @tuxmea, it was me under different login. Yes we can close it, I can live with it.

tuxmea commented 6 years ago

@TomaszUrugOlszewski great. thanks.

Ulme007 commented 6 years ago

We have tried to update to the latest Puppet module version and we got an error with the Prometheus config test during the Puppet run.

puppet-agent[23364]: (/Stage[main]/Prometheus::Config/File[prometheus.yaml]/content)   line 135: cannot unmarshal !!str `[__addr...` into model.LabelNames
puppet-agent[23364]: (/Stage[main]/Prometheus::Config/File[prometheus.yaml]/content)   line 139: cannot unmarshal !!str `[__para...` into model.LabelNames

We use the following setup:

Part of our working 'prometheus.yaml'

- job_name: blackbox
  scrape_interval: 30s
  scrape_timeout: 30s
  metrics_path: "/probe"
  params:
    module:
    - index_page
  static_configs:
  - targets:
    - https://localhost/index.html
  relabel_configs:
  - source_labels: [__address__]
    target_label: __param_target
  - source_labels: [__param_target]
    target_label: instance
  - target_label: __address__
    replacement: 127.0.0.1:9115

The is the not working config:

...
  - source_labels: >-
    [__address__]
...

Could you please reopen this issue.

vanch commented 6 years ago

I have the same issue with:

puppetserver=5.3.3 puppet-agent=5.5.3 ruby=2.4.4p296 (2018-03-28 revision 63013) prometheus module=6.0.6

And this definitely affects the service.

UPD: I was trying to use prometheus server > v2, but did it wrong with hiera. Now I am able to use hiera right way and I have prom v2 and my config has right syntax.

bastelfreak commented 6 years ago

@vanch what did you change? @Ulme007 not sure what the issue is. Are the hiera strings quoted? Could you share your hiera data?

TheMeier commented 4 months ago

Closing due to lack of feedback, feel free to re-open