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

Support 'why-run' mode #118

Closed
miketheman opened this issue Apr 28, 2014 · 7 comments
Closed

Support 'why-run' mode #118

miketheman opened this issue Apr 28, 2014 · 7 comments
Assignees
Labels

Comments

@miketheman
Copy link
Contributor

No description provided.

@miketheman
Copy link
Contributor Author

On Chef 10.26.0, I get this:

$ sudo chef-client -W -Fdoc
...
Compiling Cookbooks...
Recipe: chef_handler::default
  * remote_directory[/var/chef/handlers] action createRecipe: <Dynamically Defined Resource>
  * cookbook_file[/var/chef/handlers/README] action create (up to date)
 (up to date)
Recipe: datadog::dd-handler
  * chef_gem[chef-handler-datadog] action install (up to date)
  * chef_handler[Chef::Handler::Datadog] action enable
    - Would load chef/handler/datadog
    - Would enable chef_handler[Chef::Handler::Datadog] as a report handler
    - Would enable chef_handler[Chef::Handler::Datadog] as a exception handler
Converging 419 resources
...
Recipe: datadog::repository
  * apt_repository[datadog] action add (up to date)
Recipe: <Dynamically Defined Resource>
  * execute[install-key C7A7DA52] action run (skipped due to not_if)
  * file[/var/lib/apt/periodic/update-success-stamp] action nothing (up to date)
  * execute[apt-cache gencaches] action nothing (up to date)
  * execute[apt-get update] action nothing (up to date)
  * file[/etc/apt/sources.list.d/datadog.list] action create (up to date)
Recipe: datadog::dd-agent
  * log[Running apt-get update to work around COOK-2171] action write (skipped due to not_if)
  * package[datadog-agent] action install (up to date)
  * directory[/etc/dd-agent] action create (up to date)
  * template[/etc/dd-agent/datadog.conf] action create (up to date)
  * service[datadog-agent] action enable (up to date)
  * service[datadog-agent] action start (up to date)
Recipe: datadog::network
  * datadog_monitor[network] action add (up to date)
Recipe: <Dynamically Defined Resource>
  * template[/etc/dd-agent/conf.d/network.yaml] action create (up to date)
Recipe: chef_handler::default
  * remote_directory[/var/chef/handlers] action nothing (up to date)
Recipe: datadog::dd-handler
  * chef_gem[chef-handler-datadog] action install (up to date)
  * chef_handler[Chef::Handler::Datadog] action nothing (up to date)
....

So I think we're good - we support running in why-run mode, and do not emit events/metrics during a why-run execution.

@olivielpeau
Copy link
Member

Tested on Chef 12.2.1, the why-run execution seems to work fine (no changes to the state and no event/metrics emitted).

The only case I've found that doesn't work is the dd-handler recipe when the chef-handler-datadog gem is not installed. The run fails when 'chef/handler/datadog' is required here, with the following error:

  ================================================================================
  Recipe Compile Error in /home/vagrant/cookbooks/datadog/recipes/dd-handler.rb
  ================================================================================

  LoadError
  ---------
  cannot load such file -- chef/handler/datadog

  Cookbook Trace:
  ---------------
    /home/vagrant/cookbooks/datadog/recipes/dd-handler.rb:29:in `from_file'

(obviously because in why-run mode the chef_gem resource doesn't actually install the gem that's required)

But from what I understand this case is unavoidable.

@miketheman
Copy link
Contributor Author

@olivielpeau Thanks for the investigation. Regarding the final case, this was reported a while back, and claimed to have been resolved. Might be worthwhile looking into it a bit further?

@olivielpeau
Copy link
Member

@miketheman I think the issue you're mentioning is that the chef_gem resource itself breaks why-run mode, whereas here it's the subsequent require on chef/handler/datadog that's making the run fail when the file doesn't exist.

I'll look more into this issue (in particular I'll look at how chef_handler loads the handler's class and if that can help us solve this).

@miketheman
Copy link
Contributor Author

@olivielpeau You're right - I linked the wrong issue.

Thinking about this further, there might be a better way to wrap the require that behaves differently based on whether or not we're in why-run mode, by inspecting the value of Chef::Config[:why_run].

Something maybe like:

if Chef::Config[:why_run]
  Chef::Log.warn('Running in why-run mode, skipping dd-handler')
  return
end

at the top of the recipe.

@olivielpeau
Copy link
Member

@miketheman I like the idea of skipping dd-handler in why-run mode as I can't see any clean workaround to execute it in this mode.

FYI the 1.2.0 release of chef_handler allows using the handler without having to require it beforehand because it requires the handler's file on its own (see https://github.com/chef-cookbooks/chef_handler/blob/v1.2.0/providers/default.rb#L41), which would solve our issue here. The thing is that this version is only compatible with Chef >= 12 so we can't use it, but we should keep that in mind for the future.

Apart from that I think why-run mode is fully supported.

olivielpeau added a commit that referenced this issue Sep 16, 2015
Running in why-run mode fails when the chef-handler-datadog gem is not
installed because of the `require 'chef/handler/datadog'` line, so we
skip the entire recipe in why-run mode.

Upgrading chef_handler to v1.2 (Chef>=12)  will allow us to remove that
`require` and unskip the recipe in why-run mode.

See #118
@miketheman
Copy link
Contributor Author

Closed via #231

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants