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

prometheus.yaml broken syntax when generated from hiera #108

Closed
TomaszUrugOlszewski opened this issue Nov 14, 2017 · 14 comments
Closed

prometheus.yaml broken syntax when generated from hiera #108

TomaszUrugOlszewski opened this issue Nov 14, 2017 · 14 comments
Labels
needs-feedback Further information is requested skip-changelog

Comments

@TomaszUrugOlszewski
Copy link

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
681bc1b

Some details about environment

  • puppet-agent 1.10.8-1jessie
  • puppetserver 2.8.0-1puppetlabs1
  • Debian Jessie
@bastelfreak
Copy link
Member

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

@benpollardcts
Copy link

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
Copy link
Member

tuxmea commented Nov 19, 2017

@TomaszUrugOlszewski can you please verify the comment from @benpollardcts

@TomaszUrugOlszewski
Copy link
Author

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

@TomaszUrugOlszewski
Copy link
Author

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
Copy link
Member

tuxmea commented Nov 30, 2017

@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
Copy link

ghost commented Nov 30, 2017

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

@tuxmea
Copy link
Member

tuxmea commented Nov 30, 2017

@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
Copy link
Author

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

@tuxmea
Copy link
Member

tuxmea commented Nov 30, 2017

@TomaszUrugOlszewski great. thanks.

@Ulme007
Copy link

Ulme007 commented Mar 27, 2018

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:

  • Prometheus Version: 1.7.1
  • OS: CentOS Linux release 7.4.1708 (Core)
  • Puppet Version: 5.3.5
  • Prometheus Puppet Modul Version: v5.0.0

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
Copy link

vanch commented Jul 12, 2018

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
Copy link
Member

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

@bastelfreak bastelfreak reopened this Jul 15, 2018
@TheMeier TheMeier added needs-feedback Further information is requested and removed bug Something isn't working labels May 5, 2024
@TheMeier
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-feedback Further information is requested skip-changelog
Projects
None yet
Development

No branches or pull requests

7 participants