-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
[REVIEW] [MODULES-3520] refactored types and providers and added purging #49
Conversation
@crayfishx hai :) |
@bastelfreak that was quick!.... hold off on merging - I think the requires should be changed to relative requires otherwise this will cause ruby load errors under some circumstances |
@@ -1,24 +1,7 @@ | |||
require 'puppet_x/puppetlabs/splunk/type' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anytime we do this, we should be doing require File.join(File.dirname(__FILE__),.....etc.etc.
@crayfishx hi, any progress here? |
ups |
Thanks so much for this work. I wish I'd had the foresight to do it like this in the first place. |
On my fork I still have nearly all of the file paths hard coded. I have a provider and type for managing splunk-launch.conf. This actually sits in /opt/splunk/etc, not /opt/splunk/etc/system/local. I'm now wondering if confdir in splunk_config should actually be set to /opt/splunk/etc and the providers include system/local in the join where appropriate, thus letting us manage files like splunk-launch which sit outside of system/local. confdir is relative to forwarder_dir and server_dir. It isn't used anywhere else in the module (although it's referenced in the forwarder manifest). I think it is safe to change. I think this would be a worthwhile change so we have the ability to manage conf files that sit above system/local in a consistent, elegant way. As well as etc/splunk-launch.conf it could for example be used to manage etc/apps/splunk_http/local/inputs.conf to manage HTTP event collector tokens and other files in the future. |
8483add should stop potential problems with requiring files from the ruby load path (eg: @bastelfreak FYI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider #49 (comment) as this PR would be a good place to make that change.
Also, could you add a splunkforwarder_limits type please?
@nickperry I'll take a look at implementing that ... |
@nickperry is this what you meant? ea37d3d |
@crayfishx Yes, perfect, thanks |
@bastelfreak i have no more pending changes........ |
@nickperry one thing I thought of last night - this PR adds a title pattern to be able to define
So that would cause the section to be |
I've added another scenario to title_patterns to match '//' - if the string contains '//' it's assumed to be just the section and won't get split. irb(main):002:0> ['foo', 'foo://bar', 'foo/bar'].each do |example|
irb(main):003:1* type=Puppet::Type.type(:splunkforwarder_input).new(:title => example)
irb(main):004:1> puts "#{example} -> #{type[:section]}"
irb(main):005:1> end
foo -> foo
foo://bar -> foo://bar
foo/bar -> foo |
@crayfishx That's cool. I've been using my fork of the module with
in a large scale, complex environment, using the module from profiles with no problems for more than 6 months. |
Description
This is rather a large PR that refactors a lot of stuff internally, though should keep the existing API to users intact. It addresses the main issue raised in MODULES-3520 regarding purging.
Purging
As described in the ticket, purging as it stands does not work well with the new dynamic file_path stuff to allow overriding of the conf file locations. To use regular
instance()
based purging (eg: with the resources resource) then you have no option other than to have hard coded path names in the providers. Rather than a trade-off between the two I've taken a similar approach used in other modules to use a thegenerate
method of a core type (in this casesplunk_config
) to create resources as absent. Key things here that have changed are:params.pp
and the purge options are added to thesplunk_config
type by the classes that inherit from it (init.pp
andforwarder.pp
)splunk_config
sets the file paths on the providers based on whatparams.pp
has definedsplunk_config
uses it'sgenerate()
function to purge unwanted resourcesNamevars
Splunk types are a combination of setting and section, with a value. The current implementation is open to odd behaviour since the namevar is essentially discarded. This opens up scenarios such as the following.
The end result here is that Puppet ends up constantly changing the values because it doesn't see the resource declarations as conflicts.
The solution is to make all the types a composite namevar of
setting
andsection
. Thename
parameter has been left in because itPuppet::Type.type(:foo).new
(used for purging) seems not to work if there is not a name parameter.Now the above code fails as expected....
Title patterns
Following on from making the resource type support composite namevars, I've also added a title_pattern that allows for some shorter resource declarations. This could possibly be viewed as an API change, but I can't think of many circumstances where existing declarations would break. (needs decision). The new title patterns match
/^([^\/]*)$/
as "section" or/^(.*)\/(.*)$/
as "section/setting" meaning the following three types of declarations can be used (and do the same thing)Code clean up
Finally, all of the types and providers are identical and do exactly the same thing, the only difference is which file they do it in. This has resulted in alot of duplicated code both in the types and providers. I've added some boilerplating to this
PuppetX::Puppetlabs::Splunk::Type.clone
so the parameters, properties and methods of the types are centrally managed - but you can still add additional ones, or documentation, to individual types.Puppet::Type.type(:ini_file).provider(:splunk)
where generic stuff around file_path is set (bysplunk_config
). This then inturn inherits from the:ini_file
provider inpuppetlabs-inifile
37 files changed, 439 insertions(+), 689 deletions(-)