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

Introduce rotate_compress option for log and errors directives in Caddyfile #1731

Merged
merged 3 commits into from
Jun 28, 2017

Conversation

fern4lvarez
Copy link

@fern4lvarez fern4lvarez commented Jun 27, 2017

1. What does this change do, exactly?

This PR addresses #1728 and provides a new rotate_compress option for log and errors directive to the Caddyfile, which will enable gzip compression for rotated log files.

It also updates the Lumberjack package dependencies in the vendor directory, and adds go-syslog, which was not present in vendor and was breaking tests when this was not present.

2. Please link to the relevant issues.

#1728

3. Which documentation changes (if any) need to be made because of this PR?

caddyserver/website#18

4. Checklist

  • I have written tests and verified that they fail without my change
  • I have squashed any insignificant commits
  • This change has comments for package types, values, functions, and non-obvious lines of code
  • I am willing to help maintain this change if there are issues with it later

@CLAassistant
Copy link

CLAassistant commented Jun 27, 2017

CLA assistant check
All committers have signed the CLA.

@fern4lvarez fern4lvarez changed the title Introduce rotate_compress directive in Caddyfile Introduce rotate_compress option for log and errors directives in Caddyfile Jun 27, 2017
@mholt mholt added this to the 0.10.4 milestone Jun 28, 2017
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! This is looking pretty good, but I think we can improve the Caddyfile syntax a little.

Also, this change shouldn't introduce any new dependencies, and the CI tests were passing -- I haven't seen any failures in my inbox. We don't need dependencies for the test files to be vendored. What command did you run that failed?

@@ -85,13 +85,14 @@ func TestErrorsParse(t *testing.T) {
Roller: httpserver.DefaultLogRoller(),
},
}},
{`errors errors.txt { rotate_size 2 rotate_age 10 rotate_keep 3 }`, false, ErrorHandler{
{`errors errors.txt { rotate_size 2 rotate_age 10 rotate_keep 3 rotate_compress true }`, false, ErrorHandler{
Copy link
Member

Choose a reason for hiding this comment

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

Let's get rid of "true" here, since the presence of "rotate_compress" will make that obvious. (And lack of it is obviously "false".) In other words, the line would be "rotate_compress" by itself, no arguments.

directiveRotateAge = "rotate_age"
directiveRotateKeep = "rotate_keep"
defaultRotateKeep = 10
// defaultRotateCompress is false.
Copy link
Member

Choose a reason for hiding this comment

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

This comment isn't super helpful, it can be removed. ;)

@fern4lvarez
Copy link
Author

fern4lvarez commented Jun 28, 2017

@mholt re: broken dependency

I just reverted the commit that adds the gopkg.in/mcuadros/go-syslog.v2 package to vendor/ and ran the tests:

$ git revert 6722284                                            
[1728-log-rotate-compress 9e990b6] Revert "vendor: add go-syslog dep"
...
$ go test -v ./caddyhttp/httpserver               
# github.com/mholt/caddy/caddyhttp/httpserver
caddyhttp/httpserver/logger_test.go:15:2: cannot find package "gopkg.in/mcuadros/go-syslog.v2" in any of:
	/home/fernando/src/github.com/mholt/caddy/vendor/gopkg.in/mcuadros/go-syslog.v2 (vendor tree)
	/usr/local/go/src/gopkg.in/mcuadros/go-syslog.v2 (from $GOROOT)
	/home/fernando/src/gopkg.in/mcuadros/go-syslog.v2 (from $GOPATH)
FAIL	github.com/mholt/caddy/caddyhttp/httpserver [setup failed]

Of course, I can go get gopkg.in/mcuadros/go-syslog.v2 and the tests would pass. But this dependency is not tracked into vendor/. If you think we should not add it to vendor/ and rely on the user having imported it in their $GOPATH, I'm happy to revert that commit :)

This directive will enable gzip compression provided by [Lumberjack](natefinch/lumberjack#43).

The directive `rotate_compress` can be `true` or `false`, being `false` by default.
@fern4lvarez fern4lvarez force-pushed the 1728-log-rotate-compress branch from 7aeaec6 to 5a4e392 Compare June 28, 2017 14:29
@fern4lvarez
Copy link
Author

fern4lvarez commented Jun 28, 2017

@mholt based on your comments:

  • I agree that either we need to vendor gopkg.in/mcuadros/go-syslog.v2 or not, this ain't part of this PR, so I removed it.
  • No need to set false or true along with rotate_compress. If the option is declared into the Caddyfile, we want to compress logs.
  • Get rid of defaultRotateCompress. We don't compress by default, hence it is false, so no need to create a wrapping var for this.

I'll also update caddyserver/website#18 accordingly.

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

When you go get a repository, it doesn't fetch test dependencies. If you go get a repository to develop it, you should use go get -t to download test dependencies too. But we do not need to vendor dependencies used solely for tests.

The changes look superb!! Thanks for your great work and thorough detailing.

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.

3 participants