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

Load config files from a directory as well as from an initial file. #154

Merged
merged 1 commit into from
Oct 19, 2014

Conversation

mipearson
Copy link
Contributor

Ref #136

Naive implementation - once I'm more comfortable with Go testing I can add some tests.

@@ -94,6 +94,8 @@ include them in your config.:
]
}

You can also pull in an entire directory of JSON configs with the `-config-dir` option.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be happy if the -config flag accepted a directory instead of using a separate flag. Logstash does this today by accepting a file or directory as the config file path.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - consistency between tools is always a good thing.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use os.Stat to check the config file exists, it should also return whether or not it's a directory (http://golang.org/pkg/os/#Stat). That way you could switch between reading a file and a directory. I would write a patch, but this is the first time I've read Go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry about it - hoping to attack this again on the train home this afternoon :)

@NoodlesNZ
Copy link

This is a feature that would be really helpful. I'm adding logstash-forwarder through my puppet config, but different servers will forward different logs, so it would be good to have a directory with syslog.json, apache.json, mysql.json etc rather than rewriting a single conf file.

@jordansissel
Copy link
Contributor

@mipearson thanks for your continued work on improving this project. :)

@mipearson
Copy link
Contributor Author

No problem! New commits should resolve both issues raised. Let me know what you think.

@mipearson
Copy link
Contributor Author

After discovering a couple of issues with this change in my own testing I decided to add a series of test cases.

This code is now running in production in @bikeexchange.

@mipearson
Copy link
Contributor Author

Hi Jordan - anything else you want me to do on this branch before you can merge it in?

@neeravkumar
Copy link

Any progress on this pull request? This feature would be really good with logging inside docker since we can add the main config for the forwarder in the base container while app containers can then include there own config with tagging etc to route logs correctly.

@mipearson
Copy link
Contributor Author

Hi,

If your can't wait for Jordan to merge this, we are using this branch already in production with no issues.

Sent from my iPad

On 1 Jun 2014, at 1:01 pm, Neerav Kumar notifications@github.com wrote:

Any progress on this pull request? This feature would be really good with logging inside docker since we can add the main config for the forwarder in the base container while app containers can then include there own config with tagging etc to route logs correctly.


Reply to this email directly or view it on GitHub.

@mingbowan
Copy link

this is a very useful enhancement, any progress on it? I was thinking to do it myself but this one is good enough.

@mipearson
Copy link
Contributor Author

It's complete and already in use in a production environment, just waiting on a merge.

Sent from my iPad

On 7 Jun 2014, at 12:38 am, mingbowan notifications@github.com wrote:

this is a very useful enhancement, any progress on it? I was thinking to do it myself but this one is good enough.


Reply to this email directly or view it on GitHub.

@mipearson
Copy link
Contributor Author

@jordansissel what's happening with this merge? I'd really like to bring my local version of logstash-forwarder in line with master so that I can debug our other logstash issues from a known state.

@jordansissel
Copy link
Contributor

The status is two things - One, so far we've got folks saying "I Like this idea" but almost nobody actually saying "I tested this in production and it was awesome". Second, that I haven't tested this myself, either.

I'll try to make time for this now.

@jordansissel
Copy link
Contributor

Manual test notes:

  • empty files fail Could not load config file /tmp/z/empty: unexpected end of JSON input - can we ignore empty files?
  • two files in /tmp/z are loaded correctly
  • two files in /tmp/z with duplicate network settings correctly fails
  • go test passes

As discussed in IRC, can you rebase this against master (and preferrably squash to a single commit?). Also toss things through gofmt if you haven't already :)

@mipearson
Copy link
Contributor Author

Commits squashed, empty files now ignored.

Note that one of your new tests was a duplicate of mine. I've favoured mine, as it also tests for comment stripping and is shorter.

@driskell
Copy link
Contributor

This looks good - but I question why we allow network configuration in multiple files.

It gives the potential false impression that the network config in one config file only applies to file definitions in that file.

Maybe it should only be the files definitions which are allowed as those accumulate. Whereby the network config is merged and that just feels non-intuitive and very likely superfluous to requirements.

@mipearson
Copy link
Contributor Author

Partly, we don't - any attempt to supply the network configuration twice will result in an error.

Secondly - it was easier to implement it this way rather than enforcing "you may only specify the network in one file".

Thirdly - this matches how apache / etc configs work, in that it doesn't matter where a configuration variable is specified, it'll get loaded in regardless.

@driskell
Copy link
Contributor

Apache you need to use "Include" to reference additional configs. So you have a main config and additionals which are distinct. The v host behaviour locks stuff to IPs etc so you generally don't get much undesired bleeding of config. Here you would bleed the servers config across files so they potentially affect all other configs by having that server selected instead.

I guess my concern stems from the -config - there is no main config file that could have network config. So the network config has to go somewhere. I hadn't thought of that, sorry, so I can now appreciate there's no simple way to force network config to a specific file, since none are specific, with this design.

The way I did it in Log Courier was added an "includes" section to main config with globs for additional file configs. Those files contained only the array segment [ { "paths": X, "type": Y }, {...

It can always be improved down the line! Just thought I'd throw my thoughts in the pot. 👍

@mipearson
Copy link
Contributor Author

Yep, understood. Originally the change had separate "--config" and
"--config-dir" args - Jordan commented that I should make "--config" work
both ways so that it would have the same semantics as logstash itself.

On Thu, Jul 10, 2014 at 6:32 PM, driskell notifications@github.com wrote:

Apache you need to use "Include" to reference additional configs. So you
have a main config and additionals which are distinct. The v host behaviour
locks stuff to IPs etc so you generally don't get much undesired bleeding
of config. Here you would bleed the servers config across files so they
potentially affect all other configs by having that server selected instead.

I guess my concern stems from the -config - there is no main config file
that could have network config. So the network config has to go somewhere.
I hadn't thought of that, sorry, so I can now appreciate there's no simple
way to force network config to a specific file, since none are specific,
with this design.

The way I did it in Log Courier was added an "includes" section to main
config with globs for additional file configs. Those files contained only
the array segment [ { "paths": X, "type": Y }, {...

It can always be improved down the line! Just thought I'd throw my
thoughts in the pot. [image: 👍]


Reply to this email directly or view it on GitHub
#154 (comment)
.

Michael Pearson

@mipearson
Copy link
Contributor Author

hey @jordansissel, this version is now running in production on ~5 hosts.

@mipearson
Copy link
Contributor Author

Fixed merge with master.

@blalor
Copy link

blalor commented Oct 16, 2014

What's holding this up from being merged to master?

@jordansissel
Copy link
Contributor

More testing & doing the actual merge process.

@blalor
Copy link

blalor commented Oct 16, 2014

What's the definition of "more testing"? One more person trying it out locally? Ten?

@jordansissel
Copy link
Contributor

More than just me and @mipearson would be sweet :P

@jordansissel
Copy link
Contributor

Or I can just merge it without more feedback.

@mipearson
Copy link
Contributor Author

I am will to bet my career and online reputation on the fact that it works fine on my machine.

YMMV, no warranty implied (even under local laws), may cause retinal scarring and birth defects in men between the ages of 31 and 32.5.

@neeravkumar
Copy link

I am already using this in production:

https://github.com/viki-org/logstash-forwarder

@jordansissel
Copy link
Contributor

@mipearson haha; got it! No warranty for any retinal scars. :P

@jordansissel
Copy link
Contributor

I'll work on merging this tomorrow! @mipearson if you rebase this on master before then, that'd be sweet, but otherwise I'll do the merging madness :)

@jordansissel
Copy link
Contributor

got config.go rebased; working on logstash-forwarder.go as time permits

@mipearson
Copy link
Contributor Author

Ah, I was planning on attacking that a bit later today.

Regards,

Michael Pearson
(sent from my phone)

On 18 Oct 2014, at 11:26 am, Jordan Sissel notifications@github.com wrote:

got config.go rebased; working on logstash-forwarder.go as time permits


Reply to this email directly or view it on GitHub.

 * Load multiple configuration files from a directory
 * Ignore empty configuration files
 * Filter '#' style comments from JSON configs
@mipearson
Copy link
Contributor Author

Okay, fully rebased. That was painful :(

jordansissel added a commit that referenced this pull request Oct 19, 2014
Load config files from a directory as well as from an initial file.
@jordansissel jordansissel merged commit 0632ce3 into elastic:master Oct 19, 2014
@jordansissel
Copy link
Contributor

@mipearson your intense efforts are much appreciated. <3

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

Successfully merging this pull request may close these issues.

None yet

7 participants