djoos-cookbooks / newrelic

Development repository for the newrelic cookbook
https://supermarket.chef.io/cookbooks/newrelic
MIT License
143 stars 245 forks source link

Why should java_agent get downloaded every time chef-client runs.. #311

Closed deepak-kosaraju closed 7 years ago

deepak-kosaraju commented 7 years ago

Currently this method inside the provider is running remote_file resource every time when chef-client is running, https://github.com/djoos-cookbooks/newrelic/blob/master/providers/agent_java.rb#L39-L74

Why cannot we add not_if logic something similar to,

not_if "grep #{node['newrelic']['java_agent']['version']} #{node['newrelic']['java_agent']['install_dir']}/version.txt"

I am trying to use edit_resource in Chef to edit remote_file resource in the agent_java.rb provider hoping that during chef compile time its going to modify the resource with not_if condition, but I am getting following message..

Chef: v12.10

edit_resource!(:remote_file, "#{node['newrelic']['java_agent']['install_dir']}/newrelic.zip]") do
    not_if "grep #{node['newrelic']['java_agent']['version']} #{node['newrelic']['java_agent']['install_dir']}/version.txt"
end

file "#{node['newrelic']['java_agent']['install_dir']}/version.txt" do 
    content "#{node['newrelic']['java_agent']['version']}"
    mode '0644'
    owner 'newrelic'
    group 'newrelic'
    only_if { ::File.directory?("#{node['newrelic']['java_agent']['install_dir']}") }
end

ERROR is:

-----> Chef Omnibus installation detected (12.10)
       Transferring files to <java-rhel71>
       Starting Chef Client, version 12.10.24
       resolving cookbooks for run list: ["gapNewRelic-Latest::default", "gapNewRelic-Latest::java_agent"]
       Synchronizing Cookbooks:
         - gapNewRelic-Latest (0.1.0)
         - newrelic (2.30.0)
         - poise-python (1.6.0)
         - curl (2.0.1)
         - apt (2.9.2)
         - yum (3.13.0)
         - poise-languages (2.1.1)
         - poise-archive (1.5.0)
         - poise (2.8.1)
       Installing Cookbook Gems:
       Compiling Cookbooks...
       [2017-10-06T20:36:23-07:00] WARN: Chef::Provider::AptRepository already exists!  Cannot create deprecation class for LWRP provider apt_repository from cookbook apt
       [2017-10-06T20:36:23-07:00] WARN: AptRepository already exists!  Deprecation class overwrites Custom resource apt_repository from cookbook apt

       ================================================================================
       Recipe Compile Error in /tmp/kitchen/cache/cookbooks/gapNewRelic-Latest/recipes/java_agent.rb
       ================================================================================

       Chef::Exceptions::ResourceNotFound
       ----------------------------------
       Cannot find a resource matching remote_file[/opt/newrelic/java/newrelic.zip] (did you define it first?)

       Cookbook Trace:
       ---------------
         /tmp/kitchen/cache/cookbooks/gapNewRelic-Latest/recipes/java_agent.rb:22:in `from_file'

       Relevant File Content:
       ----------------------
       /tmp/kitchen/cache/cookbooks/gapNewRelic-Latest/recipes/java_agent.rb:

        15:  #   #compile_time true if respond_to?(:compile_time)
        16:  #    version '0.0.9'
        17:  #    action :upgrade
        18:  # end
        19:  # require 'chef/rewind'
        20:
        21:  # rewind "remote_file[#{node['newrelic']['java_agent']['install_dir']}/newrelic.zip]" do
        22>> edit_resource!(:remote_file, "#{node['newrelic']['java_agent']['install_dir']}/newrelic.zip]") do
        23:     not_if "grep #{node['newrelic']['java_agent']['version']} #{node['newrelic']['java_agent']['install_dir']}/version.txt"
        24:  end
        25:
        26:  file "#{node['newrelic']['java_agent']['install_dir']}/version.txt" do
        27:     content "#{node['newrelic']['java_agent']['version']}"
        28:     mode '0644'
        29:     owner 'newrelic'
        30:     group 'newrelic'
        31:     only_if { ::File.directory?("#{node['newrelic']['java_agent']['install_dir']}") }

       Platform:
       ---------
       x86_64-linux
deepak-kosaraju commented 7 years ago

Any update (or) help on this is greatly appreciated? How are others handling this situation of downloading agent by hitting new relic download URL every time when chef-client runs. At the same time is anyone able to override the https_download variable to point to local repo instead of public and this is especially needed for environment which will not have direct access to internet.

deepak-kosaraju commented 7 years ago

I am going to submit PR to make https_download URI as attribute, so we can override in wrapper cookbooks. As chef resource is idempotent I am closing this issue.