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

Question - How to use consul_check #182

Closed
spuder opened this issue May 26, 2015 · 4 comments
Closed

Question - How to use consul_check #182

spuder opened this issue May 26, 2015 · 4 comments

Comments

@spuder
Copy link
Contributor

spuder commented May 26, 2015

I'm trying to use a LWRP to just add a check to a server. The documentation has examples of how to do this with services and checks, but not just the consul_check provider.

Here is the consul_service_def that works

consul_service_def 'influx web interface 8083' do
  check(
    id: 'Web interface',
    name: 'Web interface on port 8083',
    http: 'http://localhost:8083',
    interval: '10s',
    timeout: '1s'
  )
  notifies :reload, 'service[consul]'
end

Which succesfully translates to

        {
        "service": {
          "name": "influx web interface 8083",
          "check": {
            "id": "Web interface",
            "name": "Web interface on port 8083",
            "http": "http://localhost:8083",
            "interval": "10s",
            "timeout": "1s"
          }
        }
      }

However, this is what I am trying to do with the check_def provider

consul_check_def 'server1' do
  id 'Web interface'
  name 'Web interface on port 8083'
  http 'http://localhost:80'
  interval '10s'
  timeout '1s'
  notifies :reload, 'service[consul]'
end

This errors out

================================================================================
  Recipe Compile Error in /var/chef/cache/cookbooks/ND-consul-agent/recipes/influxdb.rb
  ================================================================================

  NoMethodError
  -------------
  undefined method `zero?' for "1s":String

  Cookbook Trace:
  ---------------
    /var/chef/cache/cookbooks/ND-consul-agent/recipes/influxdb.rb:15:in `block in from_file'
    /var/chef/cache/cookbooks/ND-consul-agent/recipes/influxdb.rb:10:in `from_file'

  Relevant File Content:
  ----------------------
  /var/chef/cache/cookbooks/ND-consul-agent/recipes/influxdb.rb:

    8:  # end
    9:
   10:  consul_check_def 'server1' do
   11:    id 'Web interface'
   12:    name 'Web interface on port 8083'
   13:    http 'http://localhost:80'
   14:    interval '10s'
   15>>   timeout '1s'
   16:    notifies :reload, 'service[consul]'
   17:  end
   18:
   19:  # {
   20:  #   "check": {
   21:  #     "id": "Web Interface ",
   22:  #     "name": "Web Interface on port 8083",
   23:  #     "http": "http://localhost:8083",
   24:  #     "interval": "10s",


  Running handlers:
[2015-05-26T15:46:04-06:00] ERROR: Running exception handlers
  Running handlers complete
[2015-05-26T15:46:04-06:00] ERROR: Exception handlers complete
[2015-05-26T15:46:04-06:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
  Chef Client failed. 0 resources updated in 3.5705527 seconds
[2015-05-26T15:46:04-06:00] ERROR: undefined method `zero?' for "1s":String
[2015-05-26T15:46:04-06:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

I've also tried the following syntaxes:

consul_check_def 'foobar' do
  id: 'Web interface',
  name: 'Web interface on port 8083',
  http: 'http://localhost:8083',
  interval: '10s',
  timeout: '1s'
  notifies :reload, 'service[consul]'
end
consul_check_def 'foobar' do
  check(
    id: 'Web interface',
    name: 'Web interface on port 8083',
    http: 'http://localhost:8083',
    interval: '10s',
    timeout: '1s'
  )
  notifies :reload, 'service[consul]'
end

Whats the proper way to use the consul_check lwrp?

@spuder
Copy link
Contributor Author

spuder commented May 26, 2015

If you remove 'timeout' then the following works.

consul_check_def 'foobar' do
  id 'web_interface_8083'
  name 'Web interface on port 8083'
  http 'http://localhost:8083'
  interval '10s'
  notifies :reload, 'service[consul]'
end

It has the side affect that the output in the consul web ui will show the entire html dump.

screenshot 2015-05-26 17 23 47

Shall I create a pull request to update the readme.md?

@csghuser
Copy link

I'm not having much look with this LWRP syntax. If I put the following:

consul_service_def 'javaapp' do
  check (
    id: 'Web interface',
    name: 'Web interface on port 8083',
    http: 'http://localhost:8083',
    interval: '10s',
    timeout: '1s'
  )
  notifies :reload, 'service[consul]'
end

I get:

[2015-05-28T08:38:10+01:00] ERROR: /tmp/kitchen/cookbooks/javaapp/recipes/default.rb:69: syntax error, unexpected tLABEL
           id: 'Web interface',

What am I doing wrong.....?

@csghuser
Copy link

Nevermind... this seems to work fine with the latest version. I was using an older version to work around #158

@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants